mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-27 21:54:17 +01:00
Merge pull request #64 from olof/topic/error_on_live_hls
Error out on live hls
This commit is contained in:
commit
693bd84444
@ -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,14 @@ 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:
|
||||
if options.verbose:
|
||||
raise e
|
||||
log.error(e.message)
|
||||
sys.exit(2)
|
||||
|
||||
if options.subtitle:
|
||||
if options.output != "-":
|
||||
stream.get_subtitle(options)
|
||||
@ -87,7 +96,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
|
||||
@ -121,6 +130,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,
|
||||
|
7
lib/svtplay_dl/error.py
Normal file
7
lib/svtplay_dl/error.py
Normal file
@ -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
|
@ -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")
|
||||
|
@ -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]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user