From 305ecf75a826db93959883427d696b1eb7a122ed Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Mon, 21 Apr 2014 21:55:39 +0200 Subject: [PATCH] services: parse hls playlist first. --- lib/svtplay_dl/fetcher/hls.py | 18 +++++++++--------- lib/svtplay_dl/service/dr.py | 6 ++++-- lib/svtplay_dl/service/justin.py | 6 ++++-- lib/svtplay_dl/service/nrk.py | 6 ++++-- lib/svtplay_dl/service/ruv.py | 6 ++++-- lib/svtplay_dl/service/svtplay.py | 6 ++++-- lib/svtplay_dl/service/urplay.py | 10 +++++++--- 7 files changed, 36 insertions(+), 22 deletions(-) diff --git a/lib/svtplay_dl/fetcher/hls.py b/lib/svtplay_dl/fetcher/hls.py index d7b29cb..fb50070 100644 --- a/lib/svtplay_dl/fetcher/hls.py +++ b/lib/svtplay_dl/fetcher/hls.py @@ -41,16 +41,16 @@ def _get_full_url(url, srcurl): return returl +def hlsparse(url): + data = get_http_data(url) + globaldata, files = parsem3u(data) + streams = {} + + for i in files: + streams[i[1]["RESOLUTION"].split("x")[1]] = i[0] + return streams + class HLS(VideoRetriever): - def parse(self): - data = get_http_data(self.url) - globaldata, files = parsem3u(data) - streams = {} - - for i in files: - streams[i[1]["RESOLUTION"].split("x")[1]] = i[0] - return streams - def download(self): if self.options.live and not self.options.force: raise LiveHLSException(self.url) diff --git a/lib/svtplay_dl/service/dr.py b/lib/svtplay_dl/service/dr.py index 99a5292..15305e9 100644 --- a/lib/svtplay_dl/service/dr.py +++ b/lib/svtplay_dl/service/dr.py @@ -8,7 +8,7 @@ import sys from svtplay_dl.service import Service, OpenGraphThumbMixin from svtplay_dl.utils import get_http_data from svtplay_dl.fetcher.rtmp import RTMP -from svtplay_dl.fetcher.hls import HLS +from svtplay_dl.fetcher.hls import HLS, hlsparse from svtplay_dl.log import log class Dr(Service, OpenGraphThumbMixin): @@ -30,7 +30,9 @@ class Dr(Service, OpenGraphThumbMixin): for i in links: if i["Target"] == "Ios": - yield HLS(options, i["Uri"], i["Bitrate"]) + streams = hlsparse(i["Uri"]) + for n in list(streams.keys()): + yield HLS(options, streams[n], n) else: if i["Target"] == "Streaming": options.other = "-y '%s'" % i["Uri"].replace("rtmp://vod.dr.dk/cms/", "") diff --git a/lib/svtplay_dl/service/justin.py b/lib/svtplay_dl/service/justin.py index b2ef64d..d4018fb 100644 --- a/lib/svtplay_dl/service/justin.py +++ b/lib/svtplay_dl/service/justin.py @@ -14,7 +14,7 @@ from svtplay_dl.utils.urllib import urlparse, quote from svtplay_dl.service import Service from svtplay_dl.utils import get_http_data from svtplay_dl.log import log -from svtplay_dl.fetcher.hls import HLS +from svtplay_dl.fetcher.hls import HLS, hlsparse from svtplay_dl.fetcher.http import HTTP class JustinException(Exception): @@ -148,4 +148,6 @@ class Justin(Service): if not options.output: options.output = channel - yield HLS(options, hls_url, 0) + streams = hlsparse(hls_url) + for n in list(streams.keys()): + yield HLS(options, streams[n], n) diff --git a/lib/svtplay_dl/service/nrk.py b/lib/svtplay_dl/service/nrk.py index 4e552e7..4c4e647 100644 --- a/lib/svtplay_dl/service/nrk.py +++ b/lib/svtplay_dl/service/nrk.py @@ -9,7 +9,7 @@ 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.hls import HLS +from svtplay_dl.fetcher.hls import HLS, hlsparse from svtplay_dl.subtitle import subtitle_tt from svtplay_dl.log import log @@ -42,7 +42,9 @@ class Nrk(Service, OpenGraphThumbMixin): options.live = data["isLive"] if options.hls: manifest_url = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8") - yield HLS(options, manifest_url, "0") + streams = hlsparse(manifest_url) + for n in list(streams.keys()): + yield HLS(options, streams[n], n) else: manifest_url = "%s?hdcore=2.8.0&g=hejsan" % manifest_url yield HDS(options, manifest_url, "0") diff --git a/lib/svtplay_dl/service/ruv.py b/lib/svtplay_dl/service/ruv.py index 02ad405..2871694 100644 --- a/lib/svtplay_dl/service/ruv.py +++ b/lib/svtplay_dl/service/ruv.py @@ -5,7 +5,7 @@ import re from svtplay_dl.service import Service from svtplay_dl.utils import get_http_data -from svtplay_dl.fetcher.hls import HLS +from svtplay_dl.fetcher.hls import HLS, hlsparse class Ruv(Service): supported_domains = ['ruv.is'] @@ -18,5 +18,7 @@ class Ruv(Service): tengipunktur = js.split('"')[1] match = re.search(r"http.*tengipunktur [+] '([:]1935.*)'", data) m3u8_url = "http://" + tengipunktur + match.group(1) - yield HLS(options, m3u8_url) + streams = hlsparse(m3u8_url) + for n in list(streams.keys()): + yield HLS(options, streams[n], n) diff --git a/lib/svtplay_dl/service/svtplay.py b/lib/svtplay_dl/service/svtplay.py index 5e2ac40..d40678f 100644 --- a/lib/svtplay_dl/service/svtplay.py +++ b/lib/svtplay_dl/service/svtplay.py @@ -10,7 +10,7 @@ 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.hls import HLS +from svtplay_dl.fetcher.hls import HLS, hlsparse from svtplay_dl.fetcher.rtmp import RTMP from svtplay_dl.fetcher.http import HTTP from svtplay_dl.subtitle import subtitle_wsrt @@ -56,7 +56,9 @@ class Svtplay(Service, OpenGraphThumbMixin): parse = urlparse(i["url"]) if parse.path.find("m3u8") > 0: - yield HLS(options, i["url"], i["bitrate"]) + streams = hlsparse(i["url"]) + for n in list(streams.keys()): + yield HLS(options, streams[n], n) elif parse.path.find("f4m") > 0: match = re.search(r"\/se\/secure\/", i["url"]) if not match: diff --git a/lib/svtplay_dl/service/urplay.py b/lib/svtplay_dl/service/urplay.py index 0ac112a..08ca0cc 100644 --- a/lib/svtplay_dl/service/urplay.py +++ b/lib/svtplay_dl/service/urplay.py @@ -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.fetcher.rtmp import RTMP -from svtplay_dl.fetcher.hls import HLS +from svtplay_dl.fetcher.hls import HLS, hlsparse from svtplay_dl.log import log from svtplay_dl.subtitle import subtitle_tt @@ -41,11 +41,15 @@ class Urplay(Service, OpenGraphThumbMixin): hls = "%s%s" % (http, jsondata["streaming_config"]["http_streaming"]["hls_file"]) rtmp = "rtmp://%s/%s" % (basedomain, jsondata["streaming_config"]["rtmp"]["application"]) path = "mp%s:%s" % (jsondata["file_flash"][-1], jsondata["file_flash"]) - yield HLS(options, hls, "480") + streams = hlsparse(hls) + for n in list(streams.keys()): + yield HLS(options, streams[n], n) options.other = "-v -a %s -y %s" % (jsondata["streaming_config"]["rtmp"]["application"], path) yield RTMP(options, rtmp, "480") if hd: - yield HLS(options, hls_hd, "720") + streams = hlsparse(hls_hd) + for n in list(streams.keys()): + yield HLS(options, streams[n], n) options.other = "-v -a %s -y %s" % (jsondata["streaming_config"]["rtmp"]["application"], path_hd) yield RTMP(options, rtmp, "720")