Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alexwk/add collections tag #26

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ Rake::TestTask.new do |i|
end

task default: :test

54 changes: 24 additions & 30 deletions lib/plex-ruby/client.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,53 @@
module Plex
class Client

NAV_METHODS = %w(moveUp moveDown moveLeft moveRight pageUp pageDown nextLetter
previousLetter select back contextMenu toggleOSD)
previousLetter select back contextMenu toggleOSD).freeze

PLAYBACK_METHODS = %w(play pause stop rewind fastForward stepForward
bigStepForward stepBack bigStepBack skipNext skipPrevious)
bigStepForward stepBack bigStepBack skipNext skipPrevious).freeze

ATTRIBUTES = %w(name host address port machineIdentifier version)
ATTRIBUTES = %w(name host address port machineIdentifier version).freeze

attr_reader *ATTRIBUTES.map {|m| Plex.underscore(m) }
attr_reader(*ATTRIBUTES.map { |m| Plex.underscore(m) })
attr_reader :server


# @param [Server] server this client belongs to
# @param [Nokogiri::XML::Element] nokogiri element to build from
def initialize(server, node)
@server = server
ATTRIBUTES.each { |e|
instance_variable_set("@#{Plex.underscore(e)}", node.attr(e))
}
ATTRIBUTES.each do |attribute|
instance_variable_set("@#{Plex.underscore(attribute)}", node.attr(attribute))
end
end

# Navigation methods
# Sends a movement command to the client to move around menus and such
#
# @return [True, nil] true if it worked, nil if something went wrong check
# the console for the error message
NAV_METHODS.each { |nav|
NAV_METHODS.each do |nav|
class_eval %(
def #{Plex.underscore(nav)}
ping player_url+'/navigation/#{nav}'
end
)
}
end

# Playback methods
# Sends a playback command to the client to play / pause videos and such
#
# @return [True, nil] true if it worked, nil if something went wrong check
# the console for the error message
PLAYBACK_METHODS.each { |playback|
PLAYBACK_METHODS.each do |playback|
class_eval %(
def #{Plex.underscore(playback)}
ping player_url+'/playback/#{playback}'
end
)
}
end

def play_file
ping player_url+"/application/playFile"
ping player_url + '/application/playFile'
end

# Plays a video that is in the library
Expand All @@ -62,14 +60,11 @@ def play_file
# @return [True, nil] true if it worked, nil if something went wrong check
# the console for the error message
def play_media(key, user_agent = nil, http_cookies = nil, view_offset = nil)
key = key.key if !key.is_a?(String) && key.respond_to?(:key)

if !key.is_a?(String) && key.respond_to?(:key)
key = key.key
end

url = player_url+'/application/playMedia?'
url += "path=#{CGI::escape(server.url+key)}"
url += "&key=#{CGI::escape(key)}"
url = player_url + '/application/playMedia?'
url += "path=#{CGI.escape(server.url + key)}"
url += "&key=#{CGI.escape(key)}"
url += "&userAgent=#{user_agent}" if user_agent
url += "&httpCookies=#{http_cookies}" if http_cookies
url += "&viewOffset=#{view_offset}" if view_offset
Expand All @@ -85,10 +80,10 @@ def play_media(key, user_agent = nil, http_cookies = nil, view_offset = nil)
# @return [True, nil] true if it worked, nil if something went wrong check
# the console for the error message
def screenshot(width, height, quality)
url = player_url+'/application/screenshot?'
url += "width=#{width}"
url += "&height=#{height}"
url += "&quality=#{quality}"
url = player_url + '/application/screenshot?'
url += "width=#{width}"
url += "&height=#{height}"
url += "&quality=#{quality}"

ping url
end
Expand All @@ -99,7 +94,7 @@ def screenshot(width, height, quality)
# @return [True, nil] true if it worked, nil if something went wrong check
# the console for the error message
def send_string(text)
ping player_url+"/application/sendString?text=#{CGI::escape(text.to_s)}"
ping player_url + "/application/sendString?text=#{CGI.escape(text.to_s)}"
end

# Sends a key code to the Plex Client. Key codes represent key presses on
Expand All @@ -112,12 +107,12 @@ def send_string(text)
# @return [True, nil] true if it worked, nil if something went wrong check
# the console for the error message
def send_key(code)
ping player_url+"/application/sendKey?code=#{CGI::escape(code.to_s)}"
ping player_url + "/application/sendKey?code=#{CGI.escape(code.to_s)}"
end

# (see #send_key)
def send_virtual_key(code)
ping player_url+"/application/sendVirtualKey?code=#{CGI::escape(code.to_s)}"
ping player_url + "/application/sendVirtualKey?code=#{CGI.escape(code.to_s)}"
end

# @private
Expand All @@ -133,14 +128,13 @@ def inspect #:nodoc:
private

def player_url
URI.escape(url+"/system/players/#{name}")
url + '/system/players/' + CGI.escape(name)
end

def ping(url)
!!Plex.open(url).read
rescue => e
puts "Error trying to ping #{url} - #{e.message}"
end

end
end
1 change: 0 additions & 1 deletion lib/plex-ruby/library.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Plex
class Library

