kodi_client 0.5.7 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/kodi_client.gemspec +3 -3
  4. data/lib/kodi_client/Chainable.rb +1 -2
  5. data/lib/kodi_client/kodi_module.rb +0 -7
  6. data/lib/kodi_client/method/addons.rb +6 -21
  7. data/lib/kodi_client/method/application.rb +1 -4
  8. data/lib/kodi_client/method/audio_library.rb +46 -0
  9. data/lib/kodi_client/method/favourites.rb +1 -4
  10. data/lib/kodi_client/method/files.rb +85 -0
  11. data/lib/kodi_client/method/gui.rb +1 -4
  12. data/lib/kodi_client/method/input.rb +1 -5
  13. data/lib/kodi_client/method/player.rb +1 -6
  14. data/lib/kodi_client/method/profiles.rb +1 -4
  15. data/lib/kodi_client/method/system.rb +1 -5
  16. data/lib/kodi_client/{global_types → types}/addon_types.rb +9 -26
  17. data/lib/kodi_client/{global_types → types}/application_types.rb +16 -25
  18. data/lib/kodi_client/types/audio_types.rb +221 -0
  19. data/lib/kodi_client/{global_types → types}/favourites_types.rb +1 -10
  20. data/lib/kodi_client/types/files_types.rb +63 -0
  21. data/lib/kodi_client/{global_types → types}/global_types.rb +0 -4
  22. data/lib/kodi_client/{global_types → types}/gui_types.rb +2 -14
  23. data/lib/kodi_client/{global_types → types}/input_types.rb +0 -2
  24. data/lib/kodi_client/{global_types → types}/item_types.rb +5 -1
  25. data/lib/kodi_client/{global_types → types}/list_types.rb +193 -64
  26. data/lib/kodi_client/{global_types → types}/media_types.rb +5 -7
  27. data/lib/kodi_client/{global_types → types}/player_type.rb +11 -36
  28. data/lib/kodi_client/{global_types → types}/profiles_types.rb +2 -17
  29. data/lib/kodi_client/{global_types → types}/pvr_type.rb +0 -2
  30. data/lib/kodi_client/{global_types → types}/system_types.rb +0 -3
  31. data/lib/kodi_client/{global_types → types}/video_types.rb +32 -25
  32. data/lib/kodi_client/util/creatable.rb +69 -15
  33. data/lib/kodi_client.rb +37 -9
  34. metadata +23 -20
  35. data/lib/kodi_client/global_types/audio_types.rb +0 -88
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/util/comparable'
4
- require 'kodi_client/util/creatable'
5
- require 'kodi_client/global_types/video_types'
6
- require 'kodi_client/global_types/audio_types'
7
-
8
3
  module KodiClient
9
4
  module Types
10
5
  module List
@@ -28,11 +23,7 @@ module KodiClient
28
23
 
29
24
  attr_reader :list_start, :list_end, :total
30
25
 
31
- def self.create(hash)
32
- return nil if hash.nil?
33
-
34
- new(hash['start'], hash['end'], hash['total'])
35
- end
26
+ fields_to_map %w[start end total]
36
27
 
37
28
  def initialize(list_start, list_end, total)
38
29
  @list_start = list_start
@@ -153,6 +144,95 @@ module KodiClient
153
144
  YEAR = 'year'
154
145
  end
155
146
 
