kodi_client 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kodi_client/global_types/gui_types'
4
+ require 'kodi_client/kodi_module'
5
+
6
+ module KodiClient
7
+ module Modules
8
+ # contains all Kodi GUI methods
9
+ class GUI < KodiModule
10
+
11
+ ACTIVATE_WINDOW = 'GUI.ActivateWindow'
12
+ GET_PROPERTIES = 'GUI.GetProperties'
13
+ GET_STEREOSCOPIC_MODES = 'GUI.GetStereoscopicModes'
14
+ SET_STEREOSCOPIC_MODES = 'GUI.SetStereoscopicMode'
15
+ SET_FULLSCREEN = 'GUI.SetFullscreen'
16
+ SHOW_NOTIFICATION = 'GUI.ShowNotification'
17
+
18
+ def activate_window(window = Types::GUI::GUIWindow::HOME, parameters = [], kodi_id = 1)
19
+ request = KodiRequest.new(kodi_id, ACTIVATE_WINDOW, { 'window' => window, 'parameters' => parameters })
20
+ json = invoke_api(request)
21
+ KodiResponse.new(json)
22
+ end
23
+
24
+ def get_properties(properties = Types::GUI::PropertyName.all_properties, kodi_id = 1)
25
+ request = KodiRequest.new(kodi_id, GET_PROPERTIES, { 'properties' => properties })
26
+ json = invoke_api(request)
27
+ result = json['result'].nil? ? nil : KodiClient::Types::GUI::PropertyValue.new(json['result'])
28
+ json['result'] = result
29
+ KodiResponse.new(json)
30
+ end
31
+
32
+ def get_stereoscopic_modes(kodi_id = 1)
33
+ request = KodiRequest.new(kodi_id, GET_STEREOSCOPIC_MODES, {})
34
+ json = invoke_api(request)
35
+ result = json['result'].nil? ? nil : json['result']['stereoscopicmodes'].map { |it| Types::GUI::StereoscopyMode.new(it) }
36
+ json['result'] = result
37
+ KodiResponse.new(json)
38
+ end
39
+
40
+ def set_fullscreen(fullscreen = Types::Global::Toggle, kodi_id = 1)
41
+ request = KodiRequest.new(kodi_id, SET_FULLSCREEN, { 'fullscreen' => fullscreen })
42
+ json = invoke_api(request)
43
+ KodiResponse.new(json)
44
+ end
45
+
46
+ def set_stereoscopic_mode(mode = Types::GUI::StereoscopyMode::OFF, kodi_id = 1)
47
+ request = KodiRequest.new(kodi_id, SET_STEREOSCOPIC_MODES, { 'mode' => mode })
48
+ json = invoke_api(request)
49
+ KodiResponse.new(json)
50
+ end
51
+
52
+ def show_notification(title, message, image = '', display_time_in_ms = 5000, kodi_id = 1)
53
+ request = KodiRequest.new(kodi_id, SHOW_NOTIFICATION, { 'title' => title,
54
+ 'message' => message,
55
+ 'image' => image,
56
+ 'displaytime' => display_time_in_ms })
57
+ json = invoke_api(request)
58
+ KodiResponse.new(json)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,220 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kodi_client/kodi_module'
4
+ require 'kodi_client/global_types/addon_types'
5
+ require 'kodi_client/global_types/list_types'
6
+ require 'kodi_client/global_types/player_type'
7
+
8
+ module KodiClient
9
+ module Modules
10
+ # contains all Kodi Application methods
11
+ class Player < KodiModule
12
+
13
+ ADD_SUBTITLE = 'Player.AddSubtitle'
14
+ OPEN = 'Player.Open'
15
+ GET_ACTIVE_PLAYER = 'Player.GetActivePlayers'
16
+ GET_ITEM = 'Player.GetItem'
17
+ GET_PLAYERS = 'Player.GetPlayers'
18
+ GET_PROPERTIES = 'Player.GetProperties'
19
+ GET_VIEW_MODE = 'Player.GetViewMode'
20
+ GO_TO = 'Player.GoTo'
21
+ MOVE = 'Player.Move'
22
+ ROTATE = 'Player.Rotate'
23
+ PLAY_PAUSE = 'Player.PlayPause'
24
+ SEEK = 'Player.Seek'
25
+ SET_AUDIO_STREAM = 'Player.SetAudioStream'
26
+ SET_PARTY_MODE = 'Player.SetPartymode'
27
+ SET_REPEAT = 'Player.SetRepeat'
28
+ SET_SPEED = 'Player.SetSpeed'
29
+ SET_SUBTITLE = 'Player.SetSubtitle'
30
+ SET_VIDEO_STREAM = 'Player.SetVideoStream'
31
+ SET_VIEW_MODE = 'Player.SetViewMode'
32
+ STOP = 'Player.Stop'
33
+ ZOOM = 'Player.Zoom'
34
+
35
+ def add_subtitle(player_id, subtitle, kodi_id = 1)
36
+ request = KodiRequest.new(kodi_id, ADD_SUBTITLE, { 'playerid' => player_id, 'subtitle' => subtitle })
37
+ json = invoke_api(request)
38
+ KodiResponse.new(json)
39
+ end
40
+
41
+ def get_active_players(kodi_id = 1)
42
+ request = KodiRequest.new(kodi_id, GET_ACTIVE_PLAYER, {})
43
+ json = invoke_api(request)
44
+ result = json['result'].nil? ? nil : json['result'].map { |it| Types::Player::Player.new(it) }
45
+ json['result'] = result
46
+ KodiResponse.new(json)
47
+ end
48
+
49
+ # local file or stream url
50
+ def player_open(file, options = {}, kodi_id = 1)
51
+ request = KodiRequest.new(kodi_id, OPEN, { 'item' => { 'file' => file }, 'options' => options })
52
+ json = invoke_api(request)
53
+ KodiResponse.new(json)
54
+ end
55
+
56
+ def get_item(player_id, properties = Types::List::ListFieldsAll.all_properties, kodi_id = 1)
57
+ request = KodiRequest.new(kodi_id, GET_ITEM, { 'playerid' => player_id,
58
+ 'properties' => properties })
59
+ json = invoke_api(request)
60
+ result = Types::List::ListItemAll.new(json['result']['item'])
61
+ json['result'] = result
62
+ KodiResponse.new(json)
63
+ end
64
+
65
+ def get_players(media = Types::Media::MediaType::ALL, kodi_id = 1)
66
+ request = KodiRequest.new(kodi_id, GET_PLAYERS, { 'media' => media })
67
+ json = invoke_api(request)
68
+ result = json['result'].map { |it| Types::Player::Player.new(it) }
69
+ json['result'] = result
70
+ KodiResponse.new(json)
71
+ end
72
+
73
+ def get_properties(player_id, properties = Types::Player::PropertyName.all_properties, kodi_id = 1)
74
+ request = KodiRequest.new(kodi_id, GET_PROPERTIES, { 'playerid' => player_id,
75
+ 'properties' => properties })
76
+ json = invoke_api(request)
77
+ result = Types::Player::PropertyValue.new(json['result'])
78
+ json['result'] = result
79
+ KodiResponse.new(json)
80
+ end
81
+
82
+ def get_view_mode(kodi_id = 1)
83
+ request = KodiRequest.new(kodi_id, GET_VIEW_MODE, {})
84
+ json = invoke_api(request)
85
+ result = Types::Player::PlayerViewMode.new(json['result'])
86
+ json['result'] = result
87
+ KodiResponse.new(json)
88
+ end
89
+
90
+ # goes to the next/prev item or to a specific item in the playlist
91
+ #
92
+ # @param [String] player_id - the player id
93
+ # @param [Integer/Types::Global::NextPrev] to - playlist position, or prev/next
94
+ # @param [Integer] kodi_id - the kodi id
95
+ #
96
+ # @return [KodiResponse] - OK or Error
97
+ def go_to(player_id, to = Types::Global::NextPrev::NEXT, kodi_id = 1)
98
+ request = KodiRequest.new(kodi_id, GO_TO, { 'playerid' => player_id, 'to' => to })
99
+ json = invoke_api(request)
100
+ KodiResponse.new(json)
101
+ end
102
+
103
+ def move(player_id, direction = Types::Global::Direction::UP, kodi_id = 1)
104
+ request = KodiRequest.new(kodi_id, MOVE, { 'playerid' => player_id, 'direction' => direction })
105
+ json = invoke_api(request)
106
+ KodiResponse.new(json)
107
+ end
108
+
109
+ def rotate(player_id, rotate = Types::Global::Rotate::CLOCKWISE, kodi_id = 1)
110
+ request = KodiRequest.new(kodi_id, ROTATE, { 'playerid' => player_id, 'value' => rotate })
111
+ json = invoke_api(request)
112
+ KodiResponse.new(json)
113
+ end
114
+
115
+ def play_pause(player_id, play = Types::Global::Toggle::TOGGLE, kodi_id = 1)
116
+ request = KodiRequest.new(kodi_id, PLAY_PAUSE, { 'playerid' => player_id, 'play' => play })
117
+ json = invoke_api(request)
118
+ result = json['result']['speed']
119
+ json['result'] = result
120
+ KodiResponse.new(json)
121
+ end
122
+
123
+ # seeks to the given position
124
+ #
125
+ # @param [Integer] player_id - the player id
126
+ # @param [Float/PlayerPositionTime/PlayerSeekJump/Integer] value - the seek value in either Percentage,
127
+ # PositionTime, Jump or seek by seconds
128
+ #
129
+ # return [KodiResponse] - return percentage, time and total time
130
+ def seek(player_id, value, kodi_id = 1)
131
+ request = KodiRequest.new(kodi_id, SEEK, { 'playerid' => player_id, 'value' => value })
132
+ json = invoke_api(request)
133
+ result = Types::Player::SeekReturnValue.new(json['result'])
134
+ json['result'] = result
135
+ KodiResponse.new(json)
136
+ end
137
+
138
+ # sets the given audio stream
139
+ #
140
+ # @param [Integer, Next/Prev] stream - the stream to set, can either be the index or next/prev
141
+ #
142
+ # return [KodiResponse] 'OK' or error
143
+ def set_audio_stream(player_id, stream, kodi_id = 1)
144
+ request = KodiRequest.new(kodi_id, SET_AUDIO_STREAM, { 'playerid' => player_id, 'stream' => stream })
145
+ json = invoke_api(request)
146
+ KodiResponse.new(json)
147
+ end
148
+
149
+ def set_party_mode(player_id, mode = Types::Global::Toggle::TOGGLE, kodi_id = 1)
150
+ request = KodiRequest.new(kodi_id, SET_PARTY_MODE, { 'playerid' => player_id, 'partymode' => mode })
151
+ json = invoke_api(request)
152
+ KodiResponse.new(json)
153
+ end
154
+
155
+ def set_repeat(player_id, repeat = Types::Player::PlayerRepeat::ALL, kodi_id = 1)
156
+ request = KodiRequest.new(kodi_id, SET_REPEAT, { 'playerid' => player_id, 'repeat' => repeat })
157
+ json = invoke_api(request)
158
+ KodiResponse.new(json)
159
+ end
160
+
161
+ def set_speed(player_id, speed = Types::Global::IncrementDecrement::INCREMENT, kodi_id = 1)
162
+ request = KodiRequest.new(kodi_id, SET_SPEED, { 'playerid' => player_id, 'speed' => speed })
163
+ json = invoke_api(request)
164
+ result = json['result']['speed']
165
+ json['result'] = result
166
+ KodiResponse.new(json)
167
+ end
168
+
169
+ # sets the subtitle
170
+ #
171
+ # @param [Integer] player_id - the player id
172
+ # @param [Next|Prev/Integer] subtitle - the subtitle to set. Can either be an index or next/prev
173
+ # @param [Boolean] enabled - true if the set subtitle should be enabled, else false
174
+ #
175
+ # @return [KodiResponse] - 'OK' else error
176
+ def set_subtitle(player_id, subtitle = Types::Global::NextPrev::NEXT, enabled = false, kodi_id = 1)
177
+ request = KodiRequest.new(kodi_id, SET_SUBTITLE, { 'playerid' => player_id, 'subtitle' => subtitle,
178
+ 'enabled' => enabled })
179
+ json = invoke_api(request)
180
+ KodiResponse.new(json)
181
+ end
182
+
183
+ # Sets the video stream
184
+ #
185
+ # @param [Integer] player_id - the player id
186
+ # @param [Next|Prev/Integer] stream - the stream to set. Can either be an index or next/prev
187
+ #
188
+ # @return [KodiResponse] - 'OK' else error
189
+ def set_video_stream(player_id, stream = Types::Global::NextPrev::NEXT, kodi_id = 1)
190
+ request = KodiRequest.new(kodi_id, SET_VIDEO_STREAM, { 'playerid' => player_id, 'stream' => stream })
191
+ json = invoke_api(request)
192
+ KodiResponse.new(json)
193
+ end
194
+
195
+ def set_view_mode(player_id, mode = Types::Player::ViewMode::NORMAL, kodi_id = 1)
196
+ request = KodiRequest.new(kodi_id, SET_VIEW_MODE, { 'playerid' => player_id, 'viewmode' => mode })
197
+ json = invoke_api(request)
198
+ KodiResponse.new(json)
199
+ end
200
+
201
+ def stop(player_id, kodi_id = 1)
202
+ request = KodiRequest.new(kodi_id, STOP, { 'playerid' => player_id })
203
+ json = invoke_api(request)
204
+ KodiResponse.new(json)
205
+ end
206
+
207
+ # Sets the zoom
208
+ #
209
+ # @param [Integer] player_id - the player id
210
+ # @param [Zoom/Integer] zoom - Can either be 1-10 or step In/Out
211
+ #
212
+ # @return [KodiResponse] - 'OK' else error
213
+ def zoom(player_id, zoom, kodi_id = 1)
214
+ request = KodiRequest.new(kodi_id, ZOOM, { 'playerid' => player_id, 'zoom' => zoom })
215
+ json = invoke_api(request)
216
+ KodiResponse.new(json)
217
+ end
218
+ end
219
+ end
220
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+ # holds all options like ip, port, credentials
5
+ class Options
6
+
7
+ attr_accessor :ip, :port, :username, :password, :tls
8
+
9
+ def initialize
10
+ @tls = false
11
+ end
12
+
13
+ def with_connection(ip, port)
14
+ @ip = ip
15
+ @port = port
16
+ end
17
+
18
+ def with_auth(username, password)
19
+ @username = username
20
+ @password = password
21
+ end
22
+
23
+ def with_tls(enabled: true)
24
+ @tls = enabled
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+
5
+ # offers compare methods
6
+ module Comparable
7
+
8
+ def compare(obj1, obj2)
9
+ is_same = true
10
+ obj1.instance_variables.each do |it|
11
+ is_same = false if obj1.instance_variable_get(it) != obj2.instance_variable_get(it)
12
+ end
13
+
14
+ is_same
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KodiClient
4
+
5
+ # offers iterable methods
6
+ module Iterable
7
+ def all_properties
8
+ constants.map { |it| const_get(it) }.sort!
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'json'
5
+
6
+ require 'kodi_client/Chainable'
7
+ require 'kodi_client/method/addons'
8
+ require 'kodi_client/method/application'
9
+ require 'kodi_client/method/gui'
10
+ require 'kodi_client/method/player'
11
+
12
+
13
+ # client for Kodi rest api https://kodi.wiki/view/JSON-RPC_API/v12
14
+ module KodiClient
15
+ extend Chainable
16
+
17
+ # client that holds all methods such as application, gui etc.
18
+ class Client
19
+ include Chainable
20
+
21
+ attr_reader :addons, :application, :gui, :player
22
+
23
+ def initialize
24
+ @addons = KodiClient::Modules::Addons.new
25
+ @application = KodiClient::Modules::Application.new
26
+ @gui = KodiClient::Modules::GUI.new
27
+ @player = KodiClient::Modules::Player.new
28
+ end
29
+
30
+ def apply_options(options)
31
+ @addons.apply_options(options)
32
+ @application.apply_options(options)
33
+ @gui.apply_options(options)
34
+ @player.apply_options(options)
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kodi_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Feier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A client for the Kodi JSON API v12, currently implemented methods are
14
+ addons, application, gui and player (more will be added with the time). For more
15
+ information how to use it and how to activate Remote Control in Kodi, please check
16
+ the github page https://github.com/cfe86/RubyKodiClient
17
+ email:
18
+ - christian.feier@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ".gitignore"
24
+ - ".rubocop.yml"
25
+ - Gemfile
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - kodi_client.gemspec
30
+ - lib/kodi_client.rb
31
+ - lib/kodi_client/Chainable.rb
32
+ - lib/kodi_client/global_types/addon_types.rb
33
+ - lib/kodi_client/global_types/application_types.rb
34
+ - lib/kodi_client/global_types/audio_types.rb
35
+ - lib/kodi_client/global_types/global_types.rb
36
+ - lib/kodi_client/global_types/gui_types.rb
37
+ - lib/kodi_client/global_types/item_types.rb
38
+ - lib/kodi_client/global_types/list_types.rb
39
+ - lib/kodi_client/global_types/media_types.rb
40
+ - lib/kodi_client/global_types/player_type.rb
41
+ - lib/kodi_client/global_types/pvr_type.rb
42
+ - lib/kodi_client/global_types/video_types.rb
43
+ - lib/kodi_client/kodi_module.rb
44
+ - lib/kodi_client/method/addons.rb
45
+ - lib/kodi_client/method/application.rb
46
+ - lib/kodi_client/method/gui.rb
47
+ - lib/kodi_client/method/player.rb
48
+ - lib/kodi_client/options.rb
49
+ - lib/kodi_client/util/comparable.rb
50
+ - lib/kodi_client/util/iterable.rb
51
+ homepage: https://github.com/cfe86/RubyKodiClient
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/cfe86/RubyKodiClient
56
+ source_code_uri: https://github.com/cfe86/RubyKodiClient
57
+ changelog_uri: https://github.com/cfe86/RubyKodiClient
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 2.5.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.2.22
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: A work-in-progress client for Kodi JSON API v2.
77
+ test_files: []