attr_reader :server

# @param [Server] server this libary belongs to
Expand Down
4 changes: 1 addition & 3 deletions lib/plex-ruby/movie.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Plex
class Movie

attr_reader :section, :key

# @param [Section] section this movie belongs in
Expand Down Expand Up @@ -46,12 +45,11 @@ def inspect #:nodoc:
private

def xml_doc
@xml_doc ||= Nokogiri::XML( Plex.open(url+key) )
@xml_doc ||= Nokogiri::XML(Plex.open(url+key))
end

def video
@video ||= Plex::Video.new(xml_doc.search('Video').first)
end

end
end
9 changes: 4 additions & 5 deletions lib/plex-ruby/section.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module Plex
class Section
GROUPS = %w(all unwatched newest recentlyAdded recentlyViewed onDeck).freeze

GROUPS = %w(all unwatched newest recentlyAdded recentlyViewed onDeck)
ATTRIBUTES = %w(refreshing key type title art agent scanner language updatedAt).freeze

ATTRIBUTES = %w(refreshing key type title art agent scanner language updatedAt)
CATEGORIES = %w(collection firstCharacter genre year contentRating folder).freeze

CATEGORIES = %w(collection firstCharacter genre year contentRating folder)

attr_reader *ATTRIBUTES.map {|m| Plex.underscore(m) }
attr_reader(*ATTRIBUTES.map { |m| Plex.underscore(m) })
attr_reader :library

# @param [Library] library this Section belongs to
Expand Down
2 changes: 0 additions & 2 deletions lib/plex-ruby/stream.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Plex
class Stream

ATTRIBUTES = %w(id streamType codec index language languageCode)

# @param [Nokogiri::XML::Element] nokogiri element that represents this
Expand All @@ -20,6 +19,5 @@ def ==(other)
super
end
end

end
end
2 changes: 1 addition & 1 deletion lib/plex-ruby/tags.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%w(Genre Writer Director Country).each { |type|
%w(Collection Genre Writer Director Country).each { |type|
eval <<-CLASS
module Plex
class #{type}
Expand Down
2 changes: 1 addition & 1 deletion lib/plex-ruby/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Plex
VERSION = "1.5.3"
VERSION = "1.5.4"
end
14 changes: 7 additions & 7 deletions lib/plex-ruby/video.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module Plex
class Video

ATTRIBUTES = %w(ratingKey key studio type title titleSort contentRating summary
rating viewCount year tagline thumb art duration
originallyAvailableAt updatedAt)

attr_reader :medias, :genres, :writers, :directors, :roles, :attribute_hash
attr_reader :medias, :genres, :writers, :directors, :roles, :collections, :attribute_hash

# @param [Nokogiri::XML::Element] nokogiri element that represents this
# Video
Expand All @@ -18,11 +17,12 @@ def initialize(node)
end
end

@medias = node.search('Media').map { |m| Plex::Media.new(m) }
@genres = node.search('Genre').map { |m| Plex::Genre.new(m) }
@writers = node.search('Writer').map { |m| Plex::Writer.new(m) }
@directors = node.search('Director').map { |m| Plex::Director.new(m) }
@roles = node.search('Role').map { |m| Plex::Role.new(m) }
@medias = node.search('Media').map { |m| Plex::Media.new(m) }
@genres = node.search('Genre').map { |m| Plex::Genre.new(m) }
@writers = node.search('Writer').map { |m| Plex::Writer.new(m) }
@directors = node.search('Director').map { |m| Plex::Director.new(m) }
@roles = node.search('Role').map { |m| Plex::Role.new(m) }
@collections = node.search('Collection').map { |m| Plex::Collection.new(m) }
end


Expand Down
27 changes: 14 additions & 13 deletions plex-ruby.gemspec
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "plex-ruby/version"
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'plex-ruby/version'

Gem::Specification.new do |s|
s.name = "plex-ruby"
s.name = 'plex-ruby'
s.version = Plex::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Eric Koslow"]
s.email = ["[email protected]"]
s.homepage = "https://github.com/ekosz/Plex-Ruby"
s.summary = %q{Plex Media Server APIs in easy ruby code}
s.description = %q{Extracts the Plex Media Server API into easy to write ruby code}
s.authors = ['Eric Koslow']
s.email = ['[email protected]']
s.homepage = 'https://github.com/ekosz/Plex-Ruby'
s.summary = 'Plex Media Server APIs in easy ruby code'
s.description = 'Extracts the Plex Media Server API into easy to write ruby code'

s.rubyforge_project = "plex-ruby"
s.rubyforge_project = 'plex-ruby'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ['lib']

s.add_development_dependency 'minitest'
s.add_development_dependency "rake"
s.add_development_dependency "fakeweb"
s.add_development_dependency 'rake'
s.add_development_dependency 'fakeweb'
s.add_development_dependency 'pry'
s.add_runtime_dependency 'nokogiri'
end
2 changes: 1 addition & 1 deletion test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Plex::Config do

it "should be configurable" do
Plex.config.auth_token.must_equal nil
assert_nil(Plex.config.auth_token)

Plex.configure do |config|
config.auth_token = "ABCD"
Expand Down
Loading