147
+ # List.Fields.Files https://kodi.wiki/view/JSON-RPC_API/v12#List.Fields.Files
148
+ module ListFieldFiles
149
+ extend Iterable
150
+
151
+ ALBUM = 'album'
152
+ ALBUMARTIST = 'albumartist'
153
+ ALBUMARTISTID = 'albumartistid'
154
+ ALBUMID = 'albumid'
155
+ ALBUMLABEL = 'albumlabel'
156
+ ART = 'art'
157
+ ARTIST = 'artist'
158
+ ARTISTID = 'artistid'
159
+ CAST = 'cast'
160
+ COMMENT = 'comment'
161
+ COUNTRY = 'country'
162
+ DATEADDED = 'dateadded'
163
+ DESCRIPTION = 'description'
164
+ DIRECTOR = 'director'
165
+ DISC = 'disc'
166
+ DISPLAYARTIST = 'displayartist'
167
+ DURATION = 'duration'
168
+ EPISODE = 'episode'
169
+ EPISODEGUIDE = 'episodeguide'
170
+ FANART = 'fanart'
171
+ FILE = 'file'
172
+ FIRSTAIRED = 'firstaired'
173
+ GENRE = 'genre'
174
+ GENREID = 'genreid'
175
+ IMDBNUMBER = 'imdbnumber'
176
+ LASTMODIFIED = 'lastmodified'
177
+ LASTPLAYED = 'lastplayed'
178
+ LYRICS = 'lyrics'
179
+ MIMETYPE = 'mimetype'
180
+ MOOD = 'mood'
181
+ MPAA = 'mpaa'
182
+ MUSICBRAINZALBUMARTISTID = 'musicbrainzalbumartistid'
183
+ MUSICBRAINZALBUMID = 'musicbrainzalbumid'
184
+ MUSICBRAINZARTISTID = 'musicbrainzartistid'
185
+ MUSICBRAINZTRACKID = 'musicbrainztrackid'
186
+ ORIGINALTITLE = 'originaltitle'
187
+ PLAYCOUNT = 'playcount'
188
+ PLOT = 'plot'
189
+ PLOTOUTLINE = 'plotoutline'
190
+ PREMIERED = 'premiered'
191
+ PRODUCTIONCODE = 'productioncode'
192
+ RATING = 'rating'
193
+ RESUME = 'resume'
194
+ RUNTIME = 'runtime'
195
+ SEASON = 'season'
196
+ SET = 'set'
197
+ SETID = 'setid'
198
+ SHOWLINK = 'showlink'
199
+ SHOWTITLE = 'showtitle'
200
+ SIZE = 'size'
201
+ SORTTITLE = 'sorttitle'
202
+ SPECIALSORTEPISODE = 'specialsortepisode'
203
+ SPECIALSORTSEASON = 'specialsortseason'
204
+ STREAMDETAILS = 'streamdetails'
205
+ STUDIO = 'studio'
206
+ STYLE = 'style'
207
+ TAG = 'tag'
208
+ TAGLINE = 'tagline'
209
+ THEME = 'theme'
210
+ THUMBNAIL = 'thumbnail'
211
+ TITLE = 'title'
212
+ TOP250 = 'top250'
213
+ TRACK = 'track'
214
+ TRAILER = 'trailer'
215
+ TVSHOWID = 'tvshowid'
216
+ UNIQUEID = 'uniqueid'
217
+ VOTES = 'votes'
218
+ WATCHEDEPISODES = 'watchedepisodes'
219
+ WRITER = 'writer'
220
+ YEAR = 'year'
221
+ end
222
+
223
+ # File/Label tuple
224
+ class FileLabel
225
+ include Comparable
226
+ extend Creatable
227
+
228
+ attr_reader :file, :label
229
+
230
+ def initialize(file, label)
231
+ @file = file
232
+ @label = label
233
+ end
234
+ end
235
+
156
236
  # List.Item.Base https://kodi.wiki/view/JSON-RPC_API/v12#List.Item.Base
157
237
  module ListItemBase
158
238
  include Video::VideoDetailsFile
@@ -168,31 +248,34 @@ module KodiClient
168
248
  :special_sort_season, :studio, :style, :tag, :tag_line, :theme, :top250, :total_discs, :track,
169
249
  :trailer, :tv_show_id, :type, :unique_id, :votes, :watched_episodes, :writer
170
250
 
