Skip to content
Browse files

added ability to play entire seasons

  • Loading branch information...
1 parent 9240b07 commit 8eb077007ce872e945ba6893aab4dfa4ae1f5525 @patrickkettner patrickkettner committed Jan 23, 2012
Showing with 195 additions and 141 deletions.
  1. +1 −0 Gemfile
  2. +151 −139 lib/siriproxy-xbmc.rb
  3. +40 −2 lib/xbmc_library.rb
  4. +3 −0 siriproxy-xbmc.gemspec
View
1 Gemfile
@@ -1,4 +1,5 @@
source "http://rubygems.org"
+gem "chronic"
# Specify your gem's dependencies in siriproxy-example.gemspec
gemspec
View
290 lib/siriproxy-xbmc.rb
@@ -21,150 +21,162 @@
require 'cora'
require 'siri_objects'
require 'xbmc_library'
+require 'chronic'
#######
# This is plugin to control XBMC
# Remember to configure the host and port for your XBMC computer in config.yml in the SiriProxy dir
######
class SiriProxy::Plugin::XBMC < SiriProxy::Plugin
- def initialize(config)
- appname = "SiriProxy-XBMC"
- host = config["xbmc_host"]
- port = config["xbmc_port"]
- username = config["xbmc_username"]
- password = config["xbmc_password"]
-
- @roomlist = Hash["default" => Hash["host" => host, "port" => port, "username" => username, "password" => password]]
-
- rooms = File.expand_path('~/.siriproxy/xbmc_rooms.yml')
- if (File::exists?( rooms ))
- @roomlist = YAML.load_file(rooms)
- end
-
- @active_room = @roomlist.keys.first
-
- @xbmc = XBMCLibrary.new(@roomlist, appname)
- end
-
- #show plugin status
- listen_for /[xX] *[bB] *[mM] *[cC] *(.*)/i do |roomname|
- roomname = roomname.downcase.strip
- roomcount = @roomlist.keys.length
-
- if (roomcount > 1 && roomname == "")
- say "You have #{roomcount} rooms, here is their status:"
-
- @roomlist.each { |name,room|
- if (@xbmc.connect(name))
- say "[#{name}] Online", spoken: "The #{name} is online"
- else
- say "[#{name}] Offline", spoken: "The #{name} is offline"
- end
- }
- else
- if (roomname == "")
- roomname = @roomlist.keys.first
- end
- if (roomname != "" && roomname != nil && @roomlist.has_key?(roomname))
- if (@xbmc.connect(roomname))
- say "XBMC is online"
- else
- say "XBMC is offline, please check the plugin configuration and check if XBMC is running"
- end
- else
- say "There is no room defined called \"#{roomname}\""
- end
- end
- request_completed #always complete your request! Otherwise the phone will "spin" at the user!
- end
-
- # stop playing
- listen_for /^stop/i do
- if (@xbmc.connect(@active_room))
- if @xbmc.stop()
- say "I stopped the video player"
- else
- say "There is no video playing"
- end
- end
- request_completed #always complete your request! Otherwise the phone will "spin" at the user!
- end
-
- # pause playing
- listen_for /^pause/i do
- if (@xbmc.connect(@active_room))
- if @xbmc.pause()
- say "I paused the video player"
- else
- say "There is no video playing"
- end
- end
- request_completed #always complete your request! Otherwise the phone will "spin" at the user!
- end
-
- # resume playing
- listen_for /^resume|unpause|continue/i do
- if (@xbmc.connect(@active_room))
- if @xbmc.pause()
- say "I resumed the video player", spoken: "Resuming video"
- else
- say "There is no video playing"
- end
- end
- request_completed #always complete your request! Otherwise the phone will "spin" at the user!
- end
-
- # set default room
- # set default room
- listen_for /(?:(?:[Ii]'m in)|(?:[Ii] am in)|(?:[Uu]se)|(?:[Cc]ontrol)) the (.*)/i do |roomname|
- roomname = roomname.downcase.strip
- if (roomname != "" && roomname != nil && @roomlist.has_key?(roomname))
- @active_room = roomname
- say "Noted.", spoken: "Commands will be sent to the \"#{roomname}\""
- else
- say "There is no room defined called \"#{roomname}\""
- end
- request_completed #always complete your request! Otherwise the phone will "spin" at the user!
- end
-
- #play movie or episode
- listen_for /play (.+?)(?: in the (.*))?$/i do |title,roomname|
- if (roomname == "" || roomname == nil)
- roomname = @active_room
- else
- roomname = roomname.downcase.strip
- end
-
- if (@xbmc.connect(roomname))
- if @roomlist.has_key?(roomname)
- @active_room = roomname
- end
-
- tvshow = @xbmc.find_show(title)
- if (tvshow == "")
- movie = @xbmc.find_movie(title)
- if (movie == "")
- say "Title not found, please try again"
- else
- say "Now playing \"#{movie["title"]}\"", spoken: "Now playing \"#{movie["title"]}\""
- @xbmc.play(movie["file"])
- end
- else
- episode = @xbmc.find_first_unwatched_episode(tvshow["tvshowid"])
- if (episode == "")
- say "No unwatched episode found for the \"#{tvshow["label"]}\""
- else
- say "Now playing \"#{episode["title"]}\" (#{episode["showtitle"]}, Season #{episode["season"]}, Episode #{episode["episode"]})", spoken: "Now playing \"#{episode["title"]}\""
- @xbmc.play(episode["file"])
- end
- end
- else
- say "The XBMC interface is unavailable, please check the plugin configuration or check if XBMC is running"
- end
-
- request_completed #always complete your request! Otherwise the phone will "spin" at the user!
- end
-
-
+ def initialize(config)
+ appname = "SiriProxy-XBMC"
+ host = config["xbmc_host"]
+ port = config["xbmc_port"]
+ username = config["xbmc_username"]
+ password = config["xbmc_password"]
+
+ @roomlist = Hash["default" => Hash["host" => host, "port" => port, "username" => username, "password" => password]]
+
+ rooms = File.expand_path('~/.siriproxy/xbmc_rooms.yml')
+ if (File::exists?( rooms ))
+ @roomlist = YAML.load_file(rooms)
+ end
+
+ @active_room = @roomlist.keys.first
+
+ @xbmc = XBMCLibrary.new(@roomlist, appname)
+ end
+
+ #show plugin status
+ listen_for /[xX] *[bB] *[mM] *[cC] *(.*)/i do |roomname|
+ roomname = roomname.downcase.strip
+ roomcount = @roomlist.keys.length
+
+ if (roomcount > 1 && roomname == "")
+ say "You have #{roomcount} rooms, here is their status:"
+
+ @roomlist.each { |name,room|
+ if (@xbmc.connect(name))
+ say "[#{name}] Online", spoken: "The #{name} is online"
+ else
+ say "[#{name}] Offline", spoken: "The #{name} is offline"
+ end
+ }
+ else
+ if (roomname == "")
+ roomname = @roomlist.keys.first
+ end
+ if (roomname != "" && roomname != nil && @roomlist.has_key?(roomname))
+ if (@xbmc.connect(roomname))
+ say "XBMC is online"
+ else
+ say "XBMC is offline, please check the plugin configuration and check if XBMC is running"
+ end
+ else
+ say "There is no room defined called \"#{roomname}\""
+ end
+ end
+ request_completed #always complete your request! Otherwise the phone will "spin" at the user!
+ end
+
+ # stop playing
+ listen_for /^stop/i do
+ if (@xbmc.connect(@active_room))
+ if @xbmc.stop()
+ say "I stopped the video player"
+ else
+ say "There is no video playing"
+ end
+ end
+ request_completed #always complete your request! Otherwise the phone will "spin" at the user!
+ end
+
+ # pause playing
+ listen_for /^pause/i do
+ if (@xbmc.connect(@active_room))
+ if @xbmc.pause()
+ say "I paused the video player"
+ else
+ say "There is no video playing"
+ end
+ end
+ request_completed #always complete your request! Otherwise the phone will "spin" at the user!
+ end
+
+ # resume playing
+ listen_for /^resume|unpause|continue/i do
+ if (@xbmc.connect(@active_room))
+ if @xbmc.pause()
+ say "I resumed the video player", spoken: "Resuming video"
+ else
+ say "There is no video playing"
+ end
+ end
+ request_completed #always complete your request! Otherwise the phone will "spin" at the user!
+ end
+
+ # set default room
+ # set default room
+ listen_for /(?:(?:[Ii]'m in)|(?:[Ii] am in)|(?:[Uu]se)|(?:[Cc]ontrol)) the (.*)/i do |roomname|
+ roomname = roomname.downcase.strip
+ if (roomname != "" && roomname != nil && @roomlist.has_key?(roomname))
+ @active_room = roomname
+ say "Noted.", spoken: "Commands will be sent to the \"#{roomname}\""
+ else
+ say "There is no room defined called \"#{roomname}\""
+ end
+ request_completed #always complete your request! Otherwise the phone will "spin" at the user!
+ end
+
+ #play movie or episode
+ listen_for /watch (.+?)(?: in the (.*))?$/i do |title,roomname|
+ if (roomname == "" || roomname == nil)
+ roomname = @active_room
+ else
+ roomname = roomname.downcase.strip
+ end
+
+ if (@xbmc.connect(roomname))
+ if @roomlist.has_key?(roomname)
+ @active_room = roomname
+ end
+
+ tvshow = @xbmc.find_show(title.split(' season')[0])
+ if (tvshow == "")
+ movie = @xbmc.find_movie(title)
+ if (movie == "")
+ say "Title not found, please try again"
+ else
+ say "Now playing \"#{movie["title"]}\"", spoken: "Now playing \"#{movie["title"]}\""
+ @xbmc.play(movie["file"])
+ end
+ else
+ numberized_title = Chronic::Numerizer.numerize(title)
+ season_check = numberized_title.match('season \d+')
+ if season_check
+ season = season_check[0].match('\d+')[0].to_i
+ episode_check = numberized_title.match('episode \d+')
+ if episode_check
+ episode = season_check[0].match('\d+')
+ #search for spefic episode
+ else
+ #search for entire season
+ tvshow = @xbmc.play_season(tvshow["tvshowid"], season)
+ end
+ else
+ episode = @xbmc.find_first_unwatched_episode(tvshow["tvshowid"])
+ if (episode == "")
+ say "No unwatched episode found for the \"#{tvshow["label"]}\""
+ else
+ say "Now playing \"#{episode["title"]}\" (#{episode["showtitle"]}, Season #{episode["season"]}, Episode #{episode["episode"]})", spoken: "Now playing \"#{episode["title"]}\""
+ @xbmc.play(episode["file"])
+ end
+ end
+ end
+ else
+ say "The XBMC interface is unavailable, please check the plugin configuration or check if XBMC is running"
+ end
+ request_completed #always complete your request! Otherwise the phone will "spin" at the user!
+ end
end
View
42 lib/xbmc_library.rb
@@ -43,7 +43,6 @@ def invoke_json_method(method, params={})
raise err.class, err.message + ". Did you configure the url and port for XBMC properly using Xbmc.base_uri 'http://localhost:1234'?"
end
-
def test()
return xbmc('VideoLibrary.GetRecentlyAddedMovies')
end
@@ -108,7 +107,7 @@ def find_movie(title)
end
def find_show(title)
- puts "[#{@appname}] Finding TV show (API version #{$apiVersion["version"]})"
+ puts "[#{@appname}] Finding #{title} (API version #{$apiVersion["version"]})"
result = ""
title = title.downcase.gsub(/[^0-9A-Za-z]/, '')
if ($apiVersion["version"] == 2)
@@ -144,6 +143,45 @@ def find_first_unwatched_episode(tvshowid)
return result
end
+ def play_season(tvshowid, season_number)
+ puts "[#{@appname}] Looking up the path for season #{season_number} of #{tvshowid} (API version #{$apiVersion["version"]})"
+ result = ""
+ if ($apiVersion["version"] == 2)
+ season_path = xbmc('VideoLibrary.GetEpisodes', { :tvshowid => tvshowid, :season => season_number, :fields => ["file"] } )['episodes']
+ if season_path
+ season_path = season_path.first['file'].split('/')
+ season_path.pop
+ season_path = season_path.join('/')
+ else
+ raise "You don't have that Season"
+ end
+ else
+ season_path = xbmc('VideoLibrary.GetEpisodes', { :tvshowid => tvshowid, :season => season_number, :properties => ["file"] } )['episodes']
+ if season_path
+ season_path = season_path.first['file'].split('/')
+ season_path.pop
+ season_path = season_path.join('/')
+ else
+ raise "You don't have that Season"
+ end
+ end
+
+ puts "[#{@appname}] Generating Playlist (API version #{$apiVersion["version"]})"
+ begin
+ if ($apiVersion["version"] == 2)
+ xbmc('VideoPlaylist.Clear')
+ xbmc('VideoPlaylist.Add', season_path)
+ xbmc('VideoPlaylist.Play')
+ else
+ xbmc('Playlist.Clear', {:playlistid => 1})
+ xbmc('Playlist.Add', {:playlistid => 1, :item => {:directory => season_path}})
+ xbmc('Player.Open', { :item => {:playlistid => 1}})
+ end
+ rescue
+ puts "[#{@appname}] An error occurred: #{$!}"
+ end
+ end
+
def play(file)
puts "[#{@appname}] Playing file (API version #{$apiVersion["version"]})"
begin
View
3 siriproxy-xbmc.gemspec
@@ -31,19 +31,22 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<json>, [">= 1.4.5"])
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
s.add_runtime_dependency(%q<i18n>, [">= 0"])
+ s.add_runtime_dependency(%q<chronic>, [">= 0"])
s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
else
s.add_dependency(%q<httparty>, [">= 0.6.0"])
s.add_dependency(%q<json>, [">= 1.4.5"])
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
s.add_dependency(%q<i18n>, [">= 0"])
+ s.add_dependency(%q<chronic>, [">= 0"])
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
end
else
s.add_dependency(%q<httparty>, [">= 0.6.0"])
s.add_dependency(%q<json>, [">= 1.4.5"])
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
s.add_dependency(%q<i18n>, [">= 0"])
+ s.add_dependency(%q<chronic>, [">= 0"])
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
end

0 comments on commit 8eb0770

Please sign in to comment.
Something went wrong with that request. Please try again.