kodi_client 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'kodi_client/util/comparable'
4
+ require 'kodi_client/util/creatable'
4
5
  require 'kodi_client/global_types/video_types'
5
6
  require 'kodi_client/global_types/audio_types'
6
7
 
@@ -18,26 +19,25 @@ module KodiClient
18
19
  @list_start = list_start
19
20
  @list_end = list_end
20
21
  end
21
-
22
- def ==(other)
23
- compare(self, other)
24
- end
25
22
  end
26
23
 
27
24
  # List.LimitsReturned https://kodi.wiki/view/JSON-RPC_API/v12#List.LimitsReturned
28
25
  class ListLimitsReturned
29
26
  include Comparable
27
+ extend Creatable
30
28
 
31
29
  attr_reader :list_start, :list_end, :total
32
30
 
33
- def initialize(hash)
34
- @list_start = hash['start']
35
- @list_end = hash['end']
36
- @total = hash['total']
31
+ def self.create(hash)
32
+ return nil if hash.nil?
33
+
34
+ new(hash['start'], hash['end'], hash['total'])
37
35
  end
38
36
 
39
- def ==(other)
40
- compare(self, other)
37
+ def initialize(list_start, list_end, total)
38
+ @list_start = list_start
39
+ @list_end = list_end
40
+ @total = total
41
41
  end
42
42
  end
43
43
 
@@ -56,16 +56,12 @@ module KodiClient
56
56
  attr_reader :ignore_article, :method, :order, :use_artist_sort_name
57
57
 
58
58
  def initialize(ignore_article = false, method = ListSortMethod::NONE,
59
- sortOrder = SortOrder::ASCENDING, use_artist_sort_name = false)
59
+ sort_order = SortOrder::ASCENDING, use_artist_sort_name = false)
60
60
  @ignore_article = ignore_article
61
61
  @method = method
62
- @order = SortOrder::ASCENDING
62
+ @order = sort_order
63
63
  @use_artist_sort_name = use_artist_sort_name
64
64
  end
65
-
66
- def ==(other)
67
- compare(self, other)
68
- end
69
65
  end
70
66
 
71
67
  # List.Fields.All https://kodi.wiki/view/JSON-RPC_API/v12#List.Fields.All
@@ -172,75 +168,116 @@ module KodiClient
172
168
  :special_sort_season, :studio, :style, :tag, :tag_line, :theme, :top250, :total_discs, :track,
173
169
  :trailer, :tv_show_id, :type, :unique_id, :votes, :watched_episodes, :writer
174
170
 
