From 045ef96252296eacfedeb300d8b8c0ebf69a0273 Mon Sep 17 00:00:00 2001 From: Olof Johansson Date: Sun, 9 Feb 2014 15:38:51 +0100 Subject: [PATCH 1/4] logging: adjust message format, : --- lib/svtplay_dl/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/svtplay_dl/__init__.py b/lib/svtplay_dl/__init__.py index 1001329..e5ab18c 100644 --- a/lib/svtplay_dl/__init__.py +++ b/lib/svtplay_dl/__init__.py @@ -87,7 +87,7 @@ def get_media(url, options): def setup_log(silent, verbose=False): - fmt = logging.Formatter('%(levelname)s %(message)s') + fmt = logging.Formatter('%(levelname)s: %(message)s') if silent: stream = sys.stderr level = logging.WARNING From b9107b20b63fa1bd0528ab0485ca0c3f262ee605 Mon Sep 17 00:00:00 2001 From: Olof Johansson Date: Sun, 9 Feb 2014 15:40:02 +0100 Subject: [PATCH 2/4] hls: Error on live streams This can be overriden using the --force flag, but the output may be a bit disappointing --- only the current state of the HLS playlist is downloaded, and no reload is attempted. --- lib/svtplay_dl/__init__.py | 11 ++++++++++- lib/svtplay_dl/error.py | 7 +++++++ lib/svtplay_dl/fetcher/hls.py | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lib/svtplay_dl/error.py diff --git a/lib/svtplay_dl/__init__.py b/lib/svtplay_dl/__init__.py index e5ab18c..50caff3 100644 --- a/lib/svtplay_dl/__init__.py +++ b/lib/svtplay_dl/__init__.py @@ -7,6 +7,7 @@ import os import logging from optparse import OptionParser +from svtplay_dl.error import UIException from svtplay_dl.log import log from svtplay_dl.utils import get_http_data, decode_html_entities, filenamify from svtplay_dl.service import service_handler, Generic @@ -41,6 +42,7 @@ class Options: self.resume = False self.live = False self.silent = False + self.force = False self.quality = 0 self.flexibleq = None self.hls = False @@ -72,7 +74,12 @@ def get_media(url, options): # output is a directory os.path.join(options.output, filenamify(title_tag)) - stream.get(options) + try: + stream.get(options) + except UIException as e: + log.error(e.message) + sys.exit(2) + if options.subtitle: if options.output != "-": stream.get_subtitle(options) @@ -121,6 +128,8 @@ def main(): action="store_true", dest="silent", default=False) parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False) + parser.add_option("-f", "--force", + action="store_true", dest="force", default=False) parser.add_option("-q", "--quality", default=0, metavar="quality", help="Choose what format to download.\nIt will download the best format by default") parser.add_option("-Q", "--flexible-quality", default=0, diff --git a/lib/svtplay_dl/error.py b/lib/svtplay_dl/error.py new file mode 100644 index 0000000..7559a9c --- /dev/null +++ b/lib/svtplay_dl/error.py @@ -0,0 +1,7 @@ +# ex:ts=4:sw=4:sts=4:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- + +from __future__ import absolute_import + +class UIException(Exception): + pass diff --git a/lib/svtplay_dl/fetcher/hls.py b/lib/svtplay_dl/fetcher/hls.py index 95baa7e..e4c051f 100644 --- a/lib/svtplay_dl/fetcher/hls.py +++ b/lib/svtplay_dl/fetcher/hls.py @@ -9,6 +9,19 @@ from svtplay_dl.utils import get_http_data, select_quality from svtplay_dl.output import progressbar, progress_stream, ETA from svtplay_dl.log import log from svtplay_dl.utils.urllib import urlparse +from svtplay_dl.error import UIException + +class HLSException(UIException): + def __init__(self, url, message): + self.url = url + super(HLSException, self).__init__(message) + + +class LiveHLSException(HLSException): + def __init__(self, url): + super(LiveHLSException, self).__init__( + url, "This is a live HLS stream, and they are not supported.") + def _get_full_url(url, srcurl): if url[:4] == 'http': @@ -31,6 +44,10 @@ def download_hls(options, url): data = get_http_data(url) globaldata, files = parsem3u(data) streams = {} + + if options.live and not options.force: + raise LiveHLSException(url) + for i in files: streams[int(i[1]["BANDWIDTH"])] = i[0] From 8e46384048f8babd49b9692898268d42a53f654f Mon Sep 17 00:00:00 2001 From: Olof Johansson Date: Tue, 11 Feb 2014 18:27:21 +0100 Subject: [PATCH 3/4] hds: Error on live streams This can be overriden using the --force flag. --- lib/svtplay_dl/fetcher/hds.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/svtplay_dl/fetcher/hds.py b/lib/svtplay_dl/fetcher/hds.py index dfc40b8..3656814 100644 --- a/lib/svtplay_dl/fetcher/hds.py +++ b/lib/svtplay_dl/fetcher/hds.py @@ -12,6 +12,7 @@ import xml.etree.ElementTree as ET from svtplay_dl.output import progressbar, progress_stream, ETA from svtplay_dl.utils import get_http_data, select_quality, is_py2_old, is_py2, is_py3 +from svtplay_dl.error import UIException log = logging.getLogger('svtplay_dl') @@ -28,12 +29,27 @@ if is_py3: def _chr(temp): return chr(temp) +class HDSException(UIException): + def __init__(self, url, message): + self.url = url + super(HDSException, self).__init__(message) + + +class LiveHDSException(HDSException): + def __init__(self, url): + super(LiveHDSException, self).__init__( + url, "This is a live HDS stream, and they are not supported.") + + def download_hds(options, url): data = get_http_data(url) streams = {} bootstrap = {} xml = ET.XML(data) + if options.live and not options.force: + raise LiveHDSException(url) + if is_py2_old: bootstrapIter = xml.getiterator("{http://ns.adobe.com/f4m/1.0}bootstrapInfo") mediaIter = xml.getiterator("{http://ns.adobe.com/f4m/1.0}media") From f6950633075ea336af68a5a08857dffd17ffbc96 Mon Sep 17 00:00:00 2001 From: Olof Johansson Date: Tue, 11 Feb 2014 18:29:20 +0100 Subject: [PATCH 4/4] Reraise UIExceptions when called with --verbose --- lib/svtplay_dl/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/svtplay_dl/__init__.py b/lib/svtplay_dl/__init__.py index 50caff3..bcb76b0 100644 --- a/lib/svtplay_dl/__init__.py +++ b/lib/svtplay_dl/__init__.py @@ -77,6 +77,8 @@ def get_media(url, options): try: stream.get(options) except UIException as e: + if options.verbose: + raise e log.error(e.message) sys.exit(2)