Skip to content

Commit 93a672b

Browse files
author
Hjalti Jakobsson
committed
Added a very basic Plex (www.plexapp.com) plugin
1 parent 9713504 commit 93a672b

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

plugins/plex/siriPlex.rb

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Copyright (C) 2011 by Hjalti Jakobsson <hjalti@hjaltijakobsson.com>
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
# THE SOFTWARE.
20+
21+
require 'rubygems'
22+
require 'tweaksiri'
23+
require 'siriobjectgenerator'
24+
require 'open-uri'
25+
26+
#######
27+
# This is a very basic plugin for Plex but I plan on adding to it =)
28+
# Eventually I'd like to have it talk to the SQLite DB that stores all the media information for Plex
29+
# That way you could ask Siri to play the latest episode of i.e. Mythbusters
30+
# Now it only supports pause, play and stop
31+
######
32+
33+
PLAY_COMMAND = "play"
34+
PAUSE_COMMAND = "pause"
35+
STOP_COMMAND = "stop"
36+
37+
class SiriPlex < SiriPlugin
38+
39+
#Plex Remote Implementation
40+
#Needs a lot of more functionality
41+
42+
def initialize()
43+
@host = "10.0.1.75"
44+
@port = 32400
45+
end
46+
47+
def run_playback_command(command)
48+
uri = "http://#{@host}:#{@port}/system/players/#{@host}/playback/#{command}"
49+
response = open(uri).read
50+
end
51+
52+
def pause()
53+
run_playback_command(PAUSE_COMMAND)
54+
end
55+
56+
def play()
57+
run_playback_command(PLAY_COMMAND)
58+
end
59+
60+
def stop()
61+
run_playback_command(STOP_COMMAND)
62+
end
63+
64+
#plugin implementations:
65+
def object_from_guzzoni(object, connection)
66+
67+
object
68+
end
69+
70+
71+
#Don't forget to return the object!
72+
def object_from_client(object, connection)
73+
74+
75+
object
76+
end
77+
78+
79+
def unknown_command(object, connection, command)
80+
object
81+
end
82+
83+
def speech_recognized(object, connection, phrase)
84+
85+
#We need to do this here because otherwise Siri thinks we are asking it to play music
86+
#from our iPhone's music library
87+
88+
if(phrase.match(/plex/i))
89+
response = nil
90+
91+
if(phrase.match(/pause/i))
92+
self.plugin_manager.block_rest_of_session_from_server
93+
pause()
94+
response = "Pausing Plex"
95+
elsif(phrase.match(/play/i) || phrase.match(/resume/i))
96+
self.plugin_manager.block_rest_of_session_from_server
97+
play()
98+
response = "Playing Plex"
99+
elsif(phrase.match(/stop/i))
100+
self.plugin_manager.block_rest_of_session_from_server
101+
stop()
102+
response = "Stopping Plex"
103+
end
104+
105+
if(response)
106+
return generate_siri_utterance(connection.lastRefId, response)
107+
end
108+
end
109+
110+
object
111+
end
112+
113+
end

start.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'plugins/testproxy/testproxy'
44
require 'plugins/eliza/eliza'
55
require 'plugins/twitter/siriTweet'
6+
require 'plugins/plex/siriPlex'
67
require './tweakSiri'
78
require './siriProxy'
89

0 commit comments

Comments
 (0)