251
+ def list_item_base_mappings
252
+ mappings = {
253
+ 'cast' => Creatable::CreateMap.new(Video::VideoCast, true),
254
+ 'contributors' => Creatable::CreateMap.new(Audio::AudioContributor, true),
255
+ 'resume' => Creatable::CreateMap.new(Video::VideoResume),
256
+ 'streamdetails' => Creatable::CreateMap.new(Video::Streams),
257
+ 'art' => Creatable::CreateMap.new(Media::MediaArtwork)
258
+ }
259
+ mappings.merge(video_details_file_mappings).merge(audio_details_media_mappings)
260
+ end
261
+
171
262
  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]))
263
+ return nil if hash.nil?
264
+
265
+ list_item_base(*Creatable.hash_to_arr(
266
+ hash, %w[album album_artist album_artist_id album_id album_release_type album_status bit_rate
267
+ bpm cast channels comment compilation contributors country description disc
268
+ disc_title display_composer display_conductor display_lyricist display_orchestra
269
+ duration dyn_path episode episode_guide first_aired id imdb_number is_box_set
270
+ lyrics media_path mood mpaa musicbrainz_artist_id musicbrainz_track_id original_date
271
+ original_title plot_outline premiered production_code release_date release_type
272
+ sample_rate season set set_id show_link show_title sort_title special_sort_episode
273
+ special_sort_season studio style tag tag_line theme top250 total_discs track
274
+ trailer tv_show_id type unique_id votes watched_episodes writer director resume
275
+ runtime stream_details date_added file last_played plot title art play_count
276
+ fan_art thumbnail label artist artist_id display_artist musicbrainz_album_artist_id
277
+ rating sort_artist user_rating year genre], list_item_base_mappings
278
+ ))
196
279
  end
197
280
 
198
281
  def list_item_base(album, album_artist, album_artist_id, album_id, album_release_type, album_status, bit_rate,
@@ -286,38 +369,27 @@ module KodiClient
286
369
  include ListItemBase
287
370
  include Comparable
288
371
  extend Creatable
372
+ extend ListItemBase
289
373
 
290
374
  attr_reader :channel, :channel_number, :channel_type, :end_time, :hidden, :locked, :start_time,
291
375
  :sub_channel_number
292
376
 
293
- def self.create(hash)
294
- return nil if hash.nil?
377
+ fields_to_map %w[channel channel_number channel_type end_time hidden locked start_time sub_channel_number
378
+ album album_artist album_artist_id album_id album_release_type album_status bit_rate
379
+ bpm cast channels comment compilation contributors country description disc
380
+ disc_title display_composer display_conductor display_lyricist display_orchestra
381
+ duration dyn_path episode episode_guide first_aired id imdb_number is_box_set
382
+ lyrics media_path mood mpaa musicbrainz_artist_id musicbrainz_track_id original_date
383
+ original_title plot_outline premiered production_code release_date release_type
384
+ sample_rate season set set_id show_link show_title sort_title special_sort_episode
385
+ special_sort_season studio style tag tag_line theme top250 total_discs track
386
+ trailer tv_show_id type unique_id votes watched_episodes writer director resume
387
+ runtime stream_details date_added file last_played plot title art play_count
388
+ fan_art thumbnail label artist artist_id display_artist musicbrainz_album_artist_id
389
+ rating sort_artist user_rating year genre]
295
390
 
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]))
391
+ def self.lazy_type_mapping
392
+ list_item_base_mappings
321
393
  end
322
394
 
323
395
  def initialize(channel, channel_number, channel_type, end_time, hidden, locked, start_time, sub_channel_number,
@@ -333,7 +405,6 @@ module KodiClient
333
405
  runtime, stream_details, date_added, file, last_played, plot, title, art, play_count,
334
406
  fan_art, thumbnail, label, artist, artist_id, display_artist, musicbrainz_album_artist_id,
335
407
  rating, sort_artist, user_rating, year, genre)
336
-
337
408
  @channel = channel
338
409
  @channel_number = channel_number
339
410
  @channel_type = channel_type
@@ -342,6 +413,7 @@ module KodiClient
342
413
  @locked = locked
343
414
  @start_time = start_time
344
415
  @sub_channel_number = sub_channel_number
416
+ type = type.nil? ? 'unknown' : type
345
417
 
