aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Christopher Rosell <chrippa@tanuki.se>2012-05-27 00:51:00 +0200
committerGravatar Christopher Rosell <chrippa@tanuki.se>2012-05-27 00:51:00 +0200
commitca945afa5ce4c5edc1648cb130bda50ae483cfbd (patch)
treedd49da41e163e7f15580e85958fd6801b3fb77ad
parent419a59b97d7f00ddfca1062be3e512b2b41e84a1 (diff)
Add option to always write to output file even if it already exists.
-rw-r--r--src/livestreamer/cli.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/livestreamer/cli.py b/src/livestreamer/cli.py
index e7fbed4..449938f 100644
--- a/src/livestreamer/cli.py
+++ b/src/livestreamer/cli.py
@@ -10,6 +10,7 @@ parser.add_argument("url", help="URL to stream", nargs="?")
parser.add_argument("stream", help="stream to play", nargs="?")
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, use - for stdout")
+parser.add_argument("-f", "--force", action="store_true", help="always write to output file even if it already exists")
parser.add_argument("-O", "--stdout", action="store_true", help="write stream to stdout instead of playing it")
parser.add_argument("-l", "--plugins", action="store_true", help="print installed plugins")
@@ -47,10 +48,15 @@ def write_stream(fd, out, progress):
if out != stdout:
out.close()
-def check_output(output):
- if os.path.isfile(output):
+def check_output(output, force):
+ if os.path.isfile(output) and not force:
sys.stderr.write(("File output {0} already exists! Overwrite it? [y/N] ").format(output))
- answer = input()
+
+ try:
+ answer = input()
+ except:
+ sys.exit()
+
answer = answer.strip().lower()
if answer != "y":
@@ -96,7 +102,7 @@ def handle_url(args):
if args.output == "-":
out = stdout
else:
- out = check_output(args.output)
+ out = check_output(args.output, args.force)
progress = True
elif args.stdout:
out = stdout