diff options
author | Christopher Rosell <chrippa@tanuki.se> | 2011-12-19 15:45:12 +0100 |
---|---|---|
committer | Christopher Rosell <chrippa@tanuki.se> | 2011-12-19 15:45:12 +0100 |
commit | 89be5d3882d3849809a99693de4da167a638ec01 (patch) | |
tree | a23daef542ee7a1c16366451f3aa2ad91c527774 /src | |
parent | 166c98fcce9548df9bdc8586570df6ed00ad71b7 (diff) |
Add argument reading from ~/.livestreamerrc.
Diffstat (limited to 'src')
-rw-r--r-- | src/livestreamer/__init__.py | 4 | ||||
-rw-r--r-- | src/livestreamer/cli.py | 15 | ||||
-rw-r--r-- | src/livestreamer/utils.py | 6 |
3 files changed, 19 insertions, 6 deletions
diff --git a/src/livestreamer/__init__.py b/src/livestreamer/__init__.py index 0e399b9..e429e7e 100644 --- a/src/livestreamer/__init__.py +++ b/src/livestreamer/__init__.py @@ -1,5 +1,9 @@ from livestreamer import plugins +import os.path + +RCFILE = os.path.expanduser("~/.livestreamerrc") + def resolve_url(url): for name, plugin in plugins.get_plugins().items(): if plugin.can_handle_url(url): diff --git a/src/livestreamer/cli.py b/src/livestreamer/cli.py index b4b99e7..7bb57e2 100644 --- a/src/livestreamer/cli.py +++ b/src/livestreamer/cli.py @@ -1,17 +1,17 @@ #!/usr/bin/env python3 -import argparse import sys, os import livestreamer -parser = argparse.ArgumentParser(description="Util to play various livestreaming services in a custom player") +parser = livestreamer.utils.ArgumentParser(description="Util to play various livestreaming services in a custom player", + fromfile_prefix_chars="@") parser.add_argument("url", help="URL to stream", nargs="?") parser.add_argument("stream", help="stream to play", nargs="?") -parser.add_argument("player", help="commandline for player", nargs="?", default="vlc") +parser.add_argument("-p", "--player", metavar="player", help="commandline for player", default="vlc") parser.add_argument("-o", "--output", metavar="filename", help="write stream to file instead of playing it") parser.add_argument("-c", "--cmdline", action="store_true", help="print commandline used internally to play stream") -parser.add_argument("-p", "--plugins", action="store_true", help="print installed plugins") +parser.add_argument("-l", "--plugins", action="store_true", help="print installed plugins") def exit(msg): @@ -59,7 +59,12 @@ def print_plugins(): def main(): - args = parser.parse_args() + arglist = sys.argv[1:] + + if os.path.exists(livestreamer.RCFILE): + arglist.insert(0, "@" + livestreamer.RCFILE) + + args = parser.parse_args(arglist) if args.url: handle_url(args) diff --git a/src/livestreamer/utils.py b/src/livestreamer/utils.py index bfb59cc..7eaec95 100644 --- a/src/livestreamer/utils.py +++ b/src/livestreamer/utils.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from livestreamer.compat import urllib, bytes -import hmac, hashlib, zlib +import hmac, hashlib, zlib, argparse SWF_KEY = b"Genuine Adobe Flash Player 001" @@ -28,6 +28,10 @@ class CommandLine(object): return cmdline +class ArgumentParser(argparse.ArgumentParser): + def convert_arg_line_to_args(self, line): + arg = line.split("=") + yield "--%s=%s" % (arg[0].strip(), arg[1].strip()) def swfverify(url): fd = urllib.urlopen(url) |