346
418
  list_item_base(album, album_artist, album_artist_id, album_id, album_release_type, album_status, bit_rate,
347
419
  bpm, cast, channels, comment, compilation, contributors, country, description, disc,
@@ -356,9 +428,66 @@ module KodiClient
356
428
  fan_art, thumbnail, label, artist, artist_id, display_artist, musicbrainz_album_artist_id,
357
429
  rating, sort_artist, user_rating, year, genre)
358
430
  end
431
+ end
359
432
 
360
- def ==(other)
361
- compare(self, other)
433
+ # List.Item.File https://kodi.wiki/view/JSON-RPC_API/v12#List.Item.File
434
+ class ListItemFile
435
+ include ListItemBase
436
+ include Comparable
437
+ extend Creatable
438
+ extend ListItemBase
439
+
440
+ attr_reader :file, :file_type, :last_modified, :mime_type, :size
441
+
442
+ fields_to_map %w[file_type last_modified mime_type size
443
+ album album_artist album_artist_id album_id album_release_type album_status bit_rate
444
+ bpm cast channels comment compilation contributors country description disc
445
+ disc_title display_composer display_conductor display_lyricist display_orchestra
446
+ duration dyn_path episode episode_guide first_aired id imdb_number is_box_set
447
+ lyrics media_path mood mpaa musicbrainz_artist_id musicbrainz_track_id original_date
448
+ original_title plot_outline premiered production_code release_date release_type
449
+ sample_rate season set set_id show_link show_title sort_title special_sort_episode
450
+ special_sort_season studio style tag tag_line theme top250 total_discs track
451
+ trailer tv_show_id type unique_id votes watched_episodes writer director resume
452
+ runtime stream_details date_added file last_played plot title art play_count
453
+ fan_art thumbnail label artist artist_id display_artist musicbrainz_album_artist_id
454
+ rating sort_artist user_rating year genre]
455
+
456
+ def self.lazy_type_mapping
457
+ list_item_base_mappings
458
+ end
459
+
460
+ def initialize(file_type, last_modified, mime_type, size,
461
+ album, album_artist, album_artist_id, album_id, album_release_type, album_status, bit_rate,
462
+ bpm, cast, channels, comment, compilation, contributors, country, description, disc,
463
+ disc_title, display_composer, display_conductor, display_lyricist, display_orchestra,
464
+ duration, dyn_path, episode, episode_guide, first_aired, id, imdb_number, is_box_set,
465
+ lyrics, media_path, mood, mpaa, musicbrainz_artist_id, musicbrainz_track_id, original_date,
466
+ original_title, plot_outline, premiered, production_code, release_date, release_type,
467
+ sample_rate, season, set, set_id, show_link, show_title, sort_title, special_sort_episode,
468
+ special_sort_season, studio, style, tag, tag_line, theme, top250, total_discs, track,
469
+ trailer, tv_show_id, type, unique_id, votes, watched_episodes, writer, director, resume,
470
+ runtime, stream_details, date_added, file, last_played, plot, title, art, play_count,
471
+ fan_art, thumbnail, label, artist, artist_id, display_artist, musicbrainz_album_artist_id,
472
+ rating, sort_artist, user_rating, year, genre)
473
+ @file = file
474
+ @file_type = file_type
475
+ @last_modified = last_modified
476
+ @mime_type = mime_type
477
+ @size = size
478
+ type = type.nil? ? 'unknown' : type
479
+ list_item_base(album, album_artist, album_artist_id, album_id, album_release_type, album_status, bit_rate,
480
+ bpm, cast, channels, comment, compilation, contributors, country, description, disc,
481
+ disc_title, display_composer, display_conductor, display_lyricist, display_orchestra,
482
+ duration, dyn_path, episode, episode_guide, first_aired, id, imdb_number, is_box_set,
483
+ lyrics, media_path, mood, mpaa, musicbrainz_artist_id, musicbrainz_track_id, original_date,
484
+ original_title, plot_outline, premiered, production_code, release_date, release_type,
485
+ sample_rate, season, set, set_id, show_link, show_title, sort_title, special_sort_episode,
486
+ special_sort_season, studio, style, tag, tag_line, theme, top250, total_discs, track,
487
+ trailer, tv_show_id, type, unique_id, votes, watched_episodes, writer, director, resume,
488
+ runtime, stream_details, date_added, file, last_played, plot, title, art, play_count,
489
+ fan_art, thumbnail, label, artist, artist_id, display_artist, musicbrainz_album_artist_id,
490
+ rating, sort_artist, user_rating, year, genre)
362
491
  end
