1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 04:05:39 +01:00

hds: parse and kwargssupport

This commit is contained in:
Johan Andersson 2014-04-27 13:19:34 +02:00
parent 218f61b95d
commit 383c0650d7
3 changed files with 32 additions and 30 deletions

View File

@ -1,5 +1,6 @@
class VideoRetriever:
def __init__(self, options, url, bitrate):
def __init__(self, options, url, bitrate, **kwargs):
self.options = options
self.url = url
self.bitrate = bitrate
self.kwargs = kwargs

View File

@ -41,38 +41,37 @@ class LiveHDSException(HDSException):
super(LiveHDSException, self).__init__(
url, "This is a live HDS stream, and they are not supported.")
def hdsparse(options, manifest):
data = get_http_data(manifest)
streams = {}
bootstrap = {}
xml = ET.XML(data)
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")
else:
bootstrapIter = xml.iter("{http://ns.adobe.com/f4m/1.0}bootstrapInfo")
mediaIter = xml.iter("{http://ns.adobe.com/f4m/1.0}media")
for i in bootstrapIter:
bootstrap[i.attrib["id"]] = i.text
for i in mediaIter:
streams[int(i.attrib["bitrate"])] = HDS(options, i.attrib["url"], i.attrib["bitrate"], manifest=manifest, bootstrap=bootstrap[i.attrib["bootstrapInfoId"]], metadata=i.find("{http://ns.adobe.com/f4m/1.0}metadata").text)
return streams
class HDS(VideoRetriever):
def download(self):
data = get_http_data(self.url)
streams = {}
bootstrap = {}
xml = ET.XML(data)
if self.options.live and not self.options.force:
raise LiveHDSException(self.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")
else:
bootstrapIter = xml.iter("{http://ns.adobe.com/f4m/1.0}bootstrapInfo")
mediaIter = xml.iter("{http://ns.adobe.com/f4m/1.0}media")
for i in bootstrapIter:
bootstrap[i.attrib["id"]] = i.text
for i in mediaIter:
streams[int(i.attrib["bitrate"])] = {"url": i.attrib["url"], "bootstrapInfoId": i.attrib["bootstrapInfoId"], "metadata": i.find("{http://ns.adobe.com/f4m/1.0}metadata").text}
test = select_quality(self.options, streams)
bootstrap = base64.b64decode(bootstrap[test["bootstrapInfoId"]])
bootstrap = base64.b64decode(self.kwargs["bootstrap"])
box = readboxtype(bootstrap, 0)
antal = None
if box[2] == b"abst":
antal = readbox(bootstrap, box[0])
baseurl = self.url[0:self.url.rfind("/")]
baseurl = self.kwargs["manifest"][0:self.kwargs["manifest"].rfind("/")]
i = 1
if self.options.output != "-":
@ -84,16 +83,16 @@ class HDS(VideoRetriever):
else:
file_d = sys.stdout
metasize = struct.pack(">L", len(base64.b64decode(test["metadata"])))[1:]
metasize = struct.pack(">L", len(base64.b64decode(self.kwargs["metadata"])))[1:]
file_d.write(binascii.a2b_hex(b"464c560105000000090000000012"))
file_d.write(metasize)
file_d.write(binascii.a2b_hex(b"00000000000000"))
file_d.write(base64.b64decode(test["metadata"]))
file_d.write(base64.b64decode(self.kwargs["metadata"]))
file_d.write(binascii.a2b_hex(b"00000000"))
total = antal[1]["total"]
eta = ETA(total)
eta = ETA(total)q
while i <= total:
url = "%s/%sSeg1-Frag%s" % (baseurl, test["url"], i)
url = "%s/%sSeg1-Frag%s" % (baseurl, self.url, i)
if self.options.output != "-":
eta.update(i)
progressbar(total, i, ''.join(["ETA: ", str(eta)]))

View File

@ -9,7 +9,7 @@ import xml.etree.ElementTree as ET
from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.utils import get_http_data
from svtplay_dl.utils.urllib import urlparse
from svtplay_dl.fetcher.hds import HDS
from svtplay_dl.fetcher.hds import HDS, hdsparse
from svtplay_dl.fetcher.hls import HLS, hlsparse
from svtplay_dl.fetcher.rtmp import RTMP
from svtplay_dl.fetcher.http import HTTP
@ -63,7 +63,9 @@ class Svtplay(Service, OpenGraphThumbMixin):
match = re.search(r"\/se\/secure\/", i["url"])
if not match:
manifest = "%s?hdcore=2.8.0&g=hejsan" % i["url"]
yield HDS(options, manifest, i["bitrate"])
streams = hdsparse(options, manifest)
for n in list(streams.keys()):
yield streams[n]
elif parse.scheme == "rtmp":
embedurl = "%s?type=embed" % url
data = get_http_data(embedurl)