]> code.delx.au - webdl/blobdiff - common.py
Switch to streamlink
[webdl] / common.py
index 18460f90da696bdccbc404240d2540cf5507d6a2..74e8a9d3e72b9fff4c3054eaaba35b367da43f47 100644 (file)
--- a/common.py
+++ b/common.py
@@ -1,4 +1,5 @@
 import hashlib
+import io
 import json
 import logging
 import lxml.etree
@@ -67,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
 
@@ -99,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(response.raw, 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
 
@@ -107,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(response.raw, 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
 
@@ -161,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()
 
@@ -202,6 +210,7 @@ def remux(infile, outfile):
         "-bsf:a", "aac_adtstoasc",
         "-acodec", "copy",
         "-vcodec", "copy",
+        "-y",
         outfile,
     ]
     if not exec_subprocess(cmd):
@@ -231,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)
 
@@ -241,7 +252,8 @@ def download_hds(filename, video_url, pvswf=None):
         param = video_url
 
     cmd = [
-        "livestreamer",
+        streamlink,
+        "-f",
         "-o", filename,
         param,
         "best",
@@ -252,12 +264,15 @@ 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,
         "best",