kodi_client 0.5.7 → 0.6.3

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.
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
@@ -5,6 +5,68 @@ module KodiClient
5
5
  # creates a create and create_list method by hash
6
6
  module Creatable
7
7
 
8
+ def fields_to_map(fields)
9
+ @fields_to_map = fields
10
+ end
11
+
12
+ def type_mapping(*args)
13
+ return if args.nil?
14
+
15
+ @type_mapping = {}
16
+ args.map { |it| @type_mapping[it[0]] = Creatable::CreateMap.new(it[1], it[2].nil? ? false : it[2]) }
17
+ end
18
+
19
+ def lazy_type_mapping
20
+ {}
21
+ end
22
+
23
+ def create_list(hash)
24
+ hash.nil? ? [] : hash.map { |it| create(it) }.reject(&:nil?)
25
+ end
26
+
27
+ def create(hash)
28
+ return nil if hash.nil?
29
+
30
+ if @fields_to_map.nil? || @fields_to_map.empty?
31
+ fields = @kodi_fields
32
+ return nil if @kodi_fields.none? { |it| !hash[it.to_s.gsub('_', '')].nil? }
33
+ else
34
+ fields = @fields_to_map
35
+ end
36
+
37
+ mapping = @type_mapping.nil? ? lazy_type_mapping : @type_mapping
38
+ args = fields.map do |it|
39
+ field = it.to_s.gsub('_', '')
40
+ Creatable.extract_field_from_hash(field, hash, mapping)
41
+ end
42
+
43
+ new(*args)
44
+ end
45
+
46
+ def self.hash_to_arr(hash, fields, mapping = {})
47
+ return nil if hash.nil?
48
+
49
+ fields.map do |it|
50
+ field = it.to_s.gsub('_', '')
51
+ extract_field_from_hash(field, hash, mapping)
52
+ end
53
+ end
54
+
55
+ def hash_to_arr(hash, fields)
56
+ Creatable.hash_to_arr(hash, fields, @type_mapping.nil? ? {} : @type_mapping)
57
+ end
58
+
59
+ def self.extract_field_from_hash(field, hash, mapping)
60
+ map = mapping[field]
61
+ return nil if hash[field].nil? && map.nil?
62
+
63
+ return hash[field] if map.nil?
64
+
65
+ return map.type.create_list(hash[field]) if map.is_list
66
+
67
+ map.type.create(hash[field])
68
+ end
69
+
8
70
  def attr_accessor(*args)
9
71
  attr_reader(*args)
10
72
  attr_writer(*args)
@@ -30,23 +92,15 @@ module KodiClient
30
92
  end
31
93
  end
32
94
 
33
- def create_list(hash)
34
- hash.nil? ? [] : hash.map { |it| create(it) }
35
- end
36
-
37
- def create(hash)
38
- return nil if hash.nil?
39
- return nil if @kodi_fields.none? { |it| !hash[it].nil? }
95
+ # mapping class with the type and if it is a list field or not
96
+ class CreateMap
40
97
 
41
- new(*@kodi_fields.map { |it| hash[it] })
42
- end
43
-
44
- def self.hash_to_arr(hash, fields)
45
- fields.map { |it| hash[it.to_s.gsub('_', '')].nil? ? nil : hash[it.to_s.gsub('_', '')] }
46
- end
98
+ attr_reader :type, :is_list
47
99
 
48
- def hash_to_arr(hash, fields)
49
- Creatable.hash_to_arr(hash, fields)
100
+ def initialize(type, is_list = false)
101
+ @type = type
102
+ @is_list = is_list
103
+ end
50
104
  end
51
105
  end
52
106
  end
data/lib/kodi_client.rb CHANGED
@@ -4,15 +4,41 @@ require 'http'
4
4
  require 'json'
5
5
 
6
6
  require 'kodi_client/Chainable'
7
+
8
+ require 'kodi_client/util/comparable'
9
+ require 'kodi_client/util/creatable'
10
+ require 'kodi_client/util/iterable'
11
+
12
+ require 'kodi_client/kodi_module'
13
+ require 'kodi_client/options'
14
+
7
15
  require 'kodi_client/method/addons'
16
+ require 'kodi_client/method/audio_library'
8
17
  require 'kodi_client/method/application'
9
18
  require 'kodi_client/method/favourites'
19
+ require 'kodi_client/method/files'
10
20
  require 'kodi_client/method/gui'
11
21
  require 'kodi_client/method/input'
12
22
  require 'kodi_client/method/player'
13
23
  require 'kodi_client/method/profiles'
14
24
  require 'kodi_client/method/system'
15
25
 