175
- def list_item_base(hash)
176
- @album = hash['album']
177
- @album_artist = hash['albumartist']
178
- @album_artist_id = hash['albumartistid']
179
- @album_id = hash['albumid']
180
- @album_release_type = hash['albumreleasetype']
181
- @album_status = hash['albumstatus']
182
- @bit_rate = hash['bitrate']
183
- @bpm = hash['bpm']
184
- @cast = hash['cast'].nil? ? [] : hash['cast'].map { |it| Types::Video::VideoCast.new(it) }
185
- @channels = hash['channels']
186
- @comment = hash['comment']
187
- @compilation = hash['compilation']
188
- @contributors = hash['contributors'].nil? ? [] : hash['contributors'].map { |it| Types::Audio::AudioContributor.new(it) }
189
- @country = hash['country']
190
- @description = hash['description']
191
- @disc = hash['disc']
192
- @disc_title = hash['disctitle']
193
- @display_composer = hash['displaycomposer']
194
- @display_conductor = hash['displayconductor']
195
- @display_lyricist = hash['displaylyricist']
196
- @display_orchestra = hash['displayorchestra']
197
- @duration = hash['duration']
198
- @dyn_path = hash['dynpath']
199
- @episode = hash['episode']
200
- @episode_guide = hash['episodeguide']
201
- @first_aired = hash['firstaired']
202
- @id = hash['id']
203
- @imdb_number = hash['imdbnumber']
204
- @is_box_set = hash['isboxset']
205
- @lyrics = hash['lyrics']
206
- @media_path = hash['mediapath']
207
- @mood = hash['mood']
208
- @mpaa = hash['mpaa']
209
- @musicbrainz_artist_id = hash['musicbrainzartistid']
210
- @musicbrainz_track_id = hash['musicbrainztrackid']
211
- @original_date = hash['originaldate']
212
- @original_title = hash['originaltitle']
213
- @plot_outline = hash['plotoutline']
214
- @premiered = hash['premiered']
215
- @production_code = hash['productioncode']
216
- @release_date = hash['releasedate']
217
- @release_type = hash['releasetype']
218
- @sample_rate = hash['samplerate']
219
- @season = hash['season']
220
- @set = hash['set']
221
- @set_id = hash['setid']
222
- @show_link = hash['showlink']
223
- @show_title = hash['showtitle']
224
- @sort_title = hash['sorttitle']
225
- @special_sort_episode = hash['specialsortepisode']
226
- @special_sort_season = hash['specialsortseason']
227
- @studio = hash['studio']
228
- @style = hash['style']
229
- @tag = hash['tag']
230
- @tag_line = hash['tagline']
231
- @theme = hash['theme']
232
- @top250 = hash['top250']
233
- @total_discs = hash['totaldiscs']
234
- @track = hash['track']
235
- @trailer = hash['trailer']
236
- @tv_show_id = hash['tvshowid']
237
- @type = hash['type'].nil? ? 'unknown' : hash['type']
238
- @unique_id = hash['uniqueid']
239
- @votes = hash['votes']
240
- @watched_episodes = hash['watchedepisodes']
241
- @writer = hash['writer']
242
- video_details_file(hash)
243
- audio_details_media(hash)
171
+ def list_item_base_by_hash(hash)
172
+ cast = Types::Video::VideoCast.create_list(hash['cast'])
173
+ contributors = Types::Audio::AudioContributor.create_list(hash['contributors'])
174
+ resume = Types::Video::VideoResume.create(hash['resume'])
175
+ stream_details = Types::Video::Streams.create(hash['streamdetails'])
176
+ art = Types::Media::MediaArtwork.create(hash['art'])
177
+ hash['type'] = 'unknown' if hash['type'].nil?
178
+ list_item_base(*Creatable.hash_to_arr(hash, %w[album album_artist album_artist_id album_id
179
+ album_release_type album_status bit_rate bpm]), cast,
180
+ hash['channels'], hash['comment'], hash['compilation'], contributors,
181
+ *Creatable.hash_to_arr(hash, %w[country description disc disc_title display_composer
182
+ display_conductor display_lyricist display_orchestra duration
183
+ dyn_path episode episode_guide first_aired id imdb_number
184
+ is_box_set lyrics media_path mood mpaa musicbrainz_artist_id
185
+ musicbrainz_track_id original_date original_title plot_outline
186
+ premiered production_code release_date release_type sample_rate
187
+ season set set_id show_link show_title sort_title
188
+ special_sort_episode special_sort_season studio style tag
189
+ tag_line theme top250 total_discs track trailer tv_show_id
190
+ type unique_id votes watched_episodes writer director]),
191
+ resume, hash['runtime'], stream_details,
192
+ *Creatable.hash_to_arr(hash, %w[date_added file last_played plot title]), art,
193
+ *Creatable.hash_to_arr(hash, %w[play_count fan_art thumbnail label artist artist_id
194
+ display_artist musicbrainz_album_artist_id rating sort_artist
195
+ user_rating year genre]))
196
+ end
197
+
198
+ def list_item_base(album, album_artist, album_artist_id, album_id, album_release_type, album_status, bit_rate,
199
+ bpm, cast, channels, comment, compilation, contributors, country, description, disc,
200
+ disc_title, display_composer, display_conductor, display_lyricist, display_orchestra,
201
+ duration, dyn_path, episode, episode_guide, first_aired, id, imdb_number, is_box_set,
202
+ lyrics, media_path, mood, mpaa, musicbrainz_artist_id, musicbrainz_track_id, original_date,
203
+ original_title, plot_outline, premiered, production_code, release_date, release_type,
204
+ sample_rate, season, set, set_id, show_link, show_title, sort_title, special_sort_episode,
205
+ special_sort_season, studio, style, tag, tag_line, theme, top250, total_discs, track,
206
+ trailer, tv_show_id, type, unique_id, votes, watched_episodes, writer, director, resume,
207
+ runtime, stream_details, date_added, file, last_played, plot, title, art, play_count,
208
+ fan_art, thumbnail, label, artist, artist_id, display_artist, musicbrainz_album_artist_id,
209
+ rating, sort_artist, user_rating, year, genre)
210
+ @album = album
211
+ @album_artist = album_artist
212
+ @album_artist_id = album_artist_id
213
+ @album_id = album_id
214
+ @album_release_type = album_release_type
215
+ @album_status = album_status
216
+ @bit_rate = bit_rate
217
+ @bpm = bpm
218
+ @cast = cast
219
+ @channels = channels
220
+ @comment = comment
221
+ @compilation = compilation
222
+ @contributors = contributors
223
+ @country = country
224
+ @description = description
225
+ @disc = disc
226
+ @disc_title = disc_title
227
+ @display_composer = display_composer
228
+ @display_conductor = display_conductor
229
+ @display_lyricist = display_lyricist
230
+ @display_orchestra = display_orchestra
231
+ @duration = duration
232
+ @dyn_path = dyn_path
233
+ @episode = episode
234
+ @episode_guide = episode_guide
235
+ @first_aired = first_aired
236
+ @id = id
237
+ @imdb_number = imdb_number
238
+ @is_box_set = is_box_set
239
+ @lyrics = lyrics
240
+ @media_path = media_path
241
+ @mood = mood
242
+ @mpaa = mpaa
243
+ @musicbrainz_artist_id = musicbrainz_artist_id
244
+ @musicbrainz_track_id = musicbrainz_track_id
245
+ @original_date = original_date
246
+ @original_title = original_title
247
+ @plot_outline = plot_outline
248
+ @premiered = premiered
249
+ @production_code = production_code
250
+ @release_date = release_date
251
+ @release_type = release_type
252
+ @sample_rate = sample_rate
253
+ @season = season
254
+ @set = set
255
+ @set_id = set_id
256
+ @show_link = show_link
257
+ @show_title = show_title
258
+ @sort_title = sort_title
259
+ @special_sort_episode = special_sort_episode
260
+ @special_sort_season = special_sort_season
261
+ @studio = studio
262
+ @style = style
263
+ @tag = tag
264
+ @tag_line = tag_line
265
+ @theme = theme
266
+ @top250 = top250
267
+ @total_discs = total_discs
268
+ @track = track
269
+ @trailer = trailer
270
+ @tv_show_id = tv_show_id
271
+ @type = type
272
+ @unique_id = unique_id
273
+ @votes = votes
274
+ @watched_episodes = watched_episodes
275
+ @writer = writer
276
+ video_details_file(director, resume, runtime, stream_details, date_added, file, last_played, plot, title,
277
+ art, play_count, fan_art, thumbnail, label)
278
+ audio_details_media(artist, artist_id, display_artist, musicbrainz_album_artist_id, original_date, rating,
279
+ release_date, sort_artist, title, user_rating, votes, year, art, date_added, genre,
280
+ fan_art, thumbnail, label)
244
281
  end
