summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntti Ajanki <antti.ajanki@iki.fi>2011-01-23 16:34:33 +0200
committerAntti Ajanki <antti.ajanki@iki.fi>2011-01-23 16:34:33 +0200
commit9ede576ef1934f3e4ce5fddbdd7d1ba0b361e67a (patch)
tree03442a8b31291e4ae1b989a8bcaf16c6f09a3ef1
parent98c387e6944ff6539a5b3bd47336187e447c2570 (diff)
downloadvdr-plugin-webvideo-9ede576ef1934f3e4ce5fddbdd7d1ba0b361e67a.tar.gz
vdr-plugin-webvideo-9ede576ef1934f3e4ce5fddbdd7d1ba0b361e67a.tar.bz2
Support downloading in watchonvdr_proxy.py, patch by Samuli Sorvakko
-rw-r--r--HISTORY4
-rw-r--r--examples/savevideo_bookmarklet.js1
-rw-r--r--[-rwxr-xr-x]examples/watchonvdr_proxy.py80
3 files changed, 48 insertions, 37 deletions
diff --git a/HISTORY b/HISTORY
index 72332f1..09543c7 100644
--- a/HISTORY
+++ b/HISTORY
@@ -215,8 +215,10 @@ Video site modules:
- Command line arguments override config file options.
- Fixes for Youtube, Metacafe and Google modules.
-Version 0.4.1
+2011-xx-xx: Version 0.4.1
- Accept -p as alternative to --postprocess (thanks to Matti Lehtimäki).
- New option --prefermplayer prefers mplayer over xineliboutput when
streaming (thanks to Matti Lehtimäki).
+- Bookmarklet for saving a video from the web browser (a patch by
+ Samuli Sorvakko).
diff --git a/examples/savevideo_bookmarklet.js b/examples/savevideo_bookmarklet.js
new file mode 100644
index 0000000..ac16542
--- /dev/null
+++ b/examples/savevideo_bookmarklet.js
@@ -0,0 +1 @@
+javascript:(function(){ var vdrserver='127.0.0.1:43280'; var xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET", "http://" + vdrserver + "/download?url=" + encodeURIComponent(location.href), true); xmlhttp.send(null); })(); \ No newline at end of file
diff --git a/examples/watchonvdr_proxy.py b/examples/watchonvdr_proxy.py
index 2ade294..be9afc2 100755..100644
--- a/examples/watchonvdr_proxy.py
+++ b/examples/watchonvdr_proxy.py
@@ -3,8 +3,8 @@
# Proxy for relaying commands to play a video on VDR from a web
# browser to VDR.
#
-# Listens for HTTP GET /play?url=XXX requests where XXX is the address
-# of the video page (not address of the video stream) and converts
+# Listens for HTTP GET /play?url=XXX requests, where XXX is the address
+# of the video page (not the address of the video stream), and converts
# them to webvideo plugin SVDRP commands. The bookmarklet in
# webvi_bookmarklet.js generates such requests. See README for the
# list of supported video sites.
@@ -27,49 +27,57 @@ class SVDRPRequestHandler(BaseHTTPRequestHandler):
def is_video_file(self, url):
ext = os.path.splitext(urlparse(url).path)[1]
- return ext not in ('', '.html', '.html')
+ return ext not in ('', '.htm', '.html')
def do_GET(self):
if self.path.startswith('/play?url='):
videopage = urllib.unquote(self.path[len('/play?url='):])
+ operation = "play"
+
+ elif self.path.startswith('/download?url='):
+ videopage = urllib.unquote(self.path[len('/download?url='):])
+ operation = "dwld"
- # Strip everything after the first linefeed to prevent
- # SVDRP command injection.
- videopage = videopage.split('\r', 1)[0].split('\n', 1)[0]
-
- try:
- self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- self.sock.settimeout(10)
- self.sock.connect(SVDRP_ADDRESS)
-
- # If this is a video file ask xineliboutput to play
- # it. Otherwise assume it is a video page from one of
- # the supported sites and let webvideo extract the
- # video address from the page.
- if self.is_video_file(videopage):
- self.send('plug xineliboutput pmda %s' % videopage)
- else:
- self.send('plug webvideo play %s' % videopage)
- self.send('quit')
- while len(self.sock.recv(4096)) > 0:
- pass
- self.sock.close()
-
- self.send_response(204, 'OK')
- self.send_header('Access-Control-Allow-Origin', '*')
- self.end_headers()
- except socket.error, exc:
- self.send_response(503, 'SVDRP connection error: %s' % exc)
- self.send_header('Access-Control-Allow-Origin', '*')
- self.end_headers()
- except socket.timeout:
- self.send_response(504, 'SVDRP timeout')
- self.send_header('Access-Control-Allow-Origin', '*')
- self.end_headers()
else:
self.send_response(404, 'Not found')
self.send_header('Access-Control-Allow-Origin', '*')
self.end_headers()
+ return
+
+ # Strip everything after the first linefeed to prevent
+ # SVDRP command injection.
+ videopage = videopage.split('\r', 1)[0].split('\n', 1)[0]
+
+ try:
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.sock.settimeout(10)
+ self.sock.connect(SVDRP_ADDRESS)
+
+ # If this is a video file ask xineliboutput to play
+ # it. Otherwise assume it is a video page from one of
+ # the supported sites and let webvideo extract the
+ # video address from the page.
+ if self.is_video_file(videopage) and operation == "play":
+ self.send('plug xineliboutput pmda %s' % videopage)
+ else:
+ self.send('plug webvideo %s %s' % (operation, videopage) )
+ self.send('quit')
+ while len(self.sock.recv(4096)) > 0:
+ pass
+ self.sock.close()
+
+ self.send_response(204, 'OK')
+ self.send_header('Access-Control-Allow-Origin', '*')
+ self.end_headers()
+ except socket.error, exc:
+ self.send_response(503, 'SVDRP connection error: %s' % exc)
+ self.send_header('Access-Control-Allow-Origin', '*')
+ self.end_headers()
+ except socket.timeout:
+ self.send_response(504, 'SVDRP timeout')
+ self.send_header('Access-Control-Allow-Origin', '*')
+ self.end_headers()
+
def main():
parser = OptionParser()