26
+ require 'kodi_client/types/global_types'
27
+ require 'kodi_client/types/item_types'
28
+ require 'kodi_client/types/media_types'
29
+ require 'kodi_client/types/player_type'
30
+ require 'kodi_client/types/pvr_type'
31
+ require 'kodi_client/types/audio_types'
32
+ require 'kodi_client/types/video_types'
33
+ require 'kodi_client/types/system_types'
34
+ require 'kodi_client/types/list_types'
35
+ require 'kodi_client/types/application_types'
36
+ require 'kodi_client/types/addon_types'
37
+ require 'kodi_client/types/gui_types'
38
+ require 'kodi_client/types/favourites_types'
39
+ require 'kodi_client/types/profiles_types'
40
+ require 'kodi_client/types/input_types'
41
+ require 'kodi_client/types/files_types'
16
42
 
17
43
  # client for Kodi rest api https://kodi.wiki/view/JSON-RPC_API/v12
18
44
  module KodiClient
@@ -22,17 +48,19 @@ module KodiClient
22
48
  class Client
23
49
  include Chainable
24
50
 
25
- attr_reader :addons, :application, :gui, :player, :input, :favourites, :system, :profiles
51
+ attr_reader :audio_library, :addons, :application, :favourites, :files, :gui, :input, :player, :profiles, :system
26
52
 
27
53
  def initialize
28
- @addons = KodiClient::Modules::Addons.new
29
- @application = KodiClient::Modules::Application.new
30
- @favourites = KodiClient::Modules::Favourites.new
31
- @gui = KodiClient::Modules::GUI.new
32
- @input = KodiClient::Modules::Input.new
33
- @player = KodiClient::Modules::Player.new
34
- @profiles = KodiClient::Modules::Profiles.new
35
- @system = KodiClient::Modules::System.new
54
+ @addons = KodiClient::Method::Addons.new
55
+ @audio_library = KodiClient::Method::AudioLibrary.new
56
+ @application = KodiClient::Method::Application.new
57
+ @favourites = KodiClient::Method::Favourites.new
58
+ @files = KodiClient::Method::Files.new
59
+ @gui = KodiClient::Method::GUI.new
60
+ @input = KodiClient::Method::Input.new
61
+ @player = KodiClient::Method::Player.new
62
+ @profiles = KodiClient::Method::Profiles.new
63
+ @system = KodiClient::Method::System.new
36
64
  end
37
65
 
38
66
  def apply_options_to_methods(options)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kodi_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Feier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-17 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -25,9 +25,9 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.0.4
27
27
  description: A client for the Kodi JSON API v12, currently implemented methods are
28
- addons, application, favourites, gui, input, player, profile and system (more will
29
- be added with the time). For more information how to use it and how to activate
30
- Remote Control in Kodi, please check the github page https://github.com/cfe86/RubyKodiClient
28
+ Addons, Application, Favourites, Files, GUI, Input, Player, Profiles and System
29
+ (more will be added with the time). For more information how to use it and how to
30
+ activate Remote Control in Kodi, please check the github page https://github.com/cfe86/RubyKodiClient
31
31
  email:
32
32
  - christian.feier@gmail.com
33
33
  executables: []
@@ -43,31 +43,34 @@ files:
43
43
  - kodi_client.gemspec
44
44
  - lib/kodi_client.rb
45
45
  - lib/kodi_client/Chainable.rb
46
- - lib/kodi_client/global_types/addon_types.rb
47
- - lib/kodi_client/global_types/application_types.rb
48
- - lib/kodi_client/global_types/audio_types.rb
49
- - lib/kodi_client/global_types/favourites_types.rb
50
- - lib/kodi_client/global_types/global_types.rb
51
- - lib/kodi_client/global_types/gui_types.rb
52
- - lib/kodi_client/global_types/input_types.rb
53
- - lib/kodi_client/global_types/item_types.rb
54
- - lib/kodi_client/global_types/list_types.rb
55
- - lib/kodi_client/global_types/media_types.rb
56
- - lib/kodi_client/global_types/player_type.rb
57
- - lib/kodi_client/global_types/profiles_types.rb
58
- - lib/kodi_client/global_types/pvr_type.rb
59
- - lib/kodi_client/global_types/system_types.rb
60
- - lib/kodi_client/global_types/video_types.rb
61
46
  - lib/kodi_client/kodi_module.rb
62
47
  - lib/kodi_client/method/addons.rb
63
48
  - lib/kodi_client/method/application.rb
49
+ - lib/kodi_client/method/audio_library.rb
64
50
  - lib/kodi_client/method/favourites.rb
51
+ - lib/kodi_client/method/files.rb
65
52
  - lib/kodi_client/method/gui.rb
66
53
  - lib/kodi_client/method/input.rb
67
54
  - lib/kodi_client/method/player.rb
68
55
  - lib/kodi_client/method/profiles.rb
69
56
  - lib/kodi_client/method/system.rb
