kodi_client 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bbe8ae31b1c2f5092c6e6fa02a4641d3a73393dcedb44cd08e75f977b85b19b
4
- data.tar.gz: 2d5362b89b5ef4e02542a2fcf9e548a8d33f38575496bbcd48a2b40c1c378003
3
+ metadata.gz: b9680c9f9dfa0c615b2f9291c9b8cf6eebc7eada7f505cbea740392d1713fabf
4
+ data.tar.gz: 965748a029340c66498531049584de14255e91206e5781be0cd41f3d392e32f9
5
5
  SHA512:
6
- metadata.gz: 89796e76db1800a22e165a2bec14b2c3365318f87d7f57cf2861cdf2646ff0ca1e1108b47f0399782f4491fa9c2604e8fadec6f83f878b15e420bd74901510e8
7
- data.tar.gz: f42bf33a0651081ec388e7bf5142d5284e00cd5d8e8d0b07d5766c05ea18197f7c523b97642fe993e6e789576c677945b1949764d592bdecab0d635d661d7edc
6
+ metadata.gz: 98754c7aa49b524de6a1569361dac82f42eb34dc760b599588db0431832c467e5b19f62732f46482da267ff6858db4c2ccbfbedcba768b52e01fb819abb2aa76
7
+ data.tar.gz: 2bea819a70f7bc67009966e2f428d9a64c3514e26a4de7cb5f96dcb57bb74fb9d57abb9812adee779385dd4f0863f2a5811900cd5f0a02f1897102b5b6b1501e
data/kodi_client.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'kodi_client'
5
- spec.version = '0.7.0'
5
+ spec.version = '0.7.1'
6
6
  spec.authors = ['Christian Feier']
7
7
  spec.email = ['christian.feier@gmail.com']
8
8
 
@@ -20,13 +20,11 @@ module KodiClient
20
20
  return if args.nil?
21
21
 
22
22
  @type_mapping = {}
23
- args.map { |it| @type_mapping[it[0]] = Creatable::CreateMap.new(it[1], it[2].nil? ? false : it[2]) }
23
+ args.map { |it| @type_mapping[it[0]] = Creatable.arr_to_mapping(it) }
24
24
  end
25
25
 
26
- # if @type_mapping is nil, it tries to fetch the mapping from here instead
27
- # @return [Hash<String, CreateMap>] an hash containing all the mappings
28
- def lazy_type_mapping
29
- {}
26
+ def self.arr_to_mapping(arr)
27
+ Creatable::CreateMap.new(arr[1], arr[2].nil? ? false : arr[2])
30
28
  end
31
29
 
32
30
  # expects the given hash is a list of hashes and calls #create on each element
@@ -51,7 +49,7 @@ module KodiClient
51
49
  fields = @fields_to_map
52
50
  end
53
51
 
54
- mapping = @type_mapping.nil? ? lazy_type_mapping : @type_mapping
52
+ mapping = @type_mapping.nil? ? {} : @type_mapping
55
53
  args = fields.map do |it|
56
54
  field = it.to_s.gsub('_', '')
57
55
  Creatable.extract_field_from_hash(field, hash, mapping)
@@ -65,22 +63,19 @@ module KodiClient
65
63
  # used
66
64
  # @param hash [Hash] the given hash
67
65
  # @param fields [Array<String>] the fields to extract
68
- # @param mapping [Hash<String, CreateMap>] optional mapping if a field contains a complex type
66
+ # @param mapping [Hash<String>, Array<Array<String>>] optional mapping if a field contains a complex type
69
67
  # @return [Array] an array containing the values of hash[field] in the given field order
70
68
  def self.hash_to_arr(hash, fields, mapping = {})
71
69
  return nil if hash.nil?
72
70
 
71
+ mapping = mapping.map { |it| arr_to_mapping(it) } unless mapping.is_a?(Hash)
72
+
73
73
  fields.map do |it|
74
74
  field = it.to_s.gsub('_', '')
75
75
  extract_field_from_hash(field, hash, mapping)
76
76
  end
77
77
  end
78
78
 
79
- # map to self.hash_to_arr. The mapping is taken from #type_mapping
80
- def hash_to_arr(hash, fields)
81
- Creatable.hash_to_arr(hash, fields, @type_mapping.nil? ? {} : @type_mapping)
82
- end
83
-
84
79
  # extracts the given field from the given hash and optionally applies mapping if given
85
80
  # @param field [String] the field name
86
81
  # @param hash [Hash, nil] the hash where to extract the field from
@@ -18,8 +18,7 @@ module KodiClient
18
18
  sort_name source_id style type years_active art date_added genre fan_art thumbnail
19
19
  label]
20
20
 
