From 05ef3b4909cafa6a98524ec26d59fb7626060a10 Mon Sep 17 00:00:00 2001 From: Alexandre Joly Date: Thu, 29 Aug 2013 14:32:40 +0200 Subject: [PATCH 01/20] commands un/watched added --- lib/plex-ruby/library.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/plex-ruby/library.rb b/lib/plex-ruby/library.rb index f2a76f8..feb9eee 100644 --- a/lib/plex-ruby/library.rb +++ b/lib/plex-ruby/library.rb @@ -33,6 +33,22 @@ def sections! @sections = search_sections(xml_doc!) end + # Set the video as watched + # + # @param [Video] video to be set as watched + def watched(video) + command = "/:/scrobble?identifier=com.plexapp.plugins.library&key=" + open(url+command+video.rating_key) + end + + # Set the video as unwatched + # + # @param [Video] video to be set as unwatched + def unwatched(video) + command = "/:/unscrobble?identifier=com.plexapp.plugins.library&key=" + open(url+command+video.rating_key) + end + # @private def key #:nodoc: "/library/sections" From 6d097efbfb90c1499489badd662d75318f4e0277 Mon Sep 17 00:00:00 2001 From: Alexandre Joly Date: Fri, 30 Aug 2013 13:33:32 +0200 Subject: [PATCH 02/20] make the command url constant --- lib/plex-ruby/library.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/plex-ruby/library.rb b/lib/plex-ruby/library.rb index feb9eee..553223d 100644 --- a/lib/plex-ruby/library.rb +++ b/lib/plex-ruby/library.rb @@ -3,6 +3,9 @@ class Library attr_reader :server + WATCHED_LINK = "/:/scrobble?identifier=com.plexapp.plugins.library&key=" + UNWATCHED_LINK = "/:/unscrobble?identifier=com.plexapp.plugins.library&key=" + # @param [Server] server this libary belongs to def initialize(server) @server = server @@ -37,16 +40,14 @@ def sections! # # @param [Video] video to be set as watched def watched(video) - command = "/:/scrobble?identifier=com.plexapp.plugins.library&key=" - open(url+command+video.rating_key) + open(url+WATCHED_LINK+video.rating_key) end # Set the video as unwatched # # @param [Video] video to be set as unwatched def unwatched(video) - command = "/:/unscrobble?identifier=com.plexapp.plugins.library&key=" - open(url+command+video.rating_key) + open(url+UNWATCHED_LINK+video.rating_key) end # @private From 2aeed22b25202ca74fd2769263c09c3a469815b7 Mon Sep 17 00:00:00 2001 From: ygelfand Date: Sun, 6 Jul 2014 07:41:26 -0400 Subject: [PATCH 03/20] add basic search support --- lib/plex-ruby/section.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/plex-ruby/section.rb b/lib/plex-ruby/section.rb index 05fedde..3d2ccf3 100644 --- a/lib/plex-ruby/section.rb +++ b/lib/plex-ruby/section.rb @@ -35,13 +35,14 @@ def refresh(deep = false, force = false) # on_deck - videos that are "on deck" in this Section # # @return [Array] list of Shows or Movies in that group - GROUPS.each { |method| - class_eval %( - def #{Plex.underscore(method)} - Plex::Parser.new( self, Nokogiri::XML(open(url+key+'/#{method}')) ).parse - end - ) - } + GROUPS.each do |method| + define_method(Plex.underscore(method).to_sym) do |options = {}| + path = '/' + method + '?' + path += "title=#{CGI::escape(options[:title])}" if options[:title] + path += "type=4" if options[:episodes] + Plex::Parser.new( self, Nokogiri::XML(open(url+key+path )) ).parse + end + end # Find TV Shows / Episodes by categories # From a0e874e4bcf72e2e756e9fcaa614b6906d567d73 Mon Sep 17 00:00:00 2001 From: ygelfand Date: Sat, 22 Nov 2014 08:52:00 -0500 Subject: [PATCH 04/20] rework to not use class_eval --- lib/plex-ruby/section.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/plex-ruby/section.rb b/lib/plex-ruby/section.rb index 1048b1b..7f5b511 100644 --- a/lib/plex-ruby/section.rb +++ b/lib/plex-ruby/section.rb @@ -35,16 +35,14 @@ def refresh(deep = false, force = false) # on_deck - videos that are "on deck" in this Section # # @return [Array] list of Shows or Movies in that group - GROUPS.each { |method| - class_eval %( - def #{Plex.underscore(method)} do |options = {}| - path = '/' + method + '?' - path += "title=#{CGI::escape(options[:title])}" if options[:title] - path += "type=4" if options[:episodes] - Plex::Parser.new( self, Nokogiri::XML(Plex.open(url+key+path)) ).parse - end - ) - } + GROUPS.each do |method| + define_method(Plex.underscore(method).to_sym) do |options = {}| + path = '/' + method + '?' + path += "title=#{CGI::escape(options[:title])}" if options[:title] + path += "type=4" if options[:episodes] + Plex::Parser.new( self, Nokogiri::XML(Plex.open(url+key+path )) ).parse + end + end # Find TV Shows / Episodes by categories # From 739cab2766c04475b301eb90cd937d23494ed737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20B=C3=B6hm?= Date: Fri, 5 Dec 2014 23:17:34 +0100 Subject: [PATCH 05/20] Bumped version --- CHANGELOG.md | 3 +++ lib/plex-ruby/version.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42db3f5..73df587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.5.2 +* Added support for authentication token via `Plex.configure` + ## 1.5.1 * `Plex::Video` now supports multiple media entries (`@media` renamed to `@medias`) diff --git a/lib/plex-ruby/version.rb b/lib/plex-ruby/version.rb index a95ac9e..981f570 100644 --- a/lib/plex-ruby/version.rb +++ b/lib/plex-ruby/version.rb @@ -1,3 +1,3 @@ module Plex - VERSION = "1.5.1" + VERSION = "1.5.2" end From fd7225292651d4a54368522bd2ca7c583c58689b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20B=C3=B6hm?= Date: Fri, 5 Dec 2014 23:27:04 +0100 Subject: [PATCH 06/20] Changed travis ruby versions --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dc2e8c8..cec036a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ rvm: - - 1.9.2 - 1.9.3 + - 2.0.0 + - 2.1.1 From 771bcaf476afdfb74672d0ee41477a9671bfa9ad Mon Sep 17 00:00:00 2001 From: Rob Amos Date: Sun, 1 Mar 2015 02:59:45 +1100 Subject: [PATCH 07/20] Add support for viewing the current sessions. --- lib/plex-ruby/server.rb | 7 ++++ lib/plex-ruby/status.rb | 81 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 lib/plex-ruby/status.rb diff --git a/lib/plex-ruby/server.rb b/lib/plex-ruby/server.rb index 29c2243..d34ee28 100644 --- a/lib/plex-ruby/server.rb +++ b/lib/plex-ruby/server.rb @@ -14,6 +14,13 @@ def initialize(host, port) def library @library ||= Plex::Library.new(self) end + + # The current status of this server + # + # @return [Status] this Servers status + def status + @status ||= Plex::Status.new(self) + end # The Plex clients that are connected to this Server # diff --git a/lib/plex-ruby/status.rb b/lib/plex-ruby/status.rb new file mode 100644 index 0000000..7fee0e9 --- /dev/null +++ b/lib/plex-ruby/status.rb @@ -0,0 +1,81 @@ +module Plex + class Status + + attr_reader :server + + # @param [Server] server this libary belongs to + def initialize(server) + @server = server + end + + # Grab a specific session + # + # @param [String, Fixnum] key of the session we want + # @return [Video] session with that key + def session(id) + search_sessions(xml_doc, id).first + end + + # Cache busting version of #session + def session!(id) + search_sessions(xml_doc!, id).first + end + + # A list of sessions that are located in this library + # + # @return [Array] list of videos + def sessions + @sessions ||= search_sessions(xml_doc) + end + + # Cache busting version of #sessions + def sessions! + @sessions = search_sessions(xml_doc!) + end + + # @private + def key #:nodoc: + "/status/sessions" + end + + # @private + def url #:nodoc: + server.url + end + + # @private + def ==(other) #:nodoc: + if other.is_a? Library + server == other.server + else + super + end + end + + # @private + def inspect #:nodoc: + "#" + end + + private + + def search_sessions(doc, key = nil) + term = key ? "Video[@sessionKey='#{key}']" : 'Video' + doc.search(term).map { |m| Plex::Section.new(self, m) } + end + + def xml_doc + @xml_doc ||= base_doc + end + + def xml_doc! + @xml_doc = base_doc + end + + def base_doc + Nokogiri::XML( Plex.open(url+key) ) + end + + + end +end From b4eecf713596b7ef09301d5841846714e4fce679 Mon Sep 17 00:00:00 2001 From: Rob Amos Date: Sun, 1 Mar 2015 03:12:31 +1100 Subject: [PATCH 08/20] Add missing require --- lib/plex-ruby.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/plex-ruby.rb b/lib/plex-ruby.rb index 793cb20..e5ee64f 100644 --- a/lib/plex-ruby.rb +++ b/lib/plex-ruby.rb @@ -63,6 +63,7 @@ def self.camelize(string, first_letter_uppercase = false) require 'plex-ruby/media' require 'plex-ruby/part' require 'plex-ruby/stream' +require 'plex-ruby/status' require 'plex-ruby/tags' require 'plex-ruby/show' require 'plex-ruby/season' From 269890171affdb5685d47c599ab34df748793265 Mon Sep 17 00:00:00 2001 From: Rob Amos Date: Sun, 1 Mar 2015 03:13:58 +1100 Subject: [PATCH 09/20] Sessions are videos, not sections. --- lib/plex-ruby/status.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plex-ruby/status.rb b/lib/plex-ruby/status.rb index 7fee0e9..51d8594 100644 --- a/lib/plex-ruby/status.rb +++ b/lib/plex-ruby/status.rb @@ -61,7 +61,7 @@ def inspect #:nodoc: def search_sessions(doc, key = nil) term = key ? "Video[@sessionKey='#{key}']" : 'Video' - doc.search(term).map { |m| Plex::Section.new(self, m) } + doc.search(term).map { |m| Plex::Video.new(self, m) } end def xml_doc From 0c2441097908ba1812756de0e6af5485525418f2 Mon Sep 17 00:00:00 2001 From: Rob Amos Date: Sun, 1 Mar 2015 03:15:13 +1100 Subject: [PATCH 10/20] Videos only take the node as an initialiser (I should read before pushing) --- lib/plex-ruby/status.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plex-ruby/status.rb b/lib/plex-ruby/status.rb index 51d8594..7f7a408 100644 --- a/lib/plex-ruby/status.rb +++ b/lib/plex-ruby/status.rb @@ -61,7 +61,7 @@ def inspect #:nodoc: def search_sessions(doc, key = nil) term = key ? "Video[@sessionKey='#{key}']" : 'Video' - doc.search(term).map { |m| Plex::Video.new(self, m) } + doc.search(term).map { |m| Plex::Video.new(m) } end def xml_doc From d9325ab52de23ebb3282162baa7e97c0c6918e28 Mon Sep 17 00:00:00 2001 From: Rob Amos Date: Sun, 1 Mar 2015 03:19:53 +1100 Subject: [PATCH 11/20] Add support for players. --- lib/plex-ruby.rb | 1 + lib/plex-ruby/player.rb | 27 +++++++++++++++++++++++++++ lib/plex-ruby/video.rb | 1 + 3 files changed, 29 insertions(+) create mode 100644 lib/plex-ruby/player.rb diff --git a/lib/plex-ruby.rb b/lib/plex-ruby.rb index e5ee64f..b349857 100644 --- a/lib/plex-ruby.rb +++ b/lib/plex-ruby.rb @@ -62,6 +62,7 @@ def self.camelize(string, first_letter_uppercase = false) require 'plex-ruby/video' require 'plex-ruby/media' require 'plex-ruby/part' +require 'plex-ruby/player' require 'plex-ruby/stream' require 'plex-ruby/status' require 'plex-ruby/tags' diff --git a/lib/plex-ruby/player.rb b/lib/plex-ruby/player.rb new file mode 100644 index 0000000..aa68f1a --- /dev/null +++ b/lib/plex-ruby/player.rb @@ -0,0 +1,27 @@ +module Plex + class Player + + ATTRIBUTES = %w(machineIdentifier platform product state title) + + attr_reader :parts + + # @param [Nokogiri::XML::Element] nokogiri element that represents this + # Media + def initialize(node) + node.attributes.each do |method, val| + define_singleton_method(Plex.underscore(method).to_sym) do + val.value + end + end + end + + def ==(other) + if other.is_a? Media + id == other.id + else + super + end + end + + end +end diff --git a/lib/plex-ruby/video.rb b/lib/plex-ruby/video.rb index 79d896e..9fbc190 100644 --- a/lib/plex-ruby/video.rb +++ b/lib/plex-ruby/video.rb @@ -23,6 +23,7 @@ def initialize(node) @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) } + @players = node.search('Player').map { |m| Plex::Player.new(m) } end From 8b1731b800a2014645f47762609d7f00b4e9d05e Mon Sep 17 00:00:00 2001 From: Rob Amos Date: Sun, 1 Mar 2015 03:20:27 +1100 Subject: [PATCH 12/20] Missed a thing --- lib/plex-ruby/video.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plex-ruby/video.rb b/lib/plex-ruby/video.rb index 9fbc190..528a1e2 100644 --- a/lib/plex-ruby/video.rb +++ b/lib/plex-ruby/video.rb @@ -5,7 +5,7 @@ class Video 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, :players, :attribute_hash # @param [Nokogiri::XML::Element] nokogiri element that represents this # Video From 0f2bc097cb72d627acdb248ec9b8e773f8299b31 Mon Sep 17 00:00:00 2001 From: Jody Albritton Date: Thu, 23 Jul 2015 11:00:38 -0500 Subject: [PATCH 13/20] Correct URI escape Use URI escape to remove spaces from URL. --- lib/plex-ruby/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plex-ruby/client.rb b/lib/plex-ruby/client.rb index 023c443..e8e19e2 100644 --- a/lib/plex-ruby/client.rb +++ b/lib/plex-ruby/client.rb @@ -133,7 +133,7 @@ def inspect #:nodoc: private def player_url - url+"/system/players/#{name}" + URI.escape(url+"/system/players/#{name}") end def ping(url) From 981dd175d674c74cad7ea8daf8b52c266c12df29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20B=C3=B6hm?= Date: Thu, 23 Jul 2015 22:30:38 +0200 Subject: [PATCH 14/20] Bumped version to 1.5.3 --- CHANGELOG.md | 3 +++ lib/plex-ruby/version.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73df587..1e477e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.5.3 +* The player name is now escaped correctly in the URI (@jodyalbritton) + ## 1.5.2 * Added support for authentication token via `Plex.configure` diff --git a/lib/plex-ruby/version.rb b/lib/plex-ruby/version.rb index 981f570..9d95496 100644 --- a/lib/plex-ruby/version.rb +++ b/lib/plex-ruby/version.rb @@ -1,3 +1,3 @@ module Plex - VERSION = "1.5.2" + VERSION = "1.5.3" end From d9ecc4d22e8fa772c99acd2e5273b2e969aa7ce6 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 21 Jul 2014 21:33:22 -0400 Subject: [PATCH 15/20] Add support for reading Music sections Adds Artist, Album, and Track classes. Album and Artist are added as supported Directory types in Parser. --- lib/plex-ruby.rb | 3 ++ lib/plex-ruby/album.rb | 85 +++++++++++++++++++++++++++++++++++++++++ lib/plex-ruby/artist.rb | 85 +++++++++++++++++++++++++++++++++++++++++ lib/plex-ruby/parser.rb | 4 ++ lib/plex-ruby/track.rb | 68 +++++++++++++++++++++++++++++++++ 5 files changed, 245 insertions(+) create mode 100644 lib/plex-ruby/album.rb create mode 100644 lib/plex-ruby/artist.rb create mode 100644 lib/plex-ruby/track.rb diff --git a/lib/plex-ruby.rb b/lib/plex-ruby.rb index 793cb20..b180351 100644 --- a/lib/plex-ruby.rb +++ b/lib/plex-ruby.rb @@ -68,4 +68,7 @@ def self.camelize(string, first_letter_uppercase = false) require 'plex-ruby/season' require 'plex-ruby/episode' require 'plex-ruby/movie' +require 'plex-ruby/artist' +require 'plex-ruby/album' +require 'plex-ruby/track' diff --git a/lib/plex-ruby/album.rb b/lib/plex-ruby/album.rb new file mode 100644 index 0000000..dfd2e89 --- /dev/null +++ b/lib/plex-ruby/album.rb @@ -0,0 +1,85 @@ +module Plex + class Album + + ATTRIBUTES = %w(ratingKey guid title summary index thumb year addedAt updatedAt) + + attr_reader :section, :key, :attribute_hash + + # @param [Artist] Artist this album belongs to + # @param [String] key to use to later grab this Album + def initialize(section, key) + @section = section + @key = key + @attribute_hash = {} + + directory.attributes.each do |method, val| + @attribute_hash[Plex.underscore(method)] = val.value + define_singleton_method(Plex.underscore(method).to_sym) do + val.value + end + end + + @attribute_hash.merge({'key' => @key}) + end + + # The list of Tracks in the library that belong to this Album + # + # @return [Array] list of Tracks that appear on this Album + def tracks + search_children children + end + + # @private + def url #:nodoc: + section.url + end + + # @private + def ==(other) #:nodoc: + if other.is_a? Plex::Album + key == other.key + else + super + end + end + + # @private + def inspect #:nodoc: + "#" + end + + private + + def base_doc + Nokogiri::XML( open(url+key) ) + end + + def children_base + Nokogiri::XML( open(url+key+'/children') ) + end + + def xml_doc + @xml_doc ||= base_doc + end + + def children + @children ||= children_base + end + + def directory + @directory ||= xml_doc.search('Directory').first + end + + def search_children(node) + node.search('Track').map do |track| + plex_track.new(self, track.attr('key')) + end + end + + def plex_track + @plex_track ||= Plex::Track + end + + end + +end diff --git a/lib/plex-ruby/artist.rb b/lib/plex-ruby/artist.rb new file mode 100644 index 0000000..a635ab9 --- /dev/null +++ b/lib/plex-ruby/artist.rb @@ -0,0 +1,85 @@ +module Plex + class Artist + + ATTRIBUTES = %w(ratingKey guid title summary index thumb addedAt updatedAt) + + attr_reader :section, :key, :attribute_hash + + # @param [Section] section this artist belongs to + # @param [String] key to use to later grab this Artist + def initialize(section, key) + @section = section + @key = key + @attribute_hash = {} + + directory.attributes.each do |method, val| + @attribute_hash[Plex.underscore(method)] = val.value + define_singleton_method(Plex.underscore(method).to_sym) do + val.value + end + end + + @attribute_hash.merge({'key' => @key}) + end + + # The list of Albums in the library that belong to this Artist + # + # @return [Array] list of Albums that are credited to this Artist + def albums + @albums ||= search_children children + end + + # @private + def url #:nodoc: + section.url + end + + # @private + def ==(other) #:nodoc: + if other.is_a? Plex::Artist + key == other.key + else + super + end + end + + # @private + def inspect #:nodoc: + "#" + end + + private + + def base_doc + Nokogiri::XML( open(url+key) ) + end + + def children_base + Nokogiri::XML( open(url+key+'/children') ) + end + + def xml_doc + @xml_doc ||= base_doc + end + + def children + @children ||= children_base + end + + def directory + @directory ||= xml_doc.search('Directory').first + end + + def search_children(node) + node.search('Directory[type="album"]').map do |album| + plex_album.new(self, album.attr('key')[0..-10]) # Remove /children + end + end + + def plex_album + @plex_album ||= Plex::Album + end + + end + +end diff --git a/lib/plex-ruby/parser.rb b/lib/plex-ruby/parser.rb index 21dd61d..eea0244 100644 --- a/lib/plex-ruby/parser.rb +++ b/lib/plex-ruby/parser.rb @@ -63,6 +63,10 @@ def parse_directory case node.attr('type') when 'show' Plex::Show.new( parent, node.attr('key')[0..-10] ) # Remove /children + when 'artist' + Plex::Artist.new( parent, node.attr('key')[0..-10] ) + when 'album' + Plex::Album.new( parent, node.attr('key')[0..-10] ) else raise "Unsupported Directory type #{node.attr('type')}" end diff --git a/lib/plex-ruby/track.rb b/lib/plex-ruby/track.rb new file mode 100644 index 0000000..fc98fbc --- /dev/null +++ b/lib/plex-ruby/track.rb @@ -0,0 +1,68 @@ +module Plex + class Track + + ATTRIBUTES = %w(ratingKey title originalTitle summary index duration thumb year addedAt updatedAt) + + attr_reader :section, :key, :attribute_hash + + # @param [Album] Album this Track belongs to + # @param [String] key to use to later grab this Track + def initialize(section, key) + @section = section + @key = key + @attribute_hash = {} + + track.attributes.each do |method, val| + @attribute_hash[Plex.underscore(method)] = val.value + define_singleton_method(Plex.underscore(method).to_sym) do + val.value + end + end + + @attribute_hash.merge({'key' => @key}) + end + + # @private + def url #:nodoc: + section.url + end + + # @private + def ==(other) #:nodoc: + if other.is_a? Plex::Track + key == other.key + else + super + end + end + + # @private + def inspect #:nodoc: + "#" + end + + private + + def base_doc + Nokogiri::XML( open(url+key) ) + end + + def children_base + Nokogiri::XML( open(url+key+'/children') ) + end + + def xml_doc + @xml_doc ||= base_doc + end + + def children + @children ||= children_base + end + + def track + @track ||= xml_doc.search('Track').first + end + + end + +end From 94b08e8be2fdddfe9939dbb39eb2a725ac37da2c Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 15 Aug 2015 00:58:07 -0400 Subject: [PATCH 16/20] Add Medias to Track --- lib/plex-ruby/album.rb | 2 +- lib/plex-ruby/track.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/plex-ruby/album.rb b/lib/plex-ruby/album.rb index dfd2e89..3d25e9c 100644 --- a/lib/plex-ruby/album.rb +++ b/lib/plex-ruby/album.rb @@ -72,7 +72,7 @@ def directory def search_children(node) node.search('Track').map do |track| - plex_track.new(self, track.attr('key')) + plex_track.new(self, track.attr('key'), track.search('Media')) end end diff --git a/lib/plex-ruby/track.rb b/lib/plex-ruby/track.rb index fc98fbc..b03263b 100644 --- a/lib/plex-ruby/track.rb +++ b/lib/plex-ruby/track.rb @@ -4,10 +4,12 @@ class Track ATTRIBUTES = %w(ratingKey title originalTitle summary index duration thumb year addedAt updatedAt) attr_reader :section, :key, :attribute_hash + attr_reader :medias # @param [Album] Album this Track belongs to # @param [String] key to use to later grab this Track - def initialize(section, key) + # @param [Nokogiri::XML::Element] Media node(s) + def initialize(section, key, medias = nil) @section = section @key = key @attribute_hash = {} @@ -20,6 +22,8 @@ def initialize(section, key) end @attribute_hash.merge({'key' => @key}) + + @medias = medias.map { |m| Plex::Media.new(m) } end # @private From d23507276a459de43c0c8c1b5cc3a321e2a6f02f Mon Sep 17 00:00:00 2001 From: Josh Cano Date: Mon, 7 Nov 2016 21:34:13 -0700 Subject: [PATCH 17/20] feat: add support for refreshing section --- lib/plex-ruby/section.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plex-ruby/section.rb b/lib/plex-ruby/section.rb index 772d1eb..6a9fb45 100644 --- a/lib/plex-ruby/section.rb +++ b/lib/plex-ruby/section.rb @@ -20,8 +20,8 @@ def initialize(library, node) } end - # NOT IMPLEMENTED - def refresh(deep = false, force = false) + def refresh + Plex.open(url + key + '/refresh') end From 6d414070c007ffd467207ad44956a846c882fed0 Mon Sep 17 00:00:00 2001 From: Daniel Rudolph Date: Fri, 9 Dec 2016 23:39:36 +0000 Subject: [PATCH 18/20] use https, ignore cert --- lib/plex-ruby.rb | 2 +- lib/plex-ruby/server.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plex-ruby.rb b/lib/plex-ruby.rb index 793cb20..a811622 100644 --- a/lib/plex-ruby.rb +++ b/lib/plex-ruby.rb @@ -22,7 +22,7 @@ def self.configure # Custom open func which adds the required headers configured by # Plex.configure def self.open(url) - headers = {} + headers = {:ssl_verify_mode => 0} headers["X-Plex-Token"] = config.auth_token if config.auth_token super(url, headers) diff --git a/lib/plex-ruby/server.rb b/lib/plex-ruby/server.rb index 29c2243..5827382 100644 --- a/lib/plex-ruby/server.rb +++ b/lib/plex-ruby/server.rb @@ -29,7 +29,7 @@ def clients! # @private def url #:nodoc: - "http://#{host}:#{port}" + "https://#{host}:#{port}" end # @private From dd496c16567f2d3f38e022b7f0d60013024d68e5 Mon Sep 17 00:00:00 2001 From: Daniel Rudolph Date: Sat, 10 Dec 2016 10:29:13 +0100 Subject: [PATCH 19/20] update test urls to https --- test/test_client.rb | 2 +- test/test_helper.rb | 2 +- test/test_plex.rb | 4 ++-- test/test_server.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_client.rb b/test/test_client.rb index 41ccf95..659d3be 100644 --- a/test/test_client.rb +++ b/test/test_client.rb @@ -5,7 +5,7 @@ before do @server = FakeParent.new @client = Plex::Client.new(@server, FakeNode.new(FAKE_CLIENT_NODE_HASH)) - FakeWeb.register_uri(:get, %r|http://localhost:32400|, :body => "") + FakeWeb.register_uri(:get, %r|https://localhost:32400|, :body => "") end after do diff --git a/test/test_helper.rb b/test/test_helper.rb index dcb7a62..bca534f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -39,7 +39,7 @@ def search(value) class FakeParent def url - 'http://localhost:32400' + 'https://localhost:32400' end end diff --git a/test/test_plex.rb b/test/test_plex.rb index 9c8a38f..fac008e 100644 --- a/test/test_plex.rb +++ b/test/test_plex.rb @@ -9,7 +9,7 @@ end before do - FakeWeb.register_uri(:get, "http://localhost:32400", :body => "") + FakeWeb.register_uri(:get, "https://localhost:32400", :body => "") end after do @@ -20,7 +20,7 @@ it "has an open function which respects the configuration" do Plex.configure {|config| config.auth_token = "ABCD" } - Plex.open("http://localhost:32400").read + Plex.open("https://localhost:32400").read FakeWeb.last_request["X-Plex-Token"].must_equal "ABCD" end end diff --git a/test/test_server.rb b/test/test_server.rb index 4a643ae..3ce3994 100644 --- a/test/test_server.rb +++ b/test/test_server.rb @@ -14,7 +14,7 @@ end it "properly formats its url" do - @server.url.must_equal "http://localhost:3000" + @server.url.must_equal "https://localhost:3000" end it "has a libary" do From b2067e97d0c5857a47728cb9d5322c8d8976019a Mon Sep 17 00:00:00 2001 From: ygelfand Date: Sun, 11 Jul 2021 18:18:34 -0400 Subject: [PATCH 20/20] call URI.open --- lib/plex-ruby.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plex-ruby.rb b/lib/plex-ruby.rb index cd381b0..aea65f1 100644 --- a/lib/plex-ruby.rb +++ b/lib/plex-ruby.rb @@ -25,7 +25,7 @@ def self.open(url) headers = {:ssl_verify_mode => 0} headers["X-Plex-Token"] = config.auth_token if config.auth_token - super(url, headers) + URI.open(url, headers) end # Converts camel case names that are commonly found in the Plex APIs into