363
492
  end
364
493
 
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/global_types/item_types'
4
- require 'kodi_client/util/comparable'
5
- require 'kodi_client/util/creatable'
6
-
7
3
  module KodiClient
8
4
  module Types
9
5
  module Media
@@ -23,10 +19,12 @@ module KodiClient
23
19
 
24
20
  attr_reader :fan_art, :thumbnail
25
21
 
22
+ def media_details_base_mappings
23
+ item_details_base_mappings
24
+ end
25
+
26
26
  def media_details_base_by_hash(hash)
27
- @fan_art = hash['fanart']
28
- @thumbnail = hash['thumbnail']
29
- item_details_base_by_hash(hash)
27
+ media_details_base(*Creatable.hash_to_arr(hash, %w[fan_art thumbnail label]), media_details_base_mappings)
30
28
  end
31
29
 
32
30
  def media_details_base(fan_art, thumbnail, label)
@@ -1,10 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/global_types/item_types'
4
- require 'kodi_client/global_types/global_types'
5
- require 'kodi_client/util/comparable'
6
- require 'kodi_client/util/iterable'
7
-
8
3
  module KodiClient
9
4
  module Types
10
5
  module Player
@@ -195,35 +190,20 @@ module KodiClient
195
190
  :live, :party_mode, :percentage, :playlist_id, :position, :repeat, :shuffled, :speed,
196
191
  :subtitle_enabled, :subtitles, :time, :total_time, :type, :video_streams
197
192
 
198
- def self.create(hash)
199
- return nil if hash.nil?
200
-
201
- audio_streams = AudioStream.create_list(hash['audiostreams'])
202
- current_audio_stream = AudioStream.create(hash['currentaudiostream'])
203
- current_subtitle = Subtitle.create(hash['currentsubtitle'])
204
- current_video_stream = VideoStream.create(hash['currentvideostream'])
205
- subtitles = Subtitle.create_list(hash['subtitles'])
206
- time = Types::Global::GlobalTime.create(hash['time'])
207
- total_time = Types::Global::GlobalTime.create(hash['totaltime'])
208
- video_streams = VideoStream.create_list(hash['videostreams'])
209
-
210
- hash['type'] = PlayerType::VIDEO if hash['type'].nil?
211
- hash['playlistid'] = -1 if hash['playlistid'].nil?
212
- hash['position'] = -1 if hash['position'].nil?
213
- hash['repeat'] = PlayerRepeat::OFF if hash['repeat'].nil?
214
-
215
- new(audio_streams, *Creatable.hash_to_arr(hash, %w[cache_percentage can_change_speed can_move
216
- can_repeat can_rotate can_seek can_shuffle can_zoom]),
217
- current_audio_stream, current_subtitle, current_video_stream,
218
- *Creatable.hash_to_arr(hash, %w[live party_mode percentage playlist_id position repeat
219
- shuffled speed subtitle_enabled]), subtitles, time, total_time,
220
- hash['type'], video_streams)
221
- end
193
+ type_mapping ['audiostreams', AudioStream, true], ['currentaudiostream', AudioStream],
194
+ ['currentsubtitle', Subtitle], ['currentvideostream', VideoStream],
195
+ ['subtitles', Subtitle, true], ['time', Global::GlobalTime],
196
+ ['totaltime', Global::GlobalTime], ['videostreams', VideoStream, true]
222
197
 
