summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntti Ajanki <antti.ajanki@iki.fi>2012-02-26 11:55:45 +0200
committerAntti Ajanki <antti.ajanki@iki.fi>2012-02-26 11:58:39 +0200
commit2404dfacec80307be5e68a3d970e37e4c7d7daf8 (patch)
tree99594a87cdfbdabd24ab5c1060eea3099c3b359a
parenta93e1f7cc301f874b5b22782c1f3f3ef8017a526 (diff)
downloadvdr-plugin-webvideo-2404dfacec80307be5e68a3d970e37e4c7d7daf8.tar.gz
vdr-plugin-webvideo-2404dfacec80307be5e68a3d970e37e4c7d7daf8.tar.bz2
Simple video download mode: --url
-rw-r--r--README.webvi5
-rw-r--r--TODO2
-rw-r--r--src/webvicli/webvicli/client.py47
3 files changed, 39 insertions, 15 deletions
diff --git a/README.webvi b/README.webvi
index 0248af9..326f7f4 100644
--- a/README.webvi
+++ b/README.webvi
@@ -49,6 +49,7 @@ Command line parameters
-h, --help show this help message and exit
-t DIR, --templatepath=DIR read video site templates from DIR
--vfat generate Windows compatible filenames
+-u URL, --url=URL Download video from URL and exit
-v, --verbose debug output
Usage
@@ -77,6 +78,10 @@ stream commands). A plain number without a command follows a link
(like "select") or downloads a stream (like "download") if the item is
not a navigation link.
+The command line option --url runs a single download mode that
+downloads a video from the the given URL and exits. URL must point to
+a video page on one of the supported sites (see README).
+
Config file
-----------
diff --git a/TODO b/TODO
index 3ef306e..dca011e 100644
--- a/TODO
+++ b/TODO
@@ -18,5 +18,3 @@ Fix support for mplayer plugin
Fix Vimeo search
Kill external downloader process when the player stops mid-stream
-
-webvi: load video based on web page url
diff --git a/src/webvicli/webvicli/client.py b/src/webvicli/webvicli/client.py
index f6ae3e9..db51aa1 100644
--- a/src/webvicli/webvicli/client.py
+++ b/src/webvicli/webvicli/client.py
@@ -67,6 +67,13 @@ def safe_filename(name, vfat):
return res
+def url_to_wvtref(url):
+ domain = urlparse(url).netloc.lower()
+ if domain == '':
+ return None
+
+ return 'wvt:///%s/videopage.xsl?srcurl=%s' % (domain, urllib.quote(url, ''))
+
class DownloadData:
def __init__(self, handle, progressstream):
self.handle = handle
@@ -637,13 +644,6 @@ class WVShell(cmd.Cmd):
return None
return menupage[v]
- def url_to_wvtref(self, url):
- domain = urlparse(url).netloc.lower()
- if domain == '':
- return None
-
- return 'wvt:///%s/videopage.xsl?srcurl=%s' % (domain, urllib.quote(url, ''))
-
def do_select(self, arg):
"""select x
Select the link whose index is x.
@@ -679,7 +679,7 @@ URL of a video page.
pass
if stream is None and arg.find('://') != -1:
- stream = self.url_to_wvtref(arg)
+ stream = url_to_wvtref(arg)
if stream is not None:
self.client.download(stream)
@@ -702,7 +702,7 @@ Play a stream. x can be an integer referring to a downloadable item
pass
if stream is None and arg.find('://') != -1:
- stream = self.url_to_wvtref(arg)
+ stream = url_to_wvtref(arg)
if stream is not None:
self.client.play_stream(stream)
@@ -811,6 +811,10 @@ def parse_command_line(cmdlineargs, options):
parser.add_option('--vfat', action='store_true',
dest='vfat', default=False,
help='generate Windows compatible filenames')
+ parser.add_option('-u', '--url', type='string',
+ dest='url',
+ help='Download video from URL and exit',
+ metavar='URL', default=None)
cmdlineopt = parser.parse_args(cmdlineargs)[0]
if cmdlineopt.templatepath is not None:
@@ -819,6 +823,8 @@ def parse_command_line(cmdlineargs, options):
options['verbose'] = cmdlineopt.verbose
if cmdlineopt.vfat:
options['vfat'] = cmdlineopt.vfat
+ if cmdlineopt.url:
+ options['url'] = cmdlineopt.url
return options
@@ -854,10 +860,25 @@ def main(argv):
if options.has_key('templatepath'):
webvi.api.set_config(WebviConfig.TEMPLATE_PATH, options['templatepath'])
- shell = WVShell(WVClient(player_list(options),
- options.get('download-limits', {}),
- options.get('stream-limits', {}),
- options.get('vfat', False)))
+ client = WVClient(player_list(options),
+ options.get('download-limits', {}),
+ options.get('stream-limits', {}),
+ options.get('vfat', False))
+
+ if options.has_key('url'):
+ stream = url_to_wvtref(options['url'])
+ if not stream:
+ print >> sys.stderr, 'Can\'t find video at ' + options['url']
+ sys.exit(1)
+
+ if not client.download(stream):
+ # FIXME: more helpful error message if URL is not a
+ # supported site
+ sys.exit(1)
+
+ sys.exit(0)
+
+ shell = WVShell(client)
shell.cmdloop()
if __name__ == '__main__':