70
57
  - lib/kodi_client/options.rb
58
+ - lib/kodi_client/types/addon_types.rb
59
+ - lib/kodi_client/types/application_types.rb
60
+ - lib/kodi_client/types/audio_types.rb
61
+ - lib/kodi_client/types/favourites_types.rb
62
+ - lib/kodi_client/types/files_types.rb
63
+ - lib/kodi_client/types/global_types.rb
64
+ - lib/kodi_client/types/gui_types.rb
65
+ - lib/kodi_client/types/input_types.rb
66
+ - lib/kodi_client/types/item_types.rb
67
+ - lib/kodi_client/types/list_types.rb
68
+ - lib/kodi_client/types/media_types.rb
69
+ - lib/kodi_client/types/player_type.rb
70
+ - lib/kodi_client/types/profiles_types.rb
71
+ - lib/kodi_client/types/pvr_type.rb
72
+ - lib/kodi_client/types/system_types.rb
73
+ - lib/kodi_client/types/video_types.rb
71
74
  - lib/kodi_client/util/comparable.rb
72
75
  - lib/kodi_client/util/creatable.rb
73
76
  - lib/kodi_client/util/iterable.rb
@@ -1,88 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'kodi_client/global_types/media_types'
4
- require 'kodi_client/util/comparable'
5
- require 'kodi_client/util/iterable'
6
- require 'kodi_client/util/creatable'
7
-
8
- module KodiClient
9
- module Types
10
- module Audio
11
-
12
- # Audio.Contributor https://kodi.wiki/view/JSON-RPC_API/v12#Audio.Contributors
13
- class AudioContributor
14
- include Comparable
15
- extend Creatable
16
-
17
- attr_reader :artist_id, :name, :role, :role_id
18
-
19
- def initialize(artist_id, name, role, role_id)
20
- @artist_id = artist_id
21
- @name = name
22
- @role = role
23
- @role_id = role_id
24
- end
25
- end
26
-
27
- # Audio.Album.ReleaseType https://kodi.wiki/view/JSON-RPC_API/v12#Audio.Album.ReleaseType
28
- module AudioAlbumReleaseType
29
- extend Iterable
30
-
31
- ALBUM = 'album'
32
- SINGLE = 'single'
33
- end
34
-
35
- # Audio.Details.Base https://kodi.wiki/view/JSON-RPC_API/v12#Audio.Details.Base
36
- module AudioDetailsBase
37
- include Media::MediaDetailsBase
38
-
39
- attr_reader :art, :date_added, :genre
40
-
41
- def audio_details_base_by_hash(hash)
42
- audio_details_base(Types::Media::MediaArtwork.create(hash['art']), hash['date_added'], hash['genre'],
43
- *Creatable.hash_to_arr(hash, %w[fan_art thumbnail label]))
44
- end
45
-
46
- def audio_details_base(art, date_added, genre, fan_art, thumbnail, label)
47
- @art = art
48
- @date_added = date_added
49
- @genre = genre
50
- media_details_base(fan_art, thumbnail, label)
51
- end
52
- end
53
-
54
- # Audio.Details.Media https://kodi.wiki/view/JSON-RPC_API/v12#Audio.Details.Media
55
- module AudioDetailsMedia
56
- include AudioDetailsBase
57
-
58
- attr_reader :artist, :artist_id, :display_artist, :musicbrainz_album_artist_id, :original_date, :rating,
59
- :release_date, :sort_artist, :title, :user_rating, :votes, :year
60
-
61
- def audio_details_media_by_hash(hash)
62
- audio_details_media(hash['artist'], hash['artistid'], hash['displayartist'], hash['musicbrainzalbumartistid'],
63
- hash['originaldate'], hash['rating'], hash['releasedate'], hash['sortartist'],
64
- hash['title'], hash['userrating'], hash['votes'], hash['year'],
65
- *Creatable.hash_to_arr(hash, %w[art date_added genre fan_art thumbnail label]))
66
- end
67
-
68
- def audio_details_media(artist, artist_id, display_artist, musicbrainz_album_artist_id, original_date,
69
- rating, release_date, sort_artist, title, user_rating, votes, year,
70
- art, date_added, genre, fan_art, thumbnail, label)
71
- @artist = artist
72
- @artist_id = artist_id
73
- @display_artist = display_artist
74
- @musicbrainz_album_artist_id = musicbrainz_album_artist_id
75
- @original_date = original_date
76
- @rating = rating
77
- @release_date = release_date
78
- @sort_artist = sort_artist
79
- @title = title
80
- @user_rating = user_rating
81
- @votes = votes
82
- @year = year
83
- audio_details_base(art, date_added, genre, fan_art, thumbnail, label)
84
- end
85
- end
86
- end
87
- end
88
- end