245
282
  end
246
283
 
@@ -248,20 +285,76 @@ module KodiClient
248
285
  class ListItemAll
249
286
  include ListItemBase
250
287
  include Comparable
288
+ extend Creatable
251
289
 
252
290
  attr_reader :channel, :channel_number, :channel_type, :end_time, :hidden, :locked, :start_time,
253
291
  :sub_channel_number
254
292
 
255
- def initialize(hash)
256
- @channel = hash['channel']
257
- @channel_number = hash['channelnumber']
258
- @channel_type = hash['channeltype']
259
- @end_time = hash['endtime']
260
- @hidden = hash['hidden']
261
- @locked = hash['locked']
262
- @start_time = hash['starttime']
263
- @sub_channel_number = hash['subchannelnumber']
264
- list_item_base(hash)
293
+ def self.create(hash)
294
+ return nil if hash.nil?
295
+
296
+ cast = Types::Video::VideoCast.create_list(hash['cast'])
297
+ contributors = Types::Audio::AudioContributor.create_list(hash['contributors'])
298
+ resume = Types::Video::VideoResume.create(hash['resume'])
299
+ stream_details = Types::Video::Streams.create(hash['streamdetails'])
300
+ art = Types::Media::MediaArtwork.create(hash['art'])
301
+ hash['type'] = 'unknown' if hash['type'].nil?
302
+ new(*Creatable.hash_to_arr(hash, %w[channel channel_number channel_type end_time hidden locked start_time
303
+ sub_channel_number album album_artist album_artist_id album_id
304
+ album_release_type album_status bit_rate bpm]), cast,
305
+ hash['channels'], hash['comment'], hash['compilation'], contributors,
306
+ *Creatable.hash_to_arr(hash, %w[country description disc disc_title display_composer
307
+ display_conductor display_lyricist display_orchestra duration
308
+ dyn_path episode episode_guide first_aired id imdb_number
309
+ is_box_set lyrics media_path mood mpaa musicbrainz_artist_id
310
+ musicbrainz_track_id original_date original_title plot_outline
311
+ premiered production_code release_date release_type sample_rate
312
+ season set set_id show_link show_title sort_title
313
+ special_sort_episode special_sort_season studio style tag
314
+ tag_line theme top250 total_discs track trailer tv_show_id
315
+ type unique_id votes watched_episodes writer director]),
316
+ resume, hash['runtime'], stream_details,
317
+ *Creatable.hash_to_arr(hash, %w[date_added file last_played plot title]), art,
318
+ *Creatable.hash_to_arr(hash, %w[play_count fan_art thumbnail label artist artist_id
319
+ display_artist musicbrainz_album_artist_id rating sort_artist
320
+ user_rating year genre]))
321
+ end
322
+
323
+ def initialize(channel, channel_number, channel_type, end_time, hidden, locked, start_time, sub_channel_number,
324
+ album, album_artist, album_artist_id, album_id, album_release_type, album_status, bit_rate,
325
+ bpm, cast, channels, comment, compilation, contributors, country, description, disc,
326
+ disc_title, display_composer, display_conductor, display_lyricist, display_orchestra,
327
+ duration, dyn_path, episode, episode_guide, first_aired, id, imdb_number, is_box_set,
328
+ lyrics, media_path, mood, mpaa, musicbrainz_artist_id, musicbrainz_track_id, original_date,
329
+ original_title, plot_outline, premiered, production_code, release_date, release_type,
330
+ sample_rate, season, set, set_id, show_link, show_title, sort_title, special_sort_episode,
331
+ special_sort_season, studio, style, tag, tag_line, theme, top250, total_discs, track,
332
+ trailer, tv_show_id, type, unique_id, votes, watched_episodes, writer, director, resume,
333
+ runtime, stream_details, date_added, file, last_played, plot, title, art, play_count,
334
+ fan_art, thumbnail, label, artist, artist_id, display_artist, musicbrainz_album_artist_id,
335
+ rating, sort_artist, user_rating, year, genre)
336
+
337
+ @channel = channel
338
+ @channel_number = channel_number
339
+ @channel_type = channel_type
340
+ @end_time = end_time
341
+ @hidden = hidden
342
+ @locked = locked
343
+ @start_time = start_time
344
+ @sub_channel_number = sub_channel_number
345
+
346
+ list_item_base(album, album_artist, album_artist_id, album_id, album_release_type, album_status, bit_rate,
347
+ bpm, cast, channels, comment, compilation, contributors, country, description, disc,
348
+ disc_title, display_composer, display_conductor, display_lyricist, display_orchestra,
349
+ duration, dyn_path, episode, episode_guide, first_aired, id, imdb_number, is_box_set,
350
+ lyrics, media_path, mood, mpaa, musicbrainz_artist_id, musicbrainz_track_id, original_date,
351
+ original_title, plot_outline, premiered, production_code, release_date, release_type,
352
+ sample_rate, season, set, set_id, show_link, show_title, sort_title, special_sort_episode,
353
+ special_sort_season, studio, style, tag, tag_line, theme, top250, total_discs, track,
354
+ trailer, tv_show_id, type, unique_id, votes, watched_episodes, writer, director, resume,
355
+ runtime, stream_details, date_added, file, last_played, plot, title, art, play_count,
356
+ fan_art, thumbnail, label, artist, artist_id, display_artist, musicbrainz_album_artist_id,
357
+ rating, sort_artist, user_rating, year, genre)
265
358
  end
