def get(self, options, url): data = get_http_data(url) match = re.search(r'data-media="(.*manifest.f4m)"', data) manifest_url = match.group(1) if options.hls: manifest_url = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8") download_hls(options, manifest_url) else: manifest_url = "%s?hdcore=2.8.0&g=hejsan" % manifest_url download_hds(options, manifest_url)
def get(self, options, url): if re.findall("svt.se", url): data = get_http_data(url) match = re.search("data-json-href=\"(.*)\"", data) if match: filename = match.group(1).replace("&", "&").replace("&format=json", "") url = "http://www.svt.se%s" % filename else: log.error("Can't find video file") sys.exit(2) url = "%s?type=embed" % url data = get_http_data(url) match = re.search("value=\"(/(public)?(statiskt)?/swf/video/svtplayer-[0-9\.]+swf)\"", data) swf = "http://www.svtplay.se%s" % match.group(1) options.other = "-W %s" % swf url = "%s&output=json&format=json" % url data = json.loads(get_http_data(url)) options.live = data["video"]["live"] streams = {} streams2 = {} #hack.. for i in data["video"]["videoReferences"]: if options.hls and i["playerType"] == "ios": stream = {} stream["url"] = i["url"] streams[int(i["bitrate"])] = stream elif not options.hls and i["playerType"] == "flash": stream = {} stream["url"] = i["url"] streams[int(i["bitrate"])] = stream if options.hls and i["playerType"] == "flash": stream = {} stream["url"] = i["url"] streams2[int(i["bitrate"])] = stream if len(streams) == 0 and options.hls: 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 test["url"][0:4] == "rtmp": download_rtmp(options, test["url"]) elif options.hls: download_hls(options, test["url"]) elif test["url"][len(test["url"])-3:len(test["url"])] == "f4m": match = re.search("\/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, swf) else: download_http(options, test["url"]) if options.subtitle: try: subtitle = data["video"]["subtitleReferences"][0]["url"] except KeyError: sys.exit(1) if len(subtitle) > 0: if options.output != "-": data = get_http_data(subtitle) subtitle_wsrt(options, data)
def get(self, options, url): parse = urlparse(url) if "tv4play.se" in url: try: vid = parse_qs(parse[4])["video_id"][0] except KeyError: log.error("Can't find video file") sys.exit(2) else: match = re.search("-(\d+)$", url) if match: vid = match.group(1) else: data = get_http_data(url) match = re.search("\"vid\":\"(\d+)\",", data) if match: vid = match.group(1) else: log.error("Can't find video file") sys.exit(2) url = "http://premium.tv4play.se/api/web/asset/%s/play" % vid data = get_http_data(url) xml = ET.XML(data) ss = xml.find("items") if sys.version_info < (2, 7): sa = list(ss.getiterator("item")) else: sa = list(ss.iter("item")) if xml.find("live").text: if xml.find("live").text != "false": options.live = True streams = {} subtitle = False for i in sa: if i.find("mediaFormat").text != "smi": stream = {} stream["uri"] = i.find("base").text stream["path"] = i.find("url").text streams[int(i.find("bitrate").text)] = stream elif i.find("mediaFormat").text == "smi": subtitle = i.find("url").text if len(streams) == 1: test = streams[list(streams.keys())[0]] else: test = select_quality(options, streams) swf = "http://www.tv4play.se/flash/tv4playflashlets.swf" options.other = "-W %s -y %s" % (swf, test["path"]) if test["uri"][0:4] == "rtmp": download_rtmp(options, test["uri"]) elif test["uri"][len(test["uri"])-3:len(test["uri"])] == "f4m": match = re.search("\/se\/secure\/", test["uri"]) if match: log.error("This stream is encrypted. Use --hls option") sys.exit(2) manifest = "%s?hdcore=2.8.0&g=hejsan" % test["path"] download_hds(options, manifest, swf) if options.subtitle and subtitle: data = get_http_data(subtitle) subtitle_smi(options, data)