X-Git-Url: https://code.delx.au/webdl/blobdiff_plain/a8c4bbb32465ac02fbc0b32b09c7dcdf1e9342ab..c79961c5fd06ddf7cc7ab5d7ee1e8fc8a464a8f1:/common.py diff --git a/common.py b/common.py index 58f54e1..74e8a9d 100644 --- a/common.py +++ b/common.py @@ -68,8 +68,8 @@ def load_root_node(): import sbs sbs.fill_nodes(root_node) - import brightcove - brightcove.fill_nodes(root_node) + import ten + ten.fill_nodes(root_node) return root_node @@ -100,7 +100,7 @@ def grab_html(url): logging.debug("grab_html(%r)", url) request = http_session.prepare_request(requests.Request("GET", url)) response = http_session.send(request, stream=True) - doc = lxml.html.parse(io.StringIO(response.text), lxml.html.HTMLParser(encoding="utf-8", recover=True)) + doc = lxml.html.parse(io.BytesIO(response.content), lxml.html.HTMLParser(encoding="utf-8", recover=True)) response.close() return doc @@ -108,7 +108,7 @@ def grab_xml(url): logging.debug("grab_xml(%r)", url) request = http_session.prepare_request(requests.Request("GET", url)) response = http_session.send(request, stream=True) - doc = lxml.etree.parse(io.StringIO(response.text), lxml.etree.XMLParser(encoding="utf-8", recover=True)) + doc = lxml.etree.parse(io.BytesIO(response.content), lxml.etree.XMLParser(encoding="utf-8", recover=True)) response.close() return doc @@ -162,6 +162,13 @@ def find_ffprobe(): raise Exception("You must install ffmpeg or libav-tools") +def find_streamlink(): + for streamlink in ["streamlink", "livestreamer"]: + if check_command_exists([streamlink, "--help"]): + return streamlink + + raise Exception("You must install streamlink or livestreamer") + def get_duration(filename): ffprobe = find_ffprobe() @@ -233,6 +240,8 @@ def convert_to_mp4(filename): def download_hds(filename, video_url, pvswf=None): + streamlink = find_streamlink() + filename = sanify_filename(filename) logging.info("Downloading: %s", filename) @@ -243,7 +252,7 @@ def download_hds(filename, video_url, pvswf=None): param = video_url cmd = [ - "livestreamer", + streamlink, "-f", "-o", filename, param, @@ -255,12 +264,14 @@ def download_hds(filename, video_url, pvswf=None): return False def download_hls(filename, video_url): + streamlink = find_streamlink() + filename = sanify_filename(filename) video_url = "hlsvariant://" + video_url logging.info("Downloading: %s", filename) cmd = [ - "livestreamer", + streamlink, "-f", "-o", filename, video_url,