plex-ruby 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +3 -0
- data/README.md +11 -0
- data/lib/plex-ruby.rb +25 -0
- data/lib/plex-ruby/client.rb +5 -5
- data/lib/plex-ruby/config.rb +9 -0
- data/lib/plex-ruby/episode.rb +2 -2
- data/lib/plex-ruby/library.rb +1 -1
- data/lib/plex-ruby/movie.rb +1 -1
- data/lib/plex-ruby/season.rb +5 -5
- data/lib/plex-ruby/section.rb +6 -6
- data/lib/plex-ruby/server.rb +2 -2
- data/lib/plex-ruby/show.rb +6 -6
- data/lib/plex-ruby/version.rb +1 -1
- data/test/test_config.rb +14 -0
- data/test/test_plex.rb +15 -0
- metadata +20 -33
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8866a7fbb96ee008c3f07d3f7fd350a03598eebd
|
4
|
+
data.tar.gz: 31c390b83a84299d6ddb8276e63bab13dae3726c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e1bf2dbca860b21b65fed8f45c8900ee8473fcc9afbeb2f67ea9c63c3516c72c97c83b78a30e35257596b4c8c796d7b3f345aeb0acdf91bf71f08733a5f7b9b
|
7
|
+
data.tar.gz: 192b84c99c0c7a8fcde09ef4322fb1fbd5a8635bc3612a1581c7147eb740502a2f9b54a0a5ca5679d019eff3eaa715a6be0622f2dcdfb028309ea4d51962462d
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -24,6 +24,17 @@ require 'plex-ruby'
|
|
24
24
|
I developed this using Ruby 1.9.2 so no guaranties that it will work with
|
25
25
|
lesser versions of Ruby.
|
26
26
|
|
27
|
+
## Configuration
|
28
|
+
|
29
|
+
For external access to your Plex Media Server an auth token is required. You
|
30
|
+
can configure it with the following snippet.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
Plex.configure do |config|
|
34
|
+
config.auth_token = "ABCDEFGH"
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
27
38
|
## Usage
|
28
39
|
|
29
40
|
Everything Stems from the Plex Media Server. Create a server with the host and
|
data/lib/plex-ruby.rb
CHANGED
@@ -4,6 +4,30 @@ require 'cgi'
|
|
4
4
|
|
5
5
|
module Plex
|
6
6
|
|
7
|
+
# Instantiates a Config instance once and returns it
|
8
|
+
def self.config
|
9
|
+
@config ||= Config.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# Allows the configuration of some Plex-internal settings. It yields a Config
|
13
|
+
# instance so a block can be used:
|
14
|
+
#
|
15
|
+
# Plex.configure do |config|
|
16
|
+
# config.auth_token = "ABCDEF"
|
17
|
+
# end
|
18
|
+
def self.configure
|
19
|
+
yield(config)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Custom open func which adds the required headers configured by
|
23
|
+
# <tt>Plex.configure</tt>
|
24
|
+
def self.open(url)
|
25
|
+
headers = {}
|
26
|
+
headers["X-Plex-Token"] = config.auth_token if config.auth_token
|
27
|
+
|
28
|
+
super(url, headers)
|
29
|
+
end
|
30
|
+
|
7
31
|
# Converts camel case names that are commonly found in the Plex APIs into
|
8
32
|
# ruby friendly names. I.E. <tt>playMedia</tt> -> <tt>play_media</tt>
|
9
33
|
#
|
@@ -29,6 +53,7 @@ module Plex
|
|
29
53
|
|
30
54
|
end
|
31
55
|
|
56
|
+
require 'plex-ruby/config'
|
32
57
|
require 'plex-ruby/parser'
|
33
58
|
require 'plex-ruby/server'
|
34
59
|
require 'plex-ruby/client'
|
data/lib/plex-ruby/client.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Plex
|
2
2
|
class Client
|
3
3
|
|
4
|
-
NAV_METHODS = %w(moveUp moveDown moveLeft moveRight pageUp pageDown nextLetter
|
5
|
-
previousLetter select back contextMenu toggleOSD)
|
4
|
+
NAV_METHODS = %w(moveUp moveDown moveLeft moveRight pageUp pageDown nextLetter
|
5
|
+
previousLetter select back contextMenu toggleOSD)
|
6
6
|
|
7
|
-
PLAYBACK_METHODS = %w(play pause stop rewind fastForward stepForward
|
7
|
+
PLAYBACK_METHODS = %w(play pause stop rewind fastForward stepForward
|
8
8
|
bigStepForward stepBack bigStepBack skipNext skipPrevious)
|
9
9
|
|
10
10
|
ATTRIBUTES = %w(name host address port machineIdentifier version)
|
@@ -64,7 +64,7 @@ module Plex
|
|
64
64
|
def play_media(key, user_agent = nil, http_cookies = nil, view_offset = nil)
|
65
65
|
|
66
66
|
if !key.is_a?(String) && key.respond_to?(:key)
|
67
|
-
key = key.key
|
67
|
+
key = key.key
|
68
68
|
end
|
69
69
|
|
70
70
|
url = player_url+'/application/playMedia?'
|
@@ -137,7 +137,7 @@ module Plex
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def ping(url)
|
140
|
-
!!open(url).read
|
140
|
+
!!Plex.open(url).read
|
141
141
|
rescue => e
|
142
142
|
puts "Error trying to ping #{url} - #{e.message}"
|
143
143
|
end
|
data/lib/plex-ruby/episode.rb
CHANGED
@@ -14,7 +14,7 @@ module Plex
|
|
14
14
|
def attribute_hash
|
15
15
|
video.attribute_hash.merge({'key' => key})
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Delegates all method calls to the video object that represents this
|
19
19
|
# episode, if that video object responds to the method.
|
20
20
|
def method_missing(method, *args, &block)
|
@@ -55,7 +55,7 @@ module Plex
|
|
55
55
|
private
|
56
56
|
|
57
57
|
def xml_doc
|
58
|
-
@xml_doc ||= Nokogiri::XML( open(url+key) )
|
58
|
+
@xml_doc ||= Nokogiri::XML( Plex.open(url+key) )
|
59
59
|
end
|
60
60
|
|
61
61
|
def video
|
data/lib/plex-ruby/library.rb
CHANGED
data/lib/plex-ruby/movie.rb
CHANGED
data/lib/plex-ruby/season.rb
CHANGED
@@ -2,8 +2,8 @@ module Plex
|
|
2
2
|
# Found at /library/metadata/:key
|
3
3
|
class Season
|
4
4
|
|
5
|
-
ATTRIBUTES = %w(ratingKey guid type title summary index thumb leafCount
|
6
|
-
viewedLeafCount addedAt updatedAt)
|
5
|
+
ATTRIBUTES = %w(ratingKey guid type title summary index thumb leafCount
|
6
|
+
viewedLeafCount addedAt updatedAt)
|
7
7
|
|
8
8
|
attr_reader :show, :key, :attribute_hash
|
9
9
|
|
@@ -79,18 +79,18 @@ module Plex
|
|
79
79
|
private
|
80
80
|
|
81
81
|
def base_doc
|
82
|
-
Nokogiri::XML( open(url+key) )
|
82
|
+
Nokogiri::XML( Plex.open(url+key) )
|
83
83
|
end
|
84
84
|
|
85
85
|
def base_children_doc
|
86
|
-
Nokogiri::XML( open(url+key+'/children') )
|
86
|
+
Nokogiri::XML( Plex.open(url+key+'/children') )
|
87
87
|
end
|
88
88
|
|
89
89
|
def xml_doc
|
90
90
|
@xml_doc ||= base_doc
|
91
91
|
end
|
92
92
|
|
93
|
-
def children
|
93
|
+
def children
|
94
94
|
@children ||= base_children_doc
|
95
95
|
end
|
96
96
|
|
data/lib/plex-ruby/section.rb
CHANGED
@@ -25,7 +25,7 @@ module Plex
|
|
25
25
|
end
|
26
26
|
|
27
27
|
|
28
|
-
# Returns a list of shows or movies that are in this Section.
|
28
|
+
# Returns a list of shows or movies that are in this Section.
|
29
29
|
#
|
30
30
|
# all - all videos in this Section
|
31
31
|
# unwatched - videos unwatched in this Section
|
@@ -38,7 +38,7 @@ module Plex
|
|
38
38
|
GROUPS.each { |method|
|
39
39
|
class_eval %(
|
40
40
|
def #{Plex.underscore(method)}
|
41
|
-
Plex::Parser.new( self, Nokogiri::XML(open(url+key+'/#{method}')) ).parse
|
41
|
+
Plex::Parser.new( self, Nokogiri::XML(Plex.open(url+key+'/#{method}')) ).parse
|
42
42
|
end
|
43
43
|
)
|
44
44
|
}
|
@@ -51,7 +51,7 @@ module Plex
|
|
51
51
|
# by_#{category}(key) - all shows / movies by that key
|
52
52
|
#
|
53
53
|
# Example:
|
54
|
-
#
|
54
|
+
#
|
55
55
|
# library.section(2).by_year(2008) # List of TV Shows from 2008
|
56
56
|
# library.section(1).by_first_character("H") # movies starting with 'H'
|
57
57
|
# library.section(2).genres # Array of Hashes explaining all of the genres
|
@@ -71,7 +71,7 @@ module Plex
|
|
71
71
|
@#{Plex.underscore(method)}s = grab_keys('#{method}')
|
72
72
|
end
|
73
73
|
def by_#{Plex.underscore(method)}(val)
|
74
|
-
Plex::Parser.new( self, Nokogiri::XML(open(url+key+"/#{method}/\#{val}")) ).parse
|
74
|
+
Plex::Parser.new( self, Nokogiri::XML(Plex.open(url+key+"/#{method}/\#{val}")) ).parse
|
75
75
|
end
|
76
76
|
)
|
77
77
|
}
|
@@ -80,7 +80,7 @@ module Plex
|
|
80
80
|
def key #:nodoc:
|
81
81
|
"/library/sections/#{@key}"
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
# @private
|
85
85
|
def url #:nodoc:
|
86
86
|
library.url
|
@@ -103,7 +103,7 @@ module Plex
|
|
103
103
|
private
|
104
104
|
|
105
105
|
def grab_keys(action)
|
106
|
-
Nokogiri::XML(open(url+key+"/#{action}")).search('Directory').map do |node|
|
106
|
+
Nokogiri::XML(Plex.open(url+key+"/#{action}")).search('Directory').map do |node|
|
107
107
|
{
|
108
108
|
key: node.attr('key'),
|
109
109
|
title: node.attr('title')
|
data/lib/plex-ruby/server.rb
CHANGED
@@ -16,7 +16,7 @@ module Plex
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# The Plex clients that are connected to this Server
|
19
|
-
#
|
19
|
+
#
|
20
20
|
# @return [Array] list of Clients connected to this server
|
21
21
|
def clients
|
22
22
|
@clients ||= search_clients clients_doc
|
@@ -40,7 +40,7 @@ module Plex
|
|
40
40
|
private
|
41
41
|
|
42
42
|
def clients_base
|
43
|
-
Nokogiri::XML( open(url+'/clients') )
|
43
|
+
Nokogiri::XML( Plex.open(url+'/clients') )
|
44
44
|
end
|
45
45
|
|
46
46
|
def clients_doc
|
data/lib/plex-ruby/show.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Plex
|
2
2
|
class Show
|
3
3
|
|
4
|
-
ATTRIBUTES = %w(ratingKey guid studio type title contentRating summary index
|
5
|
-
rating year thumb art leafCount viewedLeafCount addedAt
|
4
|
+
ATTRIBUTES = %w(ratingKey guid studio type title contentRating summary index
|
5
|
+
rating year thumb art leafCount viewedLeafCount addedAt
|
6
6
|
updatedAt)
|
7
7
|
|
8
8
|
attr_reader :section, :key, :attribute_hash
|
@@ -44,7 +44,7 @@ module Plex
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# Helper method for selecting the special Season of this show
|
47
|
-
# Season 0 is where Plex stores episodes that are not part of a
|
47
|
+
# Season 0 is where Plex stores episodes that are not part of a
|
48
48
|
# regular season. i.e. Christmas Specials
|
49
49
|
#
|
50
50
|
# @return [Season] season with index of 0
|
@@ -105,17 +105,17 @@ module Plex
|
|
105
105
|
private
|
106
106
|
|
107
107
|
def base_doc
|
108
|
-
Nokogiri::XML( open(url+key) )
|
108
|
+
Nokogiri::XML( Plex.open(url+key) )
|
109
109
|
end
|
110
110
|
|
111
111
|
def children_base
|
112
|
-
Nokogiri::XML( open(url+key+'/children') )
|
112
|
+
Nokogiri::XML( Plex.open(url+key+'/children') )
|
113
113
|
end
|
114
114
|
|
115
115
|
def xml_doc
|
116
116
|
@xml_doc ||= base_doc
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
def children
|
120
120
|
@children ||= children_base
|
121
121
|
end
|
data/lib/plex-ruby/version.rb
CHANGED
data/test/test_config.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Plex::Config do
|
4
|
+
|
5
|
+
it "should be configurable" do
|
6
|
+
Plex.config.auth_token.must_equal nil
|
7
|
+
|
8
|
+
Plex.configure do |config|
|
9
|
+
config.auth_token = "ABCD"
|
10
|
+
end
|
11
|
+
|
12
|
+
Plex.config.auth_token.must_equal "ABCD"
|
13
|
+
end
|
14
|
+
end
|
data/test/test_plex.rb
CHANGED
@@ -8,4 +8,19 @@ describe Plex do
|
|
8
8
|
Plex.underscore("normal").must_equal "normal"
|
9
9
|
end
|
10
10
|
|
11
|
+
before do
|
12
|
+
FakeWeb.register_uri(:get, "http://localhost:32400", :body => "")
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
FakeWeb.clean_registry
|
17
|
+
Plex.config.auth_token = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "has an open function which respects the configuration" do
|
21
|
+
Plex.configure {|config| config.auth_token = "ABCD" }
|
22
|
+
|
23
|
+
Plex.open("http://localhost:32400").read
|
24
|
+
FakeWeb.last_request["X-Plex-Token"].must_equal "ABCD"
|
25
|
+
end
|
11
26
|
end
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plex-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
5
|
-
prerelease:
|
4
|
+
version: 1.5.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Eric Koslow
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: minitest
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: fakeweb
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: nokogiri
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: Extracts the Plex Media Server API into easy to write ruby code
|
@@ -82,8 +73,8 @@ executables: []
|
|
82
73
|
extensions: []
|
83
74
|
extra_rdoc_files: []
|
84
75
|
files:
|
85
|
-
- .gitignore
|
86
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
87
78
|
- CHANGELOG.md
|
88
79
|
- Gemfile
|
89
80
|
- LICENSE
|
@@ -91,6 +82,7 @@ files:
|
|
91
82
|
- Rakefile
|
92
83
|
- lib/plex-ruby.rb
|
93
84
|
- lib/plex-ruby/client.rb
|
85
|
+
- lib/plex-ruby/config.rb
|
94
86
|
- lib/plex-ruby/episode.rb
|
95
87
|
- lib/plex-ruby/library.rb
|
96
88
|
- lib/plex-ruby/media.rb
|
@@ -107,6 +99,7 @@ files:
|
|
107
99
|
- lib/plex-ruby/video.rb
|
108
100
|
- plex-ruby.gemspec
|
109
101
|
- test/test_client.rb
|
102
|
+
- test/test_config.rb
|
110
103
|
- test/test_episode.rb
|
111
104
|
- test/test_helper.rb
|
112
105
|
- test/test_library.rb
|
@@ -122,36 +115,30 @@ files:
|
|
122
115
|
- test/test_video.rb
|
123
116
|
homepage: https://github.com/ekosz/Plex-Ruby
|
124
117
|
licenses: []
|
118
|
+
metadata: {}
|
125
119
|
post_install_message:
|
126
120
|
rdoc_options: []
|
127
121
|
require_paths:
|
128
122
|
- lib
|
129
123
|
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
124
|
requirements:
|
132
|
-
- -
|
125
|
+
- - ">="
|
133
126
|
- !ruby/object:Gem::Version
|
134
127
|
version: '0'
|
135
|
-
segments:
|
136
|
-
- 0
|
137
|
-
hash: 1533681294103733520
|
138
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
-
none: false
|
140
129
|
requirements:
|
141
|
-
- -
|
130
|
+
- - ">="
|
142
131
|
- !ruby/object:Gem::Version
|
143
132
|
version: '0'
|
144
|
-
segments:
|
145
|
-
- 0
|
146
|
-
hash: 1533681294103733520
|
147
133
|
requirements: []
|
148
134
|
rubyforge_project: plex-ruby
|
149
|
-
rubygems_version:
|
135
|
+
rubygems_version: 2.2.0
|
150
136
|
signing_key:
|
151
|
-
specification_version:
|
137
|
+
specification_version: 4
|
152
138
|
summary: Plex Media Server APIs in easy ruby code
|
153
139
|
test_files:
|
154
140
|
- test/test_client.rb
|
141
|
+
- test/test_config.rb
|
155
142
|
- test/test_episode.rb
|
156
143
|
- test/test_helper.rb
|
157
144
|
- test/test_library.rb
|