X-Git-Url: https://code.delx.au/webdl/blobdiff_plain/53da2736a1f1d2bd442932ec8e970fd327a785e0..a8c4bbb32465ac02fbc0b32b09c7dcdf1e9342ab:/common.py diff --git a/common.py b/common.py index 43c0e86..58f54e1 100644 --- a/common.py +++ b/common.py @@ -1,4 +1,5 @@ import hashlib +import io import json import logging import lxml.etree @@ -31,6 +32,9 @@ CACHE_FILE = os.path.join( "webdl", "requests_cache" ) +if not os.path.isdir(os.path.dirname(CACHE_FILE)): + os.makedirs(os.path.dirname(CACHE_FILE)) + requests_cache.install_cache(CACHE_FILE, backend='sqlite', expire_after=3600) @@ -96,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.StringIO(response.text), lxml.html.HTMLParser(encoding="utf-8", recover=True)) response.close() return doc @@ -104,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.StringIO(response.text), lxml.etree.XMLParser(encoding="utf-8", recover=True)) response.close() return doc @@ -199,6 +203,7 @@ def remux(infile, outfile): "-bsf:a", "aac_adtstoasc", "-acodec", "copy", "-vcodec", "copy", + "-y", outfile, ] if not exec_subprocess(cmd): @@ -239,6 +244,7 @@ def download_hds(filename, video_url, pvswf=None): cmd = [ "livestreamer", + "-f", "-o", filename, param, "best", @@ -255,6 +261,7 @@ def download_hls(filename, video_url): cmd = [ "livestreamer", + "-f", "-o", filename, video_url, "best",