mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-27 21:54:17 +01:00
svtplay: convert into new video fetcher
This commit is contained in:
parent
47818019ab
commit
3124e4796e
@ -9,10 +9,10 @@ import xml.etree.ElementTree as ET
|
||||
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
||||
from svtplay_dl.utils import get_http_data, select_quality, subtitle_wsrt
|
||||
from svtplay_dl.utils.urllib import urlparse
|
||||
from svtplay_dl.fetcher.hds import download_hds
|
||||
from svtplay_dl.fetcher.hls import download_hls
|
||||
from svtplay_dl.fetcher.rtmp import download_rtmp
|
||||
from svtplay_dl.fetcher.http import download_http
|
||||
from svtplay_dl.fetcher.hds import HDS
|
||||
from svtplay_dl.fetcher.hls import HLS
|
||||
from svtplay_dl.fetcher.rtmp import RTMP
|
||||
from svtplay_dl.fetcher.http import HTTP
|
||||
|
||||
from svtplay_dl.log import log
|
||||
|
||||
@ -52,64 +52,25 @@ class Svtplay(Service, OpenGraphThumbMixin):
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
streams = {}
|
||||
streams2 = {} #hack..
|
||||
for i in data["video"]["videoReferences"]:
|
||||
parse = urlparse(i["url"])
|
||||
if options.hls and parse.path[len(parse.path)-4:] == "m3u8":
|
||||
stream = {}
|
||||
stream["url"] = i["url"]
|
||||
streams[int(i["bitrate"])] = stream
|
||||
elif not options.hls and parse.path[len(parse.path)-3:] == "f4m":
|
||||
stream = {}
|
||||
stream["url"] = i["url"]
|
||||
streams[int(i["bitrate"])] = stream
|
||||
elif not options.hls and parse.path[len(parse.path)-3:] != "f4m" and parse.path[len(parse.path)-4:] != "m3u8":
|
||||
stream = {}
|
||||
stream["url"] = i["url"]
|
||||
streams[int(i["bitrate"])] = stream
|
||||
if options.hls and parse.path[len(parse.path)-3:] == "f4m":
|
||||
stream = {}
|
||||
stream["url"] = i["url"]
|
||||
streams2[int(i["bitrate"])] = stream
|
||||
|
||||
if len(streams) == 0 and options.hls:
|
||||
if len(streams) == 0:
|
||||
log.error("Can't find any streams.")
|
||||
sys.exit(2)
|
||||
test = streams2[0]
|
||||
test["url"] = test["url"].replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8")
|
||||
elif len(streams) == 0:
|
||||
log.error("Can't find any streams.")
|
||||
sys.exit(2)
|
||||
elif len(streams) == 1:
|
||||
test = streams[list(streams.keys())[0]]
|
||||
else:
|
||||
test = select_quality(options, streams)
|
||||
|
||||
if options.subtitle and options.force_subtitle:
|
||||
return
|
||||
|
||||
parse = urlparse(test["url"])
|
||||
if parse.scheme == "rtmp":
|
||||
embedurl = "%s?type=embed" % url
|
||||
data = get_http_data(embedurl)
|
||||
match = re.search(r"value=\"(/(public)?(statiskt)?/swf(/video)?/svtplayer-[0-9\.a-f]+swf)\"", data)
|
||||
swf = "http://www.svtplay.se%s" % match.group(1)
|
||||
options.other = "-W %s" % swf
|
||||
download_rtmp(options, test["url"])
|
||||
elif options.hls:
|
||||
download_hls(options, test["url"])
|
||||
elif parse.path[len(parse.path)-3:] == "f4m":
|
||||
match = re.search(r"\/se\/secure\/", test["url"])
|
||||
if match:
|
||||
log.error("This stream is encrypted. Use --hls option")
|
||||
sys.exit(2)
|
||||
manifest = "%s?hdcore=2.8.0&g=hejsan" % test["url"]
|
||||
download_hds(options, manifest)
|
||||
else:
|
||||
download_http(options, test["url"])
|
||||
|
||||
if parse.path.find("m3u8") > 0:
|
||||
yield HLS(options, i["url"], i["bitrate"])
|
||||
if parse.path.find("f4m") > 0:
|
||||
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"])
|
||||
if parse.scheme == "rtmp":
|
||||
embedurl = "%s?type=embed" % url
|
||||
data = get_http_data(embedurl)
|
||||
match = re.search(r"value=\"(/(public)?(statiskt)?/swf(/video)?/svtplayer-[0-9\.a-f]+swf)\"", data)
|
||||
swf = "http://www.svtplay.se%s" % match.group(1)
|
||||
options.other = "-W %s" % swf
|
||||
yield RTMP(options, i["url"], i["bitrate"])
|
||||
else:
|
||||
yield HTTP(options, i["url"], "0")
|
||||
|
||||
def get_subtitle(self, options):
|
||||
if self.subtitle:
|
||||
|
Loading…
Reference in New Issue
Block a user