223
198
  def initialize(audio_streams, cache_percentage, can_change_speed, can_move, can_repeat, can_rotate, can_seek,
224
199
  can_shuffle, can_zoom, current_audio_stream, current_subtitle, current_video_stream, live,
225
200
  party_mode, percentage, playlist_id, position, repeat, shuffled, speed,
226
201
  subtitle_enabled, subtitles, time, total_time, type, video_streams)
202
+ type = type.nil? ? PlayerType::VIDEO : type
203
+ playlist_id = playlist_id.nil? ? -1 : playlist_id
204
+ position = position.nil? ? -1 : position
205
+ repeat = repeat.nil? ? PlayerRepeat::OFF : repeat
206
+
227
207
  @audio_streams = audio_streams
228
208
  @cache_percentage = cache_percentage
229
209
  @can_change_speed = can_change_speed
@@ -299,14 +279,9 @@ module KodiClient
299
279
  include Comparable
300
280
  extend Creatable
301
281
 
302
- def self.create(hash)
303
- return nil if hash.nil?
282
+ attr_reader :percentage, :time, :total_time
304
283
 
305
- time = Types::Global::GlobalTime.create(hash['time'])
306
- total_time = Types::Global::GlobalTime.create(hash['totaltime'])
307
-
308
- new(hash['percentage'], time, total_time)
309
- end
284
+ type_mapping ['time', Global::GlobalTime], ['totaltime', Global::GlobalTime]
310
285
 
311
286
  def initialize(percentage, time, total_time)
312
287
  @percentage = percentage
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/util/comparable'
4
- require 'kodi_client/util/iterable'
5
- require 'kodi_client/global_types/item_types'
6
-
7
3
  module KodiClient
8
4
  module Types
9
5
  module Profiles
@@ -24,11 +20,7 @@ module KodiClient
24
20
 
25
21
  attr_reader :lock_mode, :thumbnail
26
22
 
27
- def self.create(hash)
28
- return nil if hash.nil?
29
-
30
- new(*Creatable.hash_to_arr(hash, %w[lock_mode thumbnail label]))
31
- end
23
+ fields_to_map %w[lock_mode thumbnail label]
32
24
 
33
25
  def initialize(lock_mode, thumbnail, label)
34
26
  @lock_mode = lock_mode
@@ -48,14 +40,7 @@ module KodiClient
48
40
 
49
41
  attr_reader :limits, :profiles
50
42
 
51
- def self.create(hash)
52
- return nil if hash.nil?
53
-
54
- limits = Types::List::ListLimitsReturned.create(hash['limits'])
55
- profiles = Types::Profiles::DetailsProfile.create_list(hash['profiles'])
56
-
57
- new(limits, profiles)
58
- end
43
+ type_mapping ['limits', List::ListLimitsReturned], ['profiles', DetailsProfile, true]
59
44
 
60
45
  def initialize(limits, profiles)
61
46
  @limits = limits
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/util/iterable'
4
-
5
3
  module KodiClient
6
4
  module Types
7
5
  module PVR
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/util/iterable'
4
- require 'kodi_client/util/comparable'
5
-
6
3
  module KodiClient
7
4
  module Types
8
5
  module System
@@ -1,23 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kodi_client/global_types/media_types'
4
- require 'kodi_client/global_types/player_type'
5
- require 'kodi_client/util/comparable'
6
- require 'kodi_client/util/creatable'
7
-
8
3
  module KodiClient
9
4
  module Types
10
5
  module Video
11
-
12
6
  # Video.Details.Base https://kodi.wiki/view/JSON-RPC_API/v12#Video.Details.Base
13
7
  module VideoDetailsBase
14
8
  include Media::MediaDetailsBase
15
9
 
16
10
  attr_reader :art, :play_count
17
11
 
12
+ def video_details_base_mappings
13
+ media_details_base_mappings
14
+ end
15
+
18
16
  def video_details_base_by_hash(hash)
19
- @art = Types::Media::MediaArtwork.create(hash['art'])
20
- video_details_base(art, ['playcount'], *Creatable.hash_to_arr(hash, %w[fan_art thumbnail label]))
17
+ video_details_base(*Creatable.hash_to_arr(hash, %w[art play_count fan_art thumbnail label],
18
+ video_details_base_mappings))
21
19
  end