21
- type_mapping ['songgenres', Genre, true], ['art', Types::Media::MediaArtwork],
22
- ['roles', AudioArtistRole, true]
21
+ type_mapping ['songgenres', Genre, true], ['art', Types::Media::MediaArtwork], ['roles', AudioArtistRole, true]
23
22
 
24
23
  def initialize(artist, artist_id, born, compilation_artist, description, died, disambiguation, disbanded,
25
24
  formed, gender, instrument, is_album_artist, mood, musicbrainz_artist_id, roles, song_genres,
@@ -10,8 +10,7 @@ module KodiClient
10
10
  attr_reader :art, :date_added, :genre
11
11
 
12
12
  def audio_details_base_mappings
13
- mappings = { 'art' => Extensions::Creatable::CreateMap.new(Types::Media::MediaArtwork) }
14
- mappings.merge(media_details_base_mappings)
13
+ [['art', Types::Media::MediaArtwork]] + media_details_base_mappings
15
14
  end
16
15
 
17
16
  def audio_details_base_by_hash(hash)
@@ -7,6 +7,10 @@ module KodiClient
7
7
  module AudioDetailsMedia
8
8
  include AudioDetailsBase
9
9
 
10
+ def self.included(base)
11
+ base.extend(self)
12
+ end
13
+
10
14
  attr_reader :artist, :artist_id, :display_artist, :musicbrainz_album_artist_id, :original_date, :rating,
11
15
  :release_date, :sort_artist, :title, :user_rating, :votes, :year
12
16
 
@@ -8,7 +8,6 @@ module KodiClient
8
8
  include AudioDetailsMedia
9
9
  include Extensions::Comparable
10
10
  extend Extensions::Creatable
11
- extend AudioDetailsMedia
12
11
 
13
12
  attr_reader :album, :album_artist, :album_artist_id, :album_id, :album_release_type, :bitrate, :bpm, :channels,
14
13
  :comment, :contributors, :disc, :disc_title, :display_composer, :display_conductor,
@@ -16,6 +15,8 @@ module KodiClient
16
15
  :musicbrainz_artist_id, :musicbrainz_track_id, :play_count, :sample_rate, :song_id, :source_id,
17
16
  :track
18
17
 
18
+ type_mapping ['contributors', Types::Audio::AudioContributor, true], *audio_details_media_mappings
19
+
19
20
  fields_to_map %w[album album_artist album_artist_id album_id album_release_type bitrate bpm channels
20
21
  comment contributors disc disc_title display_composer display_conductor display_lyricist
21
22
  display_orchestra duration file genre_id last_played lyrics mood musicbrainz_artist_id
@@ -24,11 +25,6 @@ module KodiClient
24
25
  rating release_date sort_artist title user_rating votes year
25
26
  art date_added genre fan_art thumbnail label]
26
27
 
27
- def self.lazy_type_mapping
28
- mapping = { 'contributors' => Extensions::Creatable::CreateMap.new(Types::Audio::AudioContributor, true) }
29
- mapping.merge(audio_details_media_mappings)
30
- end
31
-
32
28
  def initialize(album, album_artist, album_artist_id, album_id, album_release_type, bitrate, bpm, channels,
33
29
  comment, contributors, disc, disc_title, display_composer, display_conductor, display_lyricist,
34
30
  display_orchestra, duration, file, genre_id, last_played, lyrics, mood, musicbrainz_artist_id,
@@ -8,7 +8,7 @@ module KodiClient
8
8
  attr_reader :label
9
9
 
10
10
  def item_details_base_mappings
11
- {}
11
+ []
12
12
  end
13
13
 
14
14
  def item_details_base_by_hash(hash)
@@ -8,7 +8,6 @@ module KodiClient
8
8
  include ListItemBase
9
9
  include Extensions::Comparable
10
10
  extend Extensions::Creatable
11
- extend ListItemBase
12
11
 
13
12
  attr_reader :channel, :channel_number, :channel_type, :end_time, :hidden, :locked, :start_time,
14
13
  :sub_channel_number
@@ -27,9 +26,7 @@ module KodiClient
27
26
  fan_art thumbnail label artist artist_id display_artist musicbrainz_album_artist_id
28
27
  rating sort_artist user_rating year genre]
29
28
 
30
- def self.lazy_type_mapping
31
- list_item_base_mappings
32
- end
29
+ type_mapping(*list_item_base_mappings)
33
30
 
34
31
  def initialize(channel, channel_number, channel_type, end_time, hidden, locked, start_time, sub_channel_number,
35
32
  album, album_artist, album_artist_id, album_id, album_release_type, album_status, bit_rate,
@@ -8,6 +8,10 @@ module KodiClient
8
8
  include Video::VideoDetailsFile
9
9
  include Audio::AudioDetailsMedia
10
10
 
11
+ def self.included(base)
12
+ base.extend(self)
13
+ end
14
+
11
15
  attr_reader :album, :album_artist, :album_artist_id, :album_id, :album_release_type, :album_status, :bit_rate,
12
16
  :bpm, :cast, :channels, :comment, :compilation, :contributors, :country, :description, :disc,
13
17
  :disc_title, :display_composer, :display_conductor, :display_lyricist, :display_orchestra,
@@ -19,14 +23,13 @@ module KodiClient
19
23
  :trailer, :tv_show_id, :type, :unique_id, :votes, :watched_episodes, :writer
20
24
 
21
25
  def list_item_base_mappings
22
- mappings = {
23
- 'cast' => Extensions::Creatable::CreateMap.new(Video::VideoCast, true),
24
- 'contributors' => Extensions::Creatable::CreateMap.new(Audio::AudioContributor, true),
25
- 'resume' => Extensions::Creatable::CreateMap.new(Video::VideoResume),
26
- 'streamdetails' => Extensions::Creatable::CreateMap.new(Video::StreamDetails),
27
- 'art' => Extensions::Creatable::CreateMap.new(Media::MediaArtwork)
28
- }
29
- mappings.merge(video_details_file_mappings).merge(audio_details_media_mappings)
26
+ [
27
+ ['cast', Video::VideoCast, true],
28
+ ['contributors', Audio::AudioContributor, true],
29
+ ['resume', Video::VideoResume],
30
+ ['streamdetails', Video::StreamDetails],
31
+ ['art', Media::MediaArtwork]
32
+ ] + video_details_file_mappings + audio_details_media_mappings
30
33
  end
31
34
 
32
35
  def list_item_base_by_hash(hash)
@@ -8,7 +8,6 @@ module KodiClient
8
8
  include ListItemBase
9
9
  include Extensions::Comparable
10
10
  extend Extensions::Creatable
11
- extend ListItemBase
12
11
 
13
12
  attr_reader :file, :file_type, :last_modified, :mime_type, :size
14
13
 
@@ -26,9 +25,8 @@ module KodiClient
26
25
  fan_art thumbnail label artist artist_id display_artist musicbrainz_album_artist_id
27
26
  rating sort_artist user_rating year genre]
28
27
 
29
- def self.lazy_type_mapping
30
- list_item_base_mappings
31
- end
28
+ type_mapping(*list_item_base_mappings)
29
+
32
30
 
33
31
  def initialize(file_type, last_modified, mime_type, size,
34
32
  album, album_artist, album_artist_id, album_id, album_release_type, album_status, bit_rate,
@@ -14,7 +14,8 @@ module KodiClient
14
14
  end
15
15
 
16
16
  def media_details_base_by_hash(hash)
17
- media_details_base(*Extensions::Creatable.hash_to_arr(hash, %w[fan_art thumbnail label]), media_details_base_mappings)
17
+ media_details_base(*Extensions::Creatable.hash_to_arr(hash, %w[fan_art thumbnail label]),
18
+ media_details_base_mappings)
18
19
  end
19
20
 
20
21
  def media_details_base(fan_art, thumbnail, label)
@@ -10,17 +10,17 @@ module KodiClient
10
10
  attr_reader :director, :resume, :runtime, :stream_details
11
11
 
12
12
  def video_details_file_mappings
13
- mappings = {
14
- 'resume' => Extensions::Creatable::CreateMap.new(VideoResume),
15
- 'streamdetails' => Extensions::Creatable::CreateMap.new(StreamDetails)
16
- }
17
- mappings.merge(video_details_item_mappings)
13
+ [
14
+ ['resume', VideoResume],
15
+ ['streamdetails', StreamDetails]
16
+ ] + video_details_item_mappings
18
17
  end
19
18
 
20
19
  def video_details_file_by_hash(hash)
21
- video_details_file(*Extensions::Creatable.hash_to_arr(hash, %w[director resume runtime stream_details date_added
22
- file last_played plot title art play_count fan_art
23
- thumbnail label], video_details_file_mappings))
20
+ video_details_file(*Extensions::Creatable.hash_to_arr(hash, %w[director resume runtime stream_details
21
+ date_added file last_played plot title art
22
+ play_count fan_art thumbnail label],
23
+ video_details_file_mappings))
24
24
  end
25
25
 
26
26
  def video_details_file(director, resume, runtime, stream_details, date_added, file, last_played, plot, title,
@@ -15,7 +15,7 @@ module KodiClient
15
15
 
16
16
  def video_details_item_by_hash(hash)
17
17
  video_details_item(*Extensions::Creatable.hash_to_arr(hash, %w[date_added file last_played plot title art
18
- play_count fan_art thumbnail label],
18
+ play_count fan_art thumbnail label],
19
19
  video_details_item_mappings))
20
20
  end
21
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kodi_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Feier