266
359
 
267
360
  def ==(other)
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'kodi_client/global_types/item_types'
4
4
  require 'kodi_client/util/comparable'
5
+ require 'kodi_client/util/creatable'
5
6
 
6
7
  module KodiClient
7
8
  module Types
@@ -10,6 +11,7 @@ module KodiClient
10
11
  # media types
11
12
  module MediaType
12
13
  extend Iterable
14
+
13
15
  VIDEO = 'video'
14
16
  AUDIO = 'audio'
15
17
  ALL = 'all'
@@ -21,28 +23,31 @@ module KodiClient
21
23
 
22
24
  attr_reader :fan_art, :thumbnail
23
25
 
24
- def media_details_base(hash)
26
+ def media_details_base_by_hash(hash)
25
27
  @fan_art = hash['fanart']
26
28
  @thumbnail = hash['thumbnail']
27
- item_details_base(hash)
29
+ item_details_base_by_hash(hash)
30
+ end
31
+
32
+ def media_details_base(fan_art, thumbnail, label)
33
+ @fan_art = fan_art
34
+ @thumbnail = thumbnail
35
+ item_details_base(label)
28
36
  end
29
37
  end
30
38
 
31
39
  # Media.Artwork https://kodi.wiki/view/JSON-RPC_API/v12#Media.Artwork
32
40
  class MediaArtwork
33
41
  include Comparable
42
+ extend Creatable
34
43
 
35
44
  attr_reader :banner, :fan_art, :poster, :thumb
36
45
 
37
- def initialize(hash)
38
- @banner = hash['banner']
39
- @fan_art = hash['fanart']
40
- @poster = hash['poster']
41
- @thumb = hash['thumb']
42
- end
43
-
44
- def ==(other)
45
- compare(self, other)
46
+ def initialize(banner, fan_art, poster, thumb)
47
+ @banner = banner
48
+ @fan_art = fan_art
49
+ @poster = poster
50
+ @thumb = thumb
46
51
  end
47
52
  end
48
53
  end