22
20
 
23
21
  def video_details_base(art, play_count, fan_art, thumbnail, label)
@@ -48,9 +46,13 @@ module KodiClient
48
46
 
49
47
  attr_reader :title
50
48
 
49
+ def video_details_media_mappings
50
+ video_details_base_mappings
51
+ end
52
+
51
53
  def video_details_media_by_hash(hash)
52
- art = Types::Media::MediaArtwork.create(hash['art'])
53
- video_details_media(hash['title'], art, *Creatable.hash_to_arr(hash, %w[play_count fan_art thumbnail label]))
54
+ video_details_media(*Creatable.hash_to_arr(hash, %w[title art play_count fan_art thumbnail label]),
55
+ video_details_base_mappings)
54
56
  end
55
57
 
56
58
  def video_details_media(title, art, play_count, fan_art, thumbnail, label)
@@ -65,10 +67,14 @@ module KodiClient
65
67
 
66
68
  attr_reader :date_added, :file, :last_played, :plot
67
69
 
70
+ def video_details_item_mappings
71
+ video_details_media_mappings
72
+ end
73
+
68
74
  def video_details_item_by_hash(hash)
69
- art = Types::Media::MediaArtwork.create(hash['art'])
70
- video_details_item(*Creatable.hash_to_arr(hash, %w[date_added file last_played plot title]), art,
71
- *Creatable.hash_to_arr(hash, %w[play_count fan_art thumbnail label]))
75
+ video_details_item(*Creatable.hash_to_arr(hash, %w[date_added file last_played plot title art
76
+ play_count fan_art thumbnail label],
77
+ video_details_item_mappings))
72
78
  end
73
79
 
74
80
  def video_details_item(date_added, file, last_played, plot, title, art, play_count, fan_art, thumbnail, label)
@@ -86,13 +92,18 @@ module KodiClient
86
92
 
87
93
  attr_reader :director, :resume, :runtime, :stream_details
88
94
 
95
+ def video_details_file_mappings
96
+ mappings = {
97
+ 'resume' => Creatable::CreateMap.new(VideoResume),
98
+ 'streamdetails' => Creatable::CreateMap.new(Streams)
99
+ }
100
+ mappings.merge(video_details_item_mappings)
101
+ end
102
+
89
103
  def video_details_file_by_hash(hash)
90
- resume = VideoResume.create(hash['resume'])
91
- stream_details = Streams.create(hash['streamdetails'])
92
- art = Types::Media::MediaArtwork.create(hash['art'])
93
- video_details_file(hash['director'], resume, hash['runtime'], stream_details,
94
- *Creatable.hash_to_arr(hash, %w[date_added file last_played plot title]), art,
95
- *Creatable.hash_to_arr(hash, %w[play_count fan_art thumbnail label]))
104
+ video_details_file(*Creatable.hash_to_arr(hash, %w[director resume runtime stream_details date_added
105
+ file last_played plot title art play_count fan_art
106
+ thumbnail label], video_details_file_mappings))
96
107
  end
97
108
 
98
109
  def video_details_file(director, resume, runtime, stream_details, date_added, file, last_played, plot, title,
@@ -125,12 +136,8 @@ module KodiClient
125
136
 
126
137
  attr_reader :audio, :subtitle, :video
127
138
 
128
- def self.create(hash)
129
- audio = Types::Player::AudioStream.create_list(hash['audio'])
130
- subtitle = Types::Player::Subtitle.create_list(hash['subtitle'])
131
- video = Types::Player::VideoStream.create_list(hash['video'])
132
- new(audio, subtitle, video)
133
- end
139
+ type_mapping ['audio', Player::AudioStream, true], ['subtitle', Player::Subtitle, true],
140
+ ['video', Player::VideoStream, true]
134
141
 
135
142
  def initialize(audio, subtitle, video)
136
143
  @audio = audio