def get(self): login = self._login() if not login: yield ServiceError("You need to login") return data = self.get_urldata() match = re.search('}}}},("staticPages".*}}); windo', data) if not match: yield ServiceError("Cant find necessary info") return janson = json.loads("{}{}".format("{", match.group(1))) video = None for play in janson["page"]["blocks"]: if "componentName" in play and play["componentName"] == "player": video = play break if not video: yield ServiceError("Can't find video") return self._autoname(video) if "subtitles" in video["_embedded"]["program"] and "subtitlesWebvtt" in video["_embedded"]["program"]["subtitles"]: yield subtitle(copy.copy(self.config), "wrst", video["_embedded"]["program"]["subtitles"]["subtitlesWebvtt"], output=self.output) res = self.http.get(video["_embedded"]["program"]["_links"]["streamLink"]["href"]) janson = res.json() stream = janson["embedded"]["prioritizedStreams"][0]["links"]["stream"] if video["_embedded"]["program"]["_links"]["streamLink"]: streams = hlsparse( self.config, self.http.request("get", stream["href"]), stream["href"], output=self.output, authorization=f"MTG-AT {self.token}", ) for n in list(streams.keys()): yield streams[n] if "subtitles" in janson["embedded"] and len(janson["embedded"]["subtitles"]) > 0: lang = re.search(r"(\.\w\w)$", urlparse(self.url).netloc).group(1) if lang in country: language = country[lang] else: language = None if not self.config.get("get_all_subtitles"): if not language: yield subtitle(copy.copy(self.config), "wrst", janson["embedded"]["subtitles"][0]["link"]["href"], output=self.output) else: for i in janson["embedded"]["subtitles"]: if i["data"]["language"] == language: yield subtitle(copy.copy(self.config), "wrst", i["link"]["href"], output=self.output) else: for i in janson["embedded"]["subtitles"]: yield subtitle(copy.copy(self.config), "wrst", i["link"]["href"], i["data"]["language"], output=copy.copy(self.output))
def get(self): key = "currentProduct" match = re.search(r'/Player/Player" data-react-props="([^\"]+)\"', self.get_urldata()) if not match: key = "program" match = re.search( r'/ProgramContainer" data-react-props="([^\"]+)\"', self.get_urldata()) if not match: yield ServiceError("Can't find json info") return data = unescape(match.group(1)) jsondata = json.loads(data) res = self.http.get( "https://streaming-loadbalancer.ur.se/loadbalancer.json") loadbalancer = res.json()["redirect"] for streaminfo in jsondata[key]["streamingInfo"].keys(): stream = jsondata[key]["streamingInfo"][streaminfo] if streaminfo == "raw": if "sd" in stream: url = "https://{}/{}playlist.m3u8".format( loadbalancer, stream["sd"]["location"]) streams = hlsparse(self.config, self.http.request("get", url), url, output=self.output) for n in list(streams.keys()): yield streams[n] if "hd" in stream: url = "https://{}/{}playlist.m3u8".format( loadbalancer, stream["hd"]["location"]) streams = hlsparse(self.config, self.http.request("get", url), url, output=self.output) for n in list(streams.keys()): yield streams[n] if not (self.config.get("get_all_subtitles")) and ( stream["default"]): yield subtitle(copy.copy(self.config), "tt", stream["tt"]["location"], output=self.output) if self.config.get("get_all_subtitles") and "tt" in stream: label = stream["tt"]["language"] if stream["tt"]["scope"] != "complete": label = "{}-{}".format(label, stream["tt"]["scope"]) yield subtitle(copy.copy(self.config), "tt", stream["tt"]["location"], label, output=copy.copy(self.output))
def get(self): data = self.get_urldata() match = re.search(r"urPlayer.init\((.*)\);", data) if not match: yield ServiceError("Can't find json info") return if self.exclude(): yield ServiceError("Excluding video") return data = match.group(1) jsondata = json.loads(data) if len(jsondata["subtitles"]) > 0: for sub in jsondata["subtitles"]: if "label" in sub: absurl = urljoin(self.url, sub["file"].split(",")[0]) if absurl.endswith("vtt"): subtype = "wrst" else: subtype = "tt" if self.options.get_all_subtitles: yield subtitle(copy.copy(self.options), subtype, absurl, "-" + filenamify(sub["label"])) else: yield subtitle(copy.copy(self.options), subtype, absurl) if "streamer" in jsondata["streaming_config"]: basedomain = jsondata["streaming_config"]["streamer"]["redirect"] else: url = jsondata["streaming_config"]["loadbalancer"] if url[:1] == "/": url = "https:{}".format(url) lbjson = self.http.request("get", url).text lbjson = json.loads(lbjson) basedomain = lbjson["redirect"] http = "https://{0}/{1}".format(basedomain, jsondata["file_http"]) hd = None if len(jsondata["file_http_hd"]) > 0: http_hd = "https://{0}/{1}".format(basedomain, jsondata["file_http_hd"]) hls_hd = "{0}{1}".format( http_hd, jsondata["streaming_config"]["http_streaming"]["hls_file"]) hd = True hls = "{0}{1}".format( http, jsondata["streaming_config"]["http_streaming"]["hls_file"]) streams = hlsparse(self.options, self.http.request("get", hls), hls) for n in list(streams.keys()): yield streams[n] if hd: streams = hlsparse(self.options, self.http.request("get", hls_hd), hls_hd) for n in list(streams.keys()): yield streams[n]
def get(self): data = self.get_urldata() match = re.search(r"urPlayer.init\((.*)\);", data) if not match: yield ServiceError("Can't find json info") return if self.exclude(): yield ServiceError("Excluding video") return data = match.group(1) jsondata = json.loads(data) if len(jsondata["subtitles"]) > 0: for sub in jsondata["subtitles"]: if "label" in sub: absurl = urljoin(self.url, sub["file"].split(",")[0]) if absurl.endswith("vtt"): subtype = "wrst" else: subtype = "tt" if self.options.get_all_subtitles: yield subtitle(copy.copy(self.options), subtype, absurl, "-" + filenamify(sub["label"])) else: yield subtitle(copy.copy(self.options), subtype, absurl) if "streamer" in jsondata["streaming_config"]: basedomain = jsondata["streaming_config"]["streamer"]["redirect"] else: url = jsondata["streaming_config"]["loadbalancer"] if url[:1] == "/": url = "https:{}".format(url) lbjson = self.http.request("get", url).text lbjson = json.loads(lbjson) basedomain = lbjson["redirect"] http = "https://{0}/{1}".format(basedomain, jsondata["file_http"]) hd = None if len(jsondata["file_http_hd"]) > 0: http_hd = "https://{0}/{1}".format(basedomain, jsondata["file_http_hd"]) hls_hd = "{0}{1}".format(http_hd, jsondata["streaming_config"]["http_streaming"]["hls_file"]) hd = True hls = "{0}{1}".format(http, jsondata["streaming_config"]["http_streaming"]["hls_file"]) streams = hlsparse(self.options, self.http.request("get", hls), hls) for n in list(streams.keys()): yield streams[n] if hd: streams = hlsparse(self.options, self.http.request("get", hls_hd), hls_hd) for n in list(streams.keys()): yield streams[n]
def get(self): data = self.get_urldata() match = re.search(r"urPlayer.init\((.*)\);", data) if not match: yield ServiceError("Can't find json info") return if self.exclude(): yield ServiceError("Excluding video") return data = match.group(1) jsondata = json.loads(data) if len(jsondata["subtitles"]) > 0: for sub in jsondata["subtitles"]: if "label" in sub: if self.options.get_all_subtitles: yield subtitle(copy.copy(self.options), "tt", sub["file"].split(",")[0], "-" + filenamify(sub["label"])) else: yield subtitle(copy.copy(self.options), "tt", sub["file"].split(",")[0]) if "streamer" in jsondata["streaming_config"]: basedomain = jsondata["streaming_config"]["streamer"]["redirect"] else: lbjson = self.http.request( "get", jsondata["streaming_config"]["loadbalancer"]).text lbjson = json.loads(lbjson) basedomain = lbjson["redirect"] http = "http://%s/%s" % (basedomain, jsondata["file_http"]) hd = None if len(jsondata["file_http_hd"]) > 0: http_hd = "http://%s/%s" % (basedomain, jsondata["file_http_hd"]) hls_hd = "%s%s" % (http_hd, jsondata["streaming_config"] ["http_streaming"]["hls_file"]) hd = True hls = "%s%s" % ( http, jsondata["streaming_config"]["http_streaming"]["hls_file"]) streams = hlsparse(self.options, self.http.request("get", hls), hls) for n in list(streams.keys()): yield streams[n] if hd: streams = hlsparse(self.options, self.http.request("get", hls_hd), hls_hd) for n in list(streams.keys()): yield streams[n]
def get(self): data = self.get_urldata() match = re.search("n.reduxState=(.*);", data) if not match: match = re.search(r"stateData = JSON.parse\(\"(.*)\"\)\<\/script", data) if not match: yield ServiceError("Cant find video info.") return janson = json.loads(codecs.escape_decode(match.group(1))[0].decode("utf-8")) if janson["recipe"]["content"]["data"]["videoClips"]: vid = janson["recipe"]["content"]["data"]["videoClips"][0]["id"] else: vid = janson["recipe"]["content"]["data"]["videoEpisodes"][0]["id"] res = self.http.get(f"https://api.svt.se/videoplayer-api/video/{vid}") else: janson = json.loads(match.group(1)) vid = janson["areaData"]["articles"][list(janson["areaData"]["articles"].keys())[0]]["media"][0]["image"]["svtId"] res = self.http.get(f"https://api.svt.se/video/{vid}") janson = res.json() if "subtitleReferences" in janson: for i in janson["subtitleReferences"]: if i["format"] == "websrt" and "url" in i: yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output) videos = self._get_video(janson) yield from videos
def get(self): data = self.get_urldata() match = re.search(r"urPlayer.init\((.*)\);", data) if not match: yield ServiceError("Can't find json info") return if self.exclude(self.options): yield ServiceError("Excluding video") return data = match.group(1) jsondata = json.loads(data) if len(jsondata["subtitles"]) > 0: yield subtitle(copy.copy(self.options), "tt", jsondata["subtitles"][0]["file"].split(",")[0]) if "streamer" in jsondata["streaming_config"]: basedomain = jsondata["streaming_config"]["streamer"]["redirect"] else: lbjson = self.http.request("get", jsondata["streaming_config"]["loadbalancer"]).text lbjson = json.loads(lbjson) basedomain = lbjson["redirect"] http = "http://%s/%s" % (basedomain, jsondata["file_http"]) hd = None if len(jsondata["file_http_hd"]) > 0: http_hd = "http://%s/%s" % (basedomain, jsondata["file_http_hd"]) hls_hd = "%s%s" % (http_hd, jsondata["streaming_config"]["http_streaming"]["hls_file"]) hd = True hls = "%s%s" % (http, jsondata["streaming_config"]["http_streaming"]["hls_file"]) streams = hlsparse(self.options, self.http.request("get", hls), hls) for n in list(streams.keys()): yield streams[n] if hd: streams = hlsparse(self.options, self.http.request("get", hls_hd), hls_hd) for n in list(streams.keys()): yield streams[n]
def _get_video(self, janson): if "subtitleReferences" in janson: for i in janson["subtitleReferences"]: if i["format"] == "websrt" and "url" in i: yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output) if "videoReferences" in janson: if len(janson["videoReferences"]) == 0: yield ServiceError("Media doesn't have any associated videos.") return for i in janson["videoReferences"]: streams = None alt_streams = None alt = None query = parse_qs(urlparse(i["url"]).query) if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if i["format"] == "hls": streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output) if alt: alt_streams = hlsparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output) elif i["format"] == "dash264" or i["format"] == "dashhbbtv": streams = dashparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output) if alt: alt_streams = dashparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output) if streams: for n in list(streams.keys()): yield streams[n] if alt_streams: for n in list(alt_streams.keys()): yield alt_streams[n]
def get(self): if self.exclude(): yield ServiceError("Excluding video") return match = re.search('iframe src="(/embed/[^"]+)"', self.get_urldata()) if not match: yield ServiceError("Cant find video") return parse = urlparse(self.url) url = "{0}://{1}{2}".format(parse.scheme, parse.netloc, match.group(1)) data = self.http.get(url) match = re.search('src="([^"]+vtt)"', data.text) if match: yield subtitle(copy.copy(self.options), "wrst", match.group(1)) match = re.search('source src="([^"]+)" type="application/x-mpegURL"', data.text) if not match: yield ServiceError("Cant find video file") return streams = hlsparse(self.options, self.http.request("get", match.group(1)), match.group(1)) for n in list(streams.keys()): yield streams[n]
def get(self): if not self.config.get("username") or not self.config.get("password"): yield ServiceError( "You need username and password to download things from this site." ) return token, message = self._login() if not token: yield ServiceError(message) return res = self.http.get(self.url) match = re.search('data-asset-id="([^"]+)"', res.text) if not match: yield ServiceError("Can't find video id") return tld = self._gettld() url = "https://restapi.cmore.{0}/api/tve_web/asset/{1}/play.json?protocol=VUDASH".format( tld, match.group(1)) res = self.http.get( url, headers={"authorization": "Bearer {0}".format(token)}) janson = res.json() if "error" in janson: yield ServiceError("This video is geoblocked") return basename = self._autoname(match.group(1)) self.output["id"] = match.group(1) if basename is None: yield ServiceError("Cant find vid id for autonaming") return if "drmProtected" in janson["playback"]: if janson["playback"]["drmProtected"]: yield ServiceError("DRM protected. Can't do anything") return if isinstance(janson["playback"]["items"]["item"], list): for i in janson["playback"]["items"]["item"]: if i["mediaFormat"] == "ism": streams = dashparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output) if streams: for n in list(streams.keys()): yield streams[n] if i["mediaFormat"] == "webvtt": yield subtitle(copy.copy(self.config), "wrst", i["url"]) else: i = janson["playback"]["items"]["item"] if i["mediaFormat"] == "ism": streams = dashparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output) for n in list(streams.keys()): yield streams[n]
def get(self): data = self.get_urldata() match = re.search(r'resource:[ ]*"([^"]*)",', data) if match: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).content resource = json.loads(resource_data) streams = self.find_stream(self.config, resource) yield from streams else: match = re.search(r'resource="([^"]*)"', data) if not match: yield ServiceError("Cant find resource info for this video") return if match.group(1)[:4] != "http": resource_url = "http:{}".format(match.group(1)) else: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).text resource = json.loads(resource_data) if "Links" not in resource: yield ServiceError("Cant access this video. its geoblocked.") return if "SubtitlesList" in resource and len( resource["SubtitlesList"]) > 0: suburl = resource["SubtitlesList"][0]["Uri"] yield subtitle(copy.copy(self.config), "wrst", suburl, output=self.output) if "Data" in resource: streams = self.find_stream(self.config, resource) yield from streams else: for stream in resource["Links"]: uri = stream["Uri"] if uri is None: uri = self._decrypt(stream["EncryptedUri"]) if stream["Target"] == "HDS": streams = hdsparse(copy.copy(self.config), self.http.request( "get", uri, params={"hdcore": "3.7.0"}), uri, output=self.output) if streams: for n in list(streams.keys()): yield streams[n] if stream["Target"] == "HLS": streams = hlsparse(self.config, self.http.request("get", uri), uri, output=self.output) for n in list(streams.keys()): yield streams[n]
def hlsparse(options, res, url, **kwargs): streams = {} if not res: return None if res.status_code > 400: streams[0] = ServiceError("Can't read HLS playlist. {0}".format(res.status_code)) return streams m3u8 = M3U8(res.text) keycookie = kwargs.pop("keycookie", None) authorization = kwargs.pop("authorization", None) httpobject = kwargs.pop("httpobject", None) media = {} segments = None if m3u8.master_playlist: for i in m3u8.master_playlist: audio_url = None subtitle_url = None if i["TAG"] == "EXT-X-MEDIA": if "AUTOSELECT" in i and (i["AUTOSELECT"].upper() == "YES"): if i["TYPE"]: if "URI" in i: if segments is None: segments = True if i["GROUP-ID"] not in media: media[i["GROUP-ID"]] = [] media[i["GROUP-ID"]].append(i["URI"]) else: segments = False continue elif i["TAG"] == "EXT-X-STREAM-INF": bit_rate = float(i["BANDWIDTH"]) / 1000 if "AUDIO" in i and (i["AUDIO"] in media): audio_url = _get_full_url(media[i["AUDIO"]][0], url) if "SUBTITLES" in i and (i["SUBTITLES"] in media): subtitle_url = _get_full_url(media[i["SUBTITLES"]][0], url) urls = _get_full_url(i["URI"], url) else: continue # Needs to be changed to utilise other tags. options.segments = bool(segments) if subtitle_url and httpobject: m3u8s = M3U8(httpobject.request("get", subtitle_url, cookies=res.cookies).text) streams[1] = subtitle(copy.copy(options), "wrst", _get_full_url(m3u8s.media_segment[0]["URI"], url)) streams[int(bit_rate)] = HLS(copy.copy(options), urls, bit_rate, cookies=res.cookies, keycookie=keycookie, authorization=authorization, audio=audio_url) elif m3u8.media_segment: options.segments = False streams[0] = HLS(copy.copy(options), url, 0, cookies=res.cookies, keycookie=keycookie, authorization=authorization) else: streams[0] = ServiceError("Can't find HLS playlist in m3u8 file.") return streams
def hlsparse(options, res, url, **kwargs): streams = {} if not res: return None if res.status_code > 400: streams[0] = ServiceError("Can't read HLS playlist. {0}".format(res.status_code)) return streams m3u8 = M3U8(res.text) keycookie = kwargs.pop("keycookie", None) authorization = kwargs.pop("authorization", None) httpobject = kwargs.pop("httpobject", None) media = {} segments = None if m3u8.master_playlist: for i in m3u8.master_playlist: audio_url = None subtitle_url = None if i["TAG"] == "EXT-X-MEDIA": if "AUTOSELECT" in i and (i["AUTOSELECT"].upper() == "YES"): if i["TYPE"]: if "URI" in i: if segments is None: segments = True if i["GROUP-ID"] not in media: media[i["GROUP-ID"]] = [] media[i["GROUP-ID"]].append(i["URI"]) else: segments = False continue elif i["TAG"] == "EXT-X-STREAM-INF": bit_rate = float(i["BANDWIDTH"]) / 1000 if "AUDIO" in i and (i["AUDIO"] in media): audio_url = _get_full_url(media[i["AUDIO"]][0], url) if "SUBTITLES" in i and (i["SUBTITLES"] in media): subtitle_url = _get_full_url(media[i["SUBTITLES"]][0], url) urls = _get_full_url(i["URI"], url) else: continue # Needs to be changed to utilise other tags. options.segments = bool(segments) if subtitle_url and httpobject: m3u8s = M3U8(httpobject.request("get", subtitle_url, cookies=res.cookies).text) streams[1] = subtitle(copy.copy(options), "wrst", _get_full_url(m3u8s.media_segment[0]["URI"], url)) streams[int(bit_rate)] = HLS(copy.copy(options), urls, bit_rate, cookies=res.cookies, keycookie=keycookie, authorization=authorization, audio=audio_url) elif m3u8.media_segment: streams[0] = HLS(copy.copy(options), url, 0, cookies=res.cookies, keycookie=keycookie, authorization=authorization) else: streams[0] = ServiceError("Can't find HLS playlist in m3u8 file.") return streams
def _get_video(self, janson): if "live" in janson: self.options.live = janson["live"] if "subtitleReferences" in janson: for i in janson["subtitleReferences"]: if i["format"] == "websrt" and "url" in i: yield subtitle(copy.copy(self.options), "wrst", i["url"]) if "videoReferences" in janson: if len(janson["videoReferences"]) == 0: yield ServiceError("Media doesn't have any associated videos (yet?)") return for i in janson["videoReferences"]: parse = urlparse(i["url"]) query = parse_qs(parse.query) if i["format"] == "hls": streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = hlsparse(self.options, self.http.request("get", alt.request.url), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n] if i["format"] == "hds": match = re.search(r"\/se\/secure\/", i["url"]) if not match: streams = hdsparse(self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = hdsparse(self.options, self.http.request("get", alt.request.url, params={"hdcore": "3.7.0"}), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n] if i["format"] == "dash264" or i["format"] == "dashhbbtv": streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = dashparse(self.options, self.http.request("get", alt.request.url), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): data = self.get_urldata() match = re.search("__data = ([^<]+)</script>", data) if not match: yield ServiceError("Cant find info for this video") return janson = json.loads(match.group(1)) page = janson["cache"]["page"][list(janson["cache"]["page"].keys())[0]] offers = page["entries"][0]["item"]["offers"] resolution = None vid = None for i in offers: if i["deliveryType"] == "Stream": vid = i["scopes"][0] resolution = i["resolution"] deviceid = uuid.uuid1() res = self.http.request( "post", "https://isl.dr-massive.com/api/authorization/anonymous-sso?device=web_browser&ff=idp%2Cldp&lang=da", json={ "deviceId": str(deviceid), "scopes": ["Catalog"], "optout": True }, ) token = res.json()[0]["value"] url = "https://isl.dr-massive.com/api/account/items/{}/videos?delivery=stream&device=web_browser&ff=idp%2Cldp&lang=da&resolution={}&sub=Anonymous".format( vid, resolution, ) res = self.http.request("get", url, headers={"authorization": f"Bearer {token}"}) for video in res.json(): if video["accessService"] == "StandardVideo": if video["format"] == "video/hls": res = self.http.request("get", video["url"]) if res.status_code > 400: yield ServiceError( "Can't play this because the video is geoblocked or not available." ) else: streams = hlsparse(self.config, res, video["url"], output=self.output) for n in list(streams.keys()): yield streams[n] yield subtitle(copy.copy(self.config), "wrst", video["subtitles"][0]["link"], output=self.output)
def get(self, options): error, data = self.get_urldata() if error: log.error("Can't download page.") return if self.exclude(options): return match = re.search(r'resource:[ ]*"([^"]*)",', data) if match: resource_url = match.group(1) error, resource_data = get_http_data(resource_url) if error: log.error("Can't get resource data") return resource = json.loads(resource_data) streams = find_stream(options, resource) for i in streams: yield i else: match = re.search(r'resource="([^"]*)"', data) if not match: log.error("Cant find resource info for this video") return resource_url = "%s" % match.group(1) error, resource_data = get_http_data(resource_url) if error: log.error("Can't get resource data") return resource = json.loads(resource_data) if "SubtitlesList" in resource: suburl = resource["SubtitlesList"][0]["Uri"] yield subtitle(copy.copy(options), "wrst", suburl) if "Data" in resource: streams = find_stream(options, resource) for i in streams: yield i else: for stream in resource['Links']: if stream["Target"] == "HDS": streams = hdsparse(copy.copy(options), stream["Uri"]) if streams: for n in list(streams.keys()): yield streams[n] if stream["Target"] == "HLS": streams = hlsparse(stream["Uri"]) for n in list(streams.keys()): yield HLS(copy.copy(options), streams[n], n) if stream["Target"] == "Streaming": options.other = "-v -y '%s'" % stream['Uri'].replace("rtmp://vod.dr.dk/cms/", "") rtmp = "rtmp://vod.dr.dk/cms/" yield RTMP(copy.copy(options), rtmp, stream['Bitrate'])
def get(self, options): data = self.get_urldata() if self.exclude(options): yield ServiceError("Excluding video") return match = re.search(r'resource:[ ]*"([^"]*)",', data) if match: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).content resource = json.loads(resource_data) streams = self.find_stream(options, resource) for i in streams: yield i else: match = re.search(r'resource="([^"]*)"', data) if not match: yield ServiceError("Cant find resource info for this video") return if match.group(1)[:4] != "http": resource_url = "http:%s" % match.group(1) else: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).text resource = json.loads(resource_data) if "Links" not in resource: yield ServiceError("Cant access this video. its geoblocked.") return if "SubtitlesList" in resource: suburl = resource["SubtitlesList"][0]["Uri"] yield subtitle(copy.copy(options), "wrst", suburl) if "Data" in resource: streams = self.find_stream(options, resource) for i in streams: yield i else: for stream in resource['Links']: if stream["Target"] == "HDS": streams = hdsparse(copy.copy(options), self.http.request("get", stream["Uri"], params={"hdcore": "3.7.0"}), stream["Uri"]) if streams: for n in list(streams.keys()): yield streams[n] if stream["Target"] == "HLS": streams = hlsparse(options, self.http.request("get", stream["Uri"]), stream["Uri"]) for n in list(streams.keys()): yield streams[n] if stream["Target"] == "Streaming": options.other = "-v -y '%s'" % stream['Uri'].replace("rtmp://vod.dr.dk/cms/", "") rtmp = "rtmp://vod.dr.dk/cms/" yield RTMP(copy.copy(options), rtmp, stream['Bitrate'])
def get(self): data = self.get_urldata() if self.exclude(): yield ServiceError("Excluding video") return match = re.search(r'resource:[ ]*"([^"]*)",', data) if match: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).content resource = json.loads(resource_data) streams = self.find_stream(self.options, resource) for i in streams: yield i else: match = re.search(r'resource="([^"]*)"', data) if not match: yield ServiceError("Cant find resource info for this video") return if match.group(1)[:4] != "http": resource_url = "http:{0}".format(match.group(1)) else: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).text resource = json.loads(resource_data) if "Links" not in resource: yield ServiceError("Cant access this video. its geoblocked.") return if "SubtitlesList" in resource and len(resource["SubtitlesList"]) > 0: suburl = resource["SubtitlesList"][0]["Uri"] yield subtitle(copy.copy(self.options), "wrst", suburl) if "Data" in resource: streams = self.find_stream(self.options, resource) for i in streams: yield i else: for stream in resource['Links']: if stream["Target"] == "HDS": streams = hdsparse(copy.copy(self.options), self.http.request("get", stream["Uri"], params={"hdcore": "3.7.0"}), stream["Uri"]) if streams: for n in list(streams.keys()): yield streams[n] if stream["Target"] == "HLS": streams = hlsparse(self.options, self.http.request("get", stream["Uri"]), stream["Uri"]) for n in list(streams.keys()): yield streams[n] if stream["Target"] == "Streaming": self.options.other = "-v -y '{0}'".format(stream['Uri'].replace("rtmp://vod.dr.dk/cms/", "")) rtmp = "rtmp://vod.dr.dk/cms/" yield RTMP(copy.copy(self.options), rtmp, stream['Bitrate'])
def get(self): if self.exclude(): yield ServiceError("Excluding video") return # First, fint the video ID from the html document match = re.search("programId: \"([^\"]+)\"", self.get_urldata()) if match: video_id = match.group(1) else: yield ServiceError("Can't find video id.") return # Get media element details match = re.search("apiBaseUrl: '([^']+)'", self.get_urldata()) if not match: yield ServiceError("Cant find apiurl.") return dataurl = "{0}/mediaelement/{1}".format(match.group(1), video_id) data = self.http.request("get", dataurl).text data = json.loads(data) manifest_url = data["mediaUrl"] self.options.live = data["isLive"] if manifest_url is None: yield ServiceError(data["messageType"]) return # Check if subtitles are available if data["subtitlesUrlPath"]: yield subtitle(copy.copy(self.options), "tt", data["subtitlesUrlPath"]) hlsurl = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8") data = self.http.request("get", hlsurl) if data.status_code == 403: yield ServiceError("Can't fetch the video because of geoblocking") return streams = hlsparse(self.options, data, hlsurl) if streams: for n in list(streams.keys()): yield streams[n] streams = hdsparse( copy.copy(self.options), self.http.request("get", manifest_url, params={"hdcore": "3.7.0"}), manifest_url) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): data = self.get_urldata() match = re.search(r'resource:[ ]*"([^"]*)",', data) if match: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).content resource = json.loads(resource_data) streams = self.find_stream(self.config, resource) for i in streams: yield i else: match = re.search(r'resource="([^"]*)"', data) if not match: yield ServiceError("Cant find resource info for this video") return if match.group(1)[:4] != "http": resource_url = "http:{0}".format(match.group(1)) else: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).text resource = json.loads(resource_data) if "Links" not in resource: yield ServiceError("Cant access this video. its geoblocked.") return if "SubtitlesList" in resource and len(resource["SubtitlesList"]) > 0: suburl = resource["SubtitlesList"][0]["Uri"] yield subtitle(copy.copy(self.config), "wrst", suburl, output=self.output) if "Data" in resource: streams = self.find_stream(self.config, resource) for i in streams: yield i else: for stream in resource['Links']: uri = stream["Uri"] if uri is None: uri = self._decrypt(stream["EncryptedUri"]) if stream["Target"] == "HDS": streams = hdsparse(copy.copy(self.config), self.http.request("get", uri, params={"hdcore": "3.7.0"}), uri, output=self.output) if streams: for n in list(streams.keys()): yield streams[n] if stream["Target"] == "HLS": streams = hlsparse(self.config, self.http.request("get", uri), uri, output=self.output) for n in list(streams.keys()): yield streams[n]
def get(self): data = self.get_urldata() match = re.search(r'resource:[ ]*"([^"]*)",', data) if match: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).content resource = json.loads(resource_data) streams = self.find_stream(self.config, resource) for i in streams: yield i else: match = re.search(r'resource="([^"]*)"', data) if not match: yield ServiceError("Cant find resource info for this video") return if match.group(1)[:4] != "http": resource_url = "http:{0}".format(match.group(1)) else: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).text resource = json.loads(resource_data) if "Links" not in resource: yield ServiceError("Cant access this video. its geoblocked.") return if "SubtitlesList" in resource and len(resource["SubtitlesList"]) > 0: suburl = resource["SubtitlesList"][0]["Uri"] yield subtitle(copy.copy(self.config), "wrst", suburl, output=self.output) if "Data" in resource: streams = self.find_stream(self.config, resource) for i in streams: yield i else: for stream in resource['Links']: if stream["Target"] == "HDS": streams = hdsparse(copy.copy(self.config), self.http.request("get", stream["Uri"], params={"hdcore": "3.7.0"}), stream["Uri"], output=self.output) if streams: for n in list(streams.keys()): yield streams[n] if stream["Target"] == "HLS": streams = hlsparse(self.config, self.http.request("get", stream["Uri"]), stream["Uri"], output=self.output) for n in list(streams.keys()): yield streams[n] if stream["Target"] == "Streaming": self.config.set("other", "-v -y '{0}'".format(stream['Uri'].replace("rtmp://vod.dr.dk/cms/", ""))) rtmp = "rtmp://vod.dr.dk/cms/" yield RTMP(copy.copy(self.config), rtmp, stream['Bitrate'], output=self.output)
def get(self, options): error, data = self.get_urldata() if error: log.error("Can't get the page") return if self.exclude(options): return match = re.search("data-subtitlesurl = \"(/.*)\"", data) if match: parse = urlparse(self.url) suburl = "%s://%s%s" % (parse.scheme, parse.netloc, match.group(1)) yield subtitle(copy.copy(options), "tt", suburl) if options.force_subtitle: return match = re.search(r'data-media="(.*manifest.f4m)"', self.get_urldata()[1]) if match: manifest_url = match.group(1) else: match = re.search(r'data-video-id="(\d+)"', self.get_urldata()[1]) if match is None: log.error("Can't find video id.") return vid = match.group(1) match = re.search(r"PS_VIDEO_API_URL : '([^']*)',", self.get_urldata()[1]) if match is None: log.error("Can't find server address with media info") return dataurl = "%smediaelement/%s" % (match.group(1), vid) error, data = get_http_data(dataurl) data = json.loads(data) manifest_url = data["mediaUrl"] options.live = data["isLive"] hlsurl = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8") streams = hlsparse(hlsurl) for n in list(streams.keys()): yield HLS(copy.copy(options), streams[n], n) streams = hdsparse(copy.copy(options), manifest_url) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): data = self.get_urldata() if self.exclude(self.options): yield ServiceError("Excluding video") return match = re.search("data-subtitlesurl = \"(/.*)\"", data) if match: parse = urlparse(self.url) suburl = "%s://%s%s" % (parse.scheme, parse.netloc, match.group(1)) yield subtitle(copy.copy(self.options), "tt", suburl) if self.options.force_subtitle: return match = re.search(r'data-media="(.*manifest.f4m)"', self.get_urldata()) if match: manifest_url = match.group(1) else: match = re.search(r'data-nrk-id="([^"]+)"></div><script', self.get_urldata()) if match is None: match = re.search(r'video-id="([^"]+)"', self.get_urldata()) if match is None: yield ServiceError("Can't find video id.") return vid = match.group(1) dataurl = "http://v8.psapi.nrk.no/mediaelement/%s" % vid data = self.http.request("get", dataurl).text data = json.loads(data) manifest_url = data["mediaUrl"] self.options.live = data["isLive"] hlsurl = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8") data = self.http.request("get", hlsurl) if data.status_code == 403: yield ServiceError("Can't fetch the video because of geoblocked") return streams = hlsparse(self.options, data, hlsurl) for n in list(streams.keys()): yield streams[n] streams = hdsparse(copy.copy(self.options), self.http.request("get", manifest_url, params={"hdcore": "3.7.0"}), manifest_url) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): # First, fint the video ID from the html document match = re.search('program-id" content="([^"]+)"', self.get_urldata()) if match: video_id = match.group(1) else: yield ServiceError("Can't find video id.") return # Get media element details match = re.search('psapi-base-url="([^"]+)"', self.get_urldata()) if not match: yield ServiceError("Cant find apiurl.") return dataurl = "{}/mediaelement/{}".format(match.group(1), video_id) data = self.http.request("get", dataurl).text data = json.loads(data) manifest_url = data["mediaUrl"] self.config.set("live", data["isLive"]) if manifest_url is None: yield ServiceError(data["messageType"]) return # Check if subtitles are available if data["subtitlesUrlPath"]: yield subtitle(copy.copy(self.config), "tt", data["subtitlesUrlPath"], output=self.output) hlsurl = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8") data = self.http.request("get", hlsurl) if data.status_code == 403: yield ServiceError("Can't fetch the video because of geoblocking") return streams = hlsparse(self.config, data, hlsurl, output=self.output) if streams: for n in list(streams.keys()): yield streams[n] else: streams = hdsparse( copy.copy(self.config), self.http.request("get", manifest_url, params={"hdcore": "3.7.0"}), manifest_url, output=self.output, ) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): if self.exclude(): yield ServiceError("Excluding video") return # First, fint the video ID from the html document match = re.search("programId: \"([^\"]+)\"", self.get_urldata()) if match: video_id = match.group(1) else: yield ServiceError("Can't find video id.") return # Get media element details match = re.search("apiBaseUrl: '([^']+)'", self.get_urldata()) if not match: yield ServiceError("Cant find apiurl.") return dataurl = "{0}/mediaelement/{1}".format(match.group(1), video_id) data = self.http.request("get", dataurl).text data = json.loads(data) manifest_url = data["mediaUrl"] self.options.live = data["isLive"] if manifest_url is None: yield ServiceError(data["messageType"]) return # Check if subtitles are available if data["subtitlesUrlPath"]: yield subtitle(copy.copy(self.options), "tt", data["subtitlesUrlPath"]) hlsurl = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8") data = self.http.request("get", hlsurl) if data.status_code == 403: yield ServiceError("Can't fetch the video because of geoblocking") return streams = hlsparse(self.options, data, hlsurl) if streams: for n in list(streams.keys()): yield streams[n] streams = hdsparse(copy.copy(self.options), self.http.request("get", manifest_url, params={"hdcore": "3.7.0"}), manifest_url) if streams: for n in list(streams.keys()): yield streams[n]
def _get_video(self, janson): if "subtitleReferences" in janson: for i in janson["subtitleReferences"]: if i["format"] == "websrt" and "url" in i: yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output) if "videoReferences" in janson: if len(janson["videoReferences"]) == 0: yield ServiceError("Media doesn't have any associated videos.") return for i in janson["videoReferences"]: streams = None alt_streams = None alt = None query = parse_qs(urlparse(i["url"]).query) if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if i["format"] == "hls": streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output) if alt: alt_streams = hlsparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output) elif i["format"] == "hds": match = re.search(r"\/se\/secure\/", i["url"]) if not match: streams = hdsparse(self.config, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"], output=self.output) if alt: alt_streams = hdsparse(self.config, self.http.request("get", alt.request.url, params={"hdcore": "3.7.0"}), alt.request.url, output=self.output) elif i["format"] == "dash264" or i["format"] == "dashhbbtv": streams = dashparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output) if alt: alt_streams = dashparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output) if streams: for n in list(streams.keys()): yield streams[n] if alt_streams: for n in list(alt_streams.keys()): yield alt_streams[n]
def get(self): data = self.get_urldata() match = re.search("n.reduxState=(.*);", data) if not match: yield ServiceError("Cant find video info.") return janson = json.loads(match.group(1)) vid = janson["areaData"]["articles"][list(janson["areaData"]["articles"].keys())[0]]["media"][0]["image"]["svtId"] res = self.http.get("https://api.svt.se/video/{}".format(vid)) janson = res.json() if "subtitleReferences" in janson: for i in janson["subtitleReferences"]: if i["format"] == "websrt" and "url" in i: yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output) videos = self._get_video(janson) yield from videos
def get(self, options): error, data = self.get_urldata() if error: log.error("Can't get the page") return match = re.search(r"urPlayer.init\((.*)\);", data) if not match: log.error("Can't find json info") return if self.exclude(options): return data = match.group(1) jsondata = json.loads(data) if len(jsondata["subtitles"]) > 0: yield subtitle(copy.copy(options), "tt", jsondata["subtitles"][0]["file"].split(",")[0]) basedomain = jsondata["streaming_config"]["streamer"]["redirect"] http = "http://%s/%s" % (basedomain, jsondata["file_http"]) hd = None if len(jsondata["file_http_hd"]) > 0: http_hd = "http://%s/%s" % (basedomain, jsondata["file_http_hd"]) hls_hd = "%s%s" % (http_hd, jsondata["streaming_config"]["http_streaming"]["hls_file"]) tmp = jsondata["file_http_hd"] match = re.search("(mp[34]:.*$)", tmp) path_hd = match.group(1) hd = True hls = "%s%s" % (http, jsondata["streaming_config"]["http_streaming"]["hls_file"]) rtmp = "rtmp://%s/%s" % (basedomain, jsondata["streaming_config"]["rtmp"]["application"]) match = re.search("(mp[34]:.*$)", jsondata["file_rtmp"]) path = match.group(1) 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: streams = hlsparse(hls_hd) for n in list(streams.keys()): yield HLS(copy.copy(options), streams[n], n) options.other = "-v -a %s -y %s" % (jsondata["streaming_config"]["rtmp"]["application"], path_hd) yield RTMP(copy.copy(options), rtmp, "720")
def get(self): data = self.get_urldata() match_data_video_id = re.search('data-video-id="(.+?)"', data) if match_data_video_id: id = match_data_video_id.group(1) else: yield ServiceError("Cant find video info.") return res = self.http.get("http://api.svt.se/videoplayer-api/video/{}".format(id)) janson = res.json() if "subtitleReferences" in janson: for i in janson["subtitleReferences"]: if i["format"] == "websrt" and "url" in i: yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output) videos = self._get_video(janson) yield from videos
def get(self): data = self.get_urldata() match_data_video_id = re.search("data-video-id=\"(.+?)\"", data) if match_data_video_id: id = match_data_video_id.group(1) else: yield ServiceError("Cant find video info.") return res = self.http.get("http://api.svt.se/videoplayer-api/video/{0}".format(id)) janson = res.json() if "subtitleReferences" in janson: for i in janson["subtitleReferences"]: if i["format"] == "websrt" and "url" in i: yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output) videos = self._get_video(janson) for i in videos: yield i
def get(self): if self.exclude(): yield ServiceError("Excluding video") return # First, fint the video ID from the html document video_id = re.search("<meta name=\"programid\".*?content=\"([^\"]*)\"", self.get_urldata()).group(1) if video_id is None: yield ServiceError("Can't find video id.") return # Get media element details parse = urlparse(self.url) dataurl = "%s://v8.psapi.nrk.no/mediaelement/%s" % (parse.scheme, video_id) data = self.http.request("get", dataurl).text data = json.loads(data) manifest_url = data["mediaUrl"] self.options.live = data["isLive"] # Check if subtitles are available if data["subtitlesUrlPath"]: yield subtitle(copy.copy(self.options), "tt", data["subtitlesUrlPath"]) hlsurl = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8") data = self.http.request("get", hlsurl) if data.status_code == 403: yield ServiceError("Can't fetch the video because of geoblocking") return streams = hlsparse(self.options, data, hlsurl) for n in list(streams.keys()): yield streams[n] streams = hdsparse(copy.copy(self.options), self.http.request("get", manifest_url, params={"hdcore": "3.7.0"}), manifest_url) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): if self.exclude(): yield ServiceError("Excluding video") return # First, fint the video ID from the html document video_id = re.search("<meta name=\"programid\".*?content=\"([^\"]*)\"", self.get_urldata()).group(1) if video_id is None: yield ServiceError("Can't find video id.") return # Get media element details dataurl = "http://v8.psapi.nrk.no/mediaelement/%s" % (video_id) data = self.http.request("get", dataurl).text data = json.loads(data) manifest_url = data["mediaUrl"] self.options.live = data["isLive"] # Check if subtitles are available if data["subtitlesUrlPath"]: yield subtitle(copy.copy(self.options), "tt", data["subtitlesUrlPath"]) hlsurl = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8") data = self.http.request("get", hlsurl) if data.status_code == 403: yield ServiceError("Can't fetch the video because of geoblocking") return streams = hlsparse(self.options, data, hlsurl) for n in list(streams.keys()): yield streams[n] streams = hdsparse(copy.copy(self.options), self.http.request("get", manifest_url, params={"hdcore": "3.7.0"}), manifest_url) if streams: for n in list(streams.keys()): yield streams[n]
def get(self, options): match = re.search(r".*video/([0-9]+)", self.url) if not match: yield ServiceError("Can't find video file") return video_id = match.group(1) if options.username and options.password: # get session cookie data = self.http.request("get", "http://www.kanal5play.se/", cookies=self.cookies) authurl = "https://kanal5swe.appspot.com/api/user/login?callback=jQuery171029989&email=%s&password=%s&_=136250" % \ (options.username, options.password) data = self.http.request("get", authurl, cookies=data.cookies).text match = re.search(r"({.*})\);", data) jsondata = json.loads(match.group(1)) if jsondata["success"] is False: yield ServiceError(jsondata["message"]) return authToken = jsondata["userData"]["auth"] self.cookies = {"authToken": authToken} options.cookies = self.cookies url = "http://www.kanal5play.se/api/getVideo?format=FLASH&videoId=%s" % video_id data = self.http.request("get", url, cookies=self.cookies).text data = json.loads(data) options.cookies = self.cookies if not options.live: options.live = data["isLive"] if options.output_auto: directory = os.path.dirname(options.output) options.service = "kanal5" title = "%s-s%s-%s-%s-%s" % (data["program"]["name"], data["seasonNumber"], data["episodeText"], data["id"], options.service) title = filenamify(title) if len(directory): options.output = os.path.join(directory, title) else: options.output = title if self.exclude(options): yield ServiceError("Excluding video") return if data["hasSubtitle"]: yield subtitle(copy.copy(options), "json", "http://www.kanal5play.se/api/subtitles/%s" % video_id) if options.force_subtitle: return show = True if "streams" in data.keys(): for i in data["streams"]: if i["drmProtected"]: yield ServiceError("We cant download drm files for this site.") return steambaseurl = data["streamBaseUrl"] bitrate = i["bitrate"] if bitrate > 1000: bitrate = bitrate / 1000 options2 = copy.copy(options) options2.other = "-W %s -y %s " % ("http://www.kanal5play.se/flash/K5StandardPlayer.swf", i["source"]) options2.live = True yield RTMP(options2, steambaseurl, bitrate) url = "http://www.kanal5play.se/api/getVideo?format=IPAD&videoId=%s" % video_id data = self.http.request("get", url, cookies=self.cookies) data = json.loads(data.text) if "reasonsForNoStreams" in data: show = False if "streams" in data.keys(): for i in data["streams"]: streams = hlsparse(i["source"], self.http.request("get", i["source"]).text) for n in list(streams.keys()): yield HLS(copy.copy(options), streams[n], n) if "reasonsForNoStreams" in data and show: yield ServiceError(data["reasonsForNoStreams"][0])
def get(self, options): data = self.get_urldata() vid = findvid(self.url, data) if vid is None: yield ServiceError("Can't find video id for %s" % self.url) return if options.username and options.password: data = self.http.request("get", "https://www.tv4play.se/session/new?https=") auth_token = re.search('name="authenticity_token" ([a-z]+="[^"]+" )?value="([^"]+)"', data.text) if not auth_token: yield ServiceError("Can't find authenticity_token needed for user / password") return url = "https://www.tv4play.se/session" postdata = {"user_name" : options.username, "password": options.password, "authenticity_token":auth_token.group(2), "https": ""} data = self.http.request("post", url, data=postdata, cookies=self.cookies) self.cookies = data.cookies fail = re.search("<p class='failed-login'>([^<]+)</p>", data.text) if fail: yield ServiceError(fail.group(1)) return url = "http://premium.tv4play.se/api/web/asset/%s/play" % vid data = self.http.request("get", url, cookies=self.cookies) if data.status_code == 401: xml = ET.XML(data.content) code = xml.find("code").text if code == "SESSION_NOT_AUTHENTICATED": yield ServiceError("Can't access premium content") elif code == "ASSET_PLAYBACK_INVALID_GEO_LOCATION": yield ServiceError("Can't downoad this video because of geoblocked.") else: yield ServiceError("Can't find any info for that video") return if data.status_code == 404: yield ServiceError("Can't find the video api") return xml = ET.XML(data.content) ss = xml.find("items") if is_py2_old: 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 if xml.find("drmProtected").text == "true": yield ServiceError("We cant download DRM protected content from this site.") return if options.output_auto: directory = os.path.dirname(options.output) options.service = "tv4play" title = "%s-%s-%s" % (options.output, vid, options.service) title = filenamify(title) if len(directory): options.output = os.path.join(directory, title) else: options.output = title if self.exclude(options): yield ServiceError("Excluding video") return for i in sa: if i.find("mediaFormat").text == "mp4": base = urlparse(i.find("base").text) parse = urlparse(i.find("url").text) if "rtmp" in base.scheme: swf = "http://www.tv4play.se/flash/tv4playflashlets.swf" options.other = "-W %s -y %s" % (swf, i.find("url").text) yield RTMP(copy.copy(options), i.find("base").text, i.find("bitrate").text) elif parse.path[len(parse.path)-3:len(parse.path)] == "f4m": streams = hdsparse(copy.copy(options), self.http.request("get", i.find("url").text, params={"hdcore": "3.7.0"}).text, i.find("url").text) if streams: for n in list(streams.keys()): yield streams[n] elif i.find("mediaFormat").text == "smi": yield subtitle(copy.copy(options), "smi", i.find("url").text) url = "http://premium.tv4play.se/api/web/asset/%s/play?protocol=hls" % vid data = self.http.request("get", url, cookies=self.cookies).content xml = ET.XML(data) ss = xml.find("items") if is_py2_old: sa = list(ss.getiterator("item")) else: sa = list(ss.iter("item")) for i in sa: if i.find("mediaFormat").text == "mp4": parse = urlparse(i.find("url").text) if parse.path.endswith("m3u8"): streams = hlsparse(i.find("url").text, self.http.request("get", i.find("url").text).text) for n in list(streams.keys()): yield HLS(copy.copy(options), streams[n], n)
def hlsparse(config, res, url, **kwargs): streams = {} if not res: return streams if res.status_code > 400: streams[0] = ServiceError("Can't read HLS playlist. {0}".format(res.status_code)) return streams m3u8 = M3U8(res.text) keycookie = kwargs.pop("keycookie", None) authorization = kwargs.pop("authorization", None) httpobject = kwargs.pop("httpobject", None) output = kwargs.pop("output", None) media = {} subtitles = {} segments = None if m3u8.master_playlist: for i in m3u8.master_playlist: audio_url = None if i["TAG"] == "EXT-X-MEDIA": if "AUTOSELECT" in i and (i["AUTOSELECT"].upper() == "YES"): if i["TYPE"] and i["TYPE"] != "SUBTITLES": if "URI" in i: if segments is None: segments = True if i["GROUP-ID"] not in media: media[i["GROUP-ID"]] = [] media[i["GROUP-ID"]].append(i["URI"]) else: segments = False if i["TYPE"] == "SUBTITLES": if "URI" in i: if i["GROUP-ID"] not in subtitles: subtitles[i["GROUP-ID"]] = [] item = [i["URI"], i["LANGUAGE"]] if item not in subtitles[i["GROUP-ID"]]: subtitles[i["GROUP-ID"]].append(item) continue elif i["TAG"] == "EXT-X-STREAM-INF": bit_rate = float(i["BANDWIDTH"]) / 1000 if "AUDIO" in i and (i["AUDIO"] in media): audio_url = get_full_url(media[i["AUDIO"]][0], url) urls = get_full_url(i["URI"], url) else: continue # Needs to be changed to utilise other tags. streams[int(bit_rate)] = HLS(copy.copy(config), urls, bit_rate, cookies=res.cookies, keycookie=keycookie, authorization=authorization, audio=audio_url, output=output, segments=bool(segments), kwargs=kwargs) if subtitles and httpobject: for sub in list(subtitles.keys()): for n in subtitles[sub]: m3u8s = M3U8(httpobject.request("get", get_full_url(n[0], url), cookies=res.cookies).text) if "cmore" in url: subtype = "wrstsegment" # this have been seen in tv4play else: subtype = "wrst" streams[int(random.randint(1, 40))] = subtitle(copy.copy(config), subtype, get_full_url(m3u8s.media_segment[0]["URI"], url), subfix=n[1], output=copy.copy(output), m3u8=m3u8s) elif m3u8.media_segment: config.set("segments", False) streams[0] = HLS(copy.copy(config), url, 0, cookies=res.cookies, keycookie=keycookie, authorization=authorization, output=output, segments=False) else: streams[0] = ServiceError("Can't find HLS playlist in m3u8 file.") return streams
def get(self): data = self.get_urldata() premium = False parse = urlparse(self.url) domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1) match = re.search(r"<link rel='shortlink' href='[^']+/\?p=(\d+)", data) if not match: match = re.search(r'data-video-id="([^"]+)"', data) if not match: yield ServiceError("Can't find video id") return vid = match.group(1) data = self.http.request( "get", "http://%s/api/v2/ajax/videos?video_id=%s" % (parse.netloc, vid)).text dataj = json.loads(data) if dataj["data"] is None: yield ServiceError("Cant find video. wrong url without video?") return if self.options.username and self.options.password: premium = self._login(self.options) if not premium: yield ServiceError("Wrong username or password") return what = self._playable(dataj, premium) if what == 1: yield ServiceError("Premium content") return if what == 2: yield ServiceError("DRM protected. Can't do anything") return if self.options.output_auto: directory = os.path.dirname(self.options.output) self.options.service = "dplay" name = self._autoname(dataj) if name is None: yield ServiceError("Cant find vid id for autonaming") return title = "%s-%s-%s" % (name, vid, self.options.service) if len(directory): self.options.output = os.path.join(directory, title) else: self.options.output = title if self.exclude(): yield ServiceError("Excluding video") return suburl = dataj["data"][0]["subtitles_sv_srt"] if len(suburl) > 0: yield subtitle(copy.copy(self.options), "raw", suburl) data = self.http.request("get", "http://geo.%s/geo.js" % domain).text dataj = json.loads(data) geo = dataj["countryCode"] timestamp = (int(time.time()) + 3600) * 1000 cookie = { "dsc-geo": quote('{"countryCode":"%s","expiry":%s}' % (geo, timestamp)) } if self.options.cookies: self.options.cookies.update(cookie) else: self.options.cookies = cookie data = self.http.request( "get", "https://secure.%s/secure/api/v2/user/authorization/stream/%s?stream_type=hds" % (domain, vid), cookies=self.options.cookies) if data.status_code == 403 or data.status_code == 401: yield ServiceError("Geoblocked video") return dataj = json.loads(data.text) if "hds" in dataj: streams = hdsparse( copy.copy(self.options), self.http.request("get", dataj["hds"], params={"hdcore": "3.8.0"}), dataj["hds"]) if streams: for n in list(streams.keys()): yield streams[n] data = self.http.request( "get", "https://secure.%s/secure/api/v2/user/authorization/stream/%s?stream_type=hls" % (domain, vid), cookies=self.options.cookies) dataj = json.loads(data.text) if "hls" in dataj: streams = hlsparse(self.options, self.http.request("get", dataj["hls"]), dataj["hls"]) if streams: for n in list(streams.keys()): yield streams[n]
def get(self, options): vid = self._get_video_id() if vid is None: yield ServiceError("Can't find video file for: %s" % self.url) return url = "http://playapi.mtgx.tv/v3/videos/%s" % vid options.other = "" data = self.http.request("get", url) if data.status_code == 403: yield ServiceError("Can't play this because the video is geoblocked.") return dataj = json.loads(data.text) if "msg" in dataj: yield ServiceError(dataj["msg"]) return if dataj["type"] == "live": options.live = True if self.exclude(options): yield ServiceError("Excluding video") return if dataj["sami_path"]: yield subtitle(copy.copy(options), "sami", dataj["sami_path"]) if dataj["subtitles_for_hearing_impaired"]: yield subtitle(copy.copy(options), "sami", dataj["subtitles_for_hearing_impaired"]) streams = self.http.request("get", "http://playapi.mtgx.tv/v3/videos/stream/%s" % vid) if streams.status_code == 403: yield ServiceError("Can't play this because the video is geoblocked.") return streamj = json.loads(streams.text) if "msg" in streamj: yield ServiceError("Can't play this because the video is either not found or geoblocked.") return if streamj["streams"]["medium"]: filename = streamj["streams"]["medium"] if ".f4m" in filename: streams = hdsparse(options, self.http.request("get", filename, params={"hdcore": "3.7.0"}), filename) if streams: for n in list(streams.keys()): yield streams[n] else: parse = urlparse(filename) match = re.search("^(/[^/]+)/(.*)", parse.path) if not match: yield ServiceError("Can't get rtmpparse info") return filename = "%s://%s:%s%s" % (parse.scheme, parse.hostname, parse.port, match.group(1)) path = "-y %s" % match.group(2) options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf %s" % path yield RTMP(copy.copy(options), filename, 800) if streamj["streams"]["hls"]: streams = hlsparse(options, self.http.request("get", streamj["streams"]["hls"]), streamj["streams"]["hls"]) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): vid = self.find_video_id() if vid is None: yield ServiceError("Cant find video id for this video") return url = "http://api.svt.se/videoplayer-api/video/{0}".format(vid) data = self.http.request("get", url) if data.status_code == 404: yield ServiceError("Can't get the json file for {0}".format(url)) return data = data.json() if "live" in data: self.options.live = data["live"] if self.options.output_auto: self.options.service = "svtplay" self.options.output = self.outputfilename(data, self.options.output, ensure_unicode(self.get_urldata())) if self.exclude(): yield ServiceError("Excluding video") return if "subtitleReferences" in data: for i in data["subtitleReferences"]: if i["format"] == "websrt": yield subtitle(copy.copy(self.options), "wrst", i["url"]) if len(data["videoReferences"]) == 0: yield ServiceError("Media doesn't have any associated videos (yet?)") return for i in data["videoReferences"]: parse = urlparse(i["url"]) query = parse_qs(parse.query) if i["format"] == "hls" or i["format"] == "ios": streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = hlsparse(self.options, self.http.request("get", alt.request.url), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n] if i["format"] == "hds" or i["format"] == "flash": match = re.search(r"\/se\/secure\/", i["url"]) if not match: streams = hdsparse(self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = hdsparse(self.options, self.http.request("get", alt.request.url, params={"hdcore": "3.7.0"}), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n] if i["format"] == "dash264" or i["format"] == "dashhbbtv": streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = dashparse(self.options, self.http.request("get", alt.request.url), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): if not self.options.username or not self.options.password: yield ServiceError( "You need username and password to download things from this site." ) return token, message = self._login() if not token: yield ServiceError(message) return res = self.http.get(self.url) match = re.search('data-asset-splash-section data-asset-id="([^"]+)"', res.text) if not match: yield ServiceError("Can't find video id") return url = "https://restapi.cmore.se/api/tve_web/asset/{0}/play.json?protocol=VUDASH".format( match.group(1)) res = self.http.get( url, headers={"authorization": "Bearer {0}".format(token)}) janson = res.json() if self.options.output_auto: directory = os.path.dirname(self.options.output) self.options.service = "cmore" basename = self._autoname(match.group(1)) if basename is None: yield ServiceError("Cant find vid id for autonaming") return title = "%s-%s-%s" % (basename, match.group(1), self.options.service) title = filenamify(title) if len(directory): self.options.output = os.path.join(directory, title) else: self.options.output = title if self.exclude(): yield ServiceError("Excluding video") return if "drmProtected" in janson["playback"]: if janson["playback"]["drmProtected"]: yield ServiceError("DRM protected. Can't do anything") return if isinstance(janson["playback"]["items"]["item"], list): for i in janson["playback"]["items"]["item"]: if i["mediaFormat"] == "ism": streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if i["mediaFormat"] == "webvtt": yield subtitle(copy.copy(self.options), "wrst", i["url"]) else: i = janson["playback"]["items"]["item"] if i["mediaFormat"] == "ism": streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n]
def hlsparse(config, res, url, **kwargs): streams = {} if not res: return streams if res.status_code > 400: streams[0] = ServiceError("Can't read HLS playlist. {0}".format( res.status_code)) return streams m3u8 = M3U8(res.text) keycookie = kwargs.pop("keycookie", None) authorization = kwargs.pop("authorization", None) httpobject = kwargs.pop("httpobject", None) output = kwargs.pop("output", None) media = {} subtitles = {} segments = None if m3u8.master_playlist: for i in m3u8.master_playlist: audio_url = None if i["TAG"] == "EXT-X-MEDIA": if "AUTOSELECT" in i and (i["AUTOSELECT"].upper() == "YES"): if i["TYPE"] and i["TYPE"] != "SUBTITLES": if "URI" in i: if segments is None: segments = True if i["GROUP-ID"] not in media: media[i["GROUP-ID"]] = [] media[i["GROUP-ID"]].append(i["URI"]) else: segments = False if i["TYPE"] == "SUBTITLES": if "URI" in i: if i["GROUP-ID"] not in subtitles: subtitles[i["GROUP-ID"]] = [] item = [i["URI"], i["LANGUAGE"]] if item not in subtitles[i["GROUP-ID"]]: subtitles[i["GROUP-ID"]].append(item) continue elif i["TAG"] == "EXT-X-STREAM-INF": bit_rate = float(i["BANDWIDTH"]) / 1000 if "AUDIO" in i and (i["AUDIO"] in media): audio_url = get_full_url(media[i["AUDIO"]][0], url) urls = get_full_url(i["URI"], url) else: continue # Needs to be changed to utilise other tags. streams[int(bit_rate)] = HLS(copy.copy(config), urls, bit_rate, cookies=res.cookies, keycookie=keycookie, authorization=authorization, audio=audio_url, output=output, segments=bool(segments), kwargs=kwargs) if subtitles and httpobject: for sub in list(subtitles.keys()): for n in subtitles[sub]: m3u8s = M3U8( httpobject.request("get", get_full_url(n[0], url), cookies=res.cookies).text) if "cmore" in url: subtype = "wrstsegment" # this have been seen in tv4play else: subtype = "wrst" streams[int(random.randint(1, 40))] = subtitle( copy.copy(config), subtype, get_full_url(m3u8s.media_segment[0]["URI"], url), subfix=n[1], output=copy.copy(output), m3u8=m3u8s) elif m3u8.media_segment: config.set("segments", False) streams[0] = HLS(copy.copy(config), url, 0, cookies=res.cookies, keycookie=keycookie, authorization=authorization, output=output, segments=False) else: streams[0] = ServiceError("Can't find HLS playlist in m3u8 file.") return streams
def get(self, options): data = self.get_urldata() vid = findvid(self.url, data) if vid is None: yield ServiceError("Can't find video id for %s" % self.url) return if options.username and options.password: work = self._login(options.username, options.password) if isinstance(work, Exception): yield work return url = "http://premium.tv4play.se/api/web/asset/%s/play" % vid data = self.http.request("get", url, cookies=self.cookies) if data.status_code == 401: xml = ET.XML(data.content) code = xml.find("code").text if code == "SESSION_NOT_AUTHENTICATED": yield ServiceError("Can't access premium content") elif code == "ASSET_PLAYBACK_INVALID_GEO_LOCATION": yield ServiceError("Can't downoad this video because of geoblocked.") else: yield ServiceError("Can't find any info for that video") return if data.status_code == 404: yield ServiceError("Can't find the video api") return xml = ET.XML(data.content) ss = xml.find("items") if is_py2_old: 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 if xml.find("drmProtected").text == "true": yield ServiceError("We cant download DRM protected content from this site.") return if options.output_auto: directory = os.path.dirname(options.output) options.service = "tv4play" basename = self._autoname(vid) if basename is None: yield ServiceError("Cant find vid id for autonaming") return title = "%s-%s-%s" % (basename, vid, options.service) title = filenamify(title) if len(directory): options.output = os.path.join(directory, title) else: options.output = title if self.exclude(options): yield ServiceError("Excluding video") return for i in sa: if i.find("mediaFormat").text == "mp4": base = urlparse(i.find("base").text) parse = urlparse(i.find("url").text) if "rtmp" in base.scheme: swf = "http://www.tv4play.se/flash/tv4playflashlets.swf" options.other = "-W %s -y %s" % (swf, i.find("url").text) yield RTMP(copy.copy(options), i.find("base").text, i.find("bitrate").text) elif parse.path[len(parse.path)-3:len(parse.path)] == "f4m": streams = hdsparse(options, self.http.request("get", i.find("url").text, params={"hdcore": "3.7.0"}), i.find("url").text) if streams: for n in list(streams.keys()): yield streams[n] elif i.find("mediaFormat").text == "smi": yield subtitle(copy.copy(options), "smi", i.find("url").text) url = "http://premium.tv4play.se/api/web/asset/%s/play?protocol=hls" % vid data = self.http.request("get", url, cookies=self.cookies).content xml = ET.XML(data) ss = xml.find("items") if is_py2_old: sa = list(ss.getiterator("item")) else: sa = list(ss.iter("item")) for i in sa: if i.find("mediaFormat").text == "mp4": parse = urlparse(i.find("url").text) if parse.path.endswith("m3u8"): streams = hlsparse(options, self.http.request("get", i.find("url").text), i.find("url").text) for n in list(streams.keys()): yield streams[n]
def get(self, options): data = self.get_urldata() premium = False if self.exclude(options): yield ServiceError("Excluding video") return match = re.search("<link rel='shortlink' href='http://www.dplay.se/\?p=(\d+)", data) if not match: yield ServiceError("Can't find video id") return vid = match.group(1) data = self.http.request("get", "http://www.dplay.se/api/v2/ajax/videos?video_id=%s" % vid).text dataj = json.loads(data) if options.username and options.password: premium = self._login(options) if not premium: yield ServiceError("Wrong username or password") return what = self._playable(dataj, premium) if what == 1: yield ServiceError("Premium content") return if what == 2: yield ServiceError("DRM protected. Can't do anything") return if options.output_auto: directory = os.path.dirname(options.output) options.service = "dplay" name = self._autoname(dataj) if name is None: yield ServiceError("Cant find vid id for autonaming") return title = "%s-%s-%s" % (name, vid, options.service) if len(directory): options.output = os.path.join(directory, title) else: options.output = title suburl = dataj["data"][0]["subtitles_sv_srt"] if len(suburl) > 0: yield subtitle(copy.copy(options), "raw", suburl) if options.force_subtitle: return data = self.http.request("get", "http://geo.dplay.se/geo.js").text dataj = json.loads(data) geo = dataj["countryCode"] timestamp = (int(time.time())+3600)*1000 cookie = {"dsc-geo": quote('{"countryCode":"%s","expiry":%s}' % (geo, timestamp))} if options.cookies: options.cookies.update(cookie) else: options.cookies = cookie data = self.http.request("get", "https://secure.dplay.se/secure/api/v2/user/authorization/stream/%s?stream_type=hds" % vid, cookies=options.cookies) dataj = json.loads(data.text) if "hds" in dataj: streams = hdsparse(copy.copy(options), self.http.request("get", dataj["hds"], params={"hdcore": "3.8.0"}), dataj["hds"]) if streams: for n in list(streams.keys()): yield streams[n] data = self.http.request("get", "https://secure.dplay.se/secure/api/v2/user/authorization/stream/%s?stream_type=hls" % vid, cookies=options.cookies) dataj = json.loads(data.text) if "hls" in dataj: streams = hlsparse(options, self.http.request("get", dataj["hls"]), dataj["hls"]) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): parse = urlparse(self.url) if parse.netloc == "www.svtplay.se" or parse.netloc == "svtplay.se": if parse.path[:6] != "/video" and parse.path[:6] != "/klipp": yield ServiceError( "This mode is not supported anymore. need the url with the video" ) return match = re.search("__svtplay'] = ({.*});", self.get_urldata()) if not match: yield ServiceError("Cant find video info.") return janson = json.loads(match.group(1))["videoTitlePage"] if "live" in janson["video"]: self.options.live = janson["video"]["live"] if not "programTitle" in janson["video"]: yield ServiceError("Can't find any video on that page") return if self.options.output_auto: self.options.service = "svtplay" self.options.output = self.outputfilename(janson["video"], self.options.output) if self.exclude(): yield ServiceError("Excluding video") return if "programVersionId" in janson["video"]: vid = janson["video"]["programVersionId"] else: vid = janson["video"]["id"] res = self.http.get( "http://api.svt.se/videoplayer-api/video/{0}".format(vid)) janson = res.json() if "live" in janson: self.options.live = janson["live"] if "subtitleReferences" in janson: for i in janson["subtitleReferences"]: if i["format"] == "websrt" and "url" in i: yield subtitle(copy.copy(self.options), "wrst", i["url"]) if "videoReferences" in janson: if len(janson["videoReferences"]) == 0: yield ServiceError( "Media doesn't have any associated videos (yet?)") return for i in janson["videoReferences"]: parse = urlparse(i["url"]) query = parse_qs(parse.query) if i["format"] == "hls": streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = hlsparse( self.options, self.http.request("get", alt.request.url), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n] if i["format"] == "hds": match = re.search(r"\/se\/secure\/", i["url"]) if not match: streams = hdsparse( self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = hdsparse( self.options, self.http.request( "get", alt.request.url, params={"hdcore": "3.7.0"}), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n] if i["format"] == "dash264" or i["format"] == "dashhbbtv": streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = dashparse( self.options, self.http.request("get", alt.request.url), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): parse = urlparse(self.url) vid = self._get_video_id() if vid is None: if parse.path[:6] == "/sport": result = self._sport() yield from result return else: yield ServiceError("Can't find video file for: {}".format( self.url)) return data = self._get_video_data(vid) if data.status_code == 403: yield ServiceError( "Can't play this because the video is geoblocked.") return dataj = json.loads(data.text) if "msg" in dataj: yield ServiceError(dataj["msg"]) return if dataj["type"] == "live": self.config.set("live", True) self.output["id"] = vid self._autoname(dataj) streams = self.http.request( "get", "http://playapi.mtgx.tv/v3/videos/stream/{}".format(vid)) if streams.status_code == 403: yield ServiceError( "Can't play this because the video is geoblocked.") return streamj = json.loads(streams.text) if "msg" in streamj: yield ServiceError( "Can't play this because the video is either not found or geoblocked." ) return if dataj["sami_path"]: if dataj["sami_path"].endswith("vtt"): subtype = "wrst" else: subtype = "sami" yield subtitle(copy.copy(self.config), subtype, dataj["sami_path"], output=self.output) if dataj["subtitles_webvtt"]: yield subtitle(copy.copy(self.config), "wrst", dataj["subtitles_webvtt"], output=self.output) if dataj["subtitles_for_hearing_impaired"]: if dataj["subtitles_for_hearing_impaired"].endswith("vtt"): subtype = "wrst" else: subtype = "sami" if self.config.get("get_all_subtitles"): yield subtitle(copy.copy(self.config), subtype, dataj["subtitles_for_hearing_impaired"], "-SDH", output=self.output) else: yield subtitle(copy.copy(self.config), subtype, dataj["subtitles_for_hearing_impaired"], output=self.output) if streamj["streams"][ "medium"] and streamj["streams"]["medium"][:7] != "[empty]": filename = streamj["streams"]["medium"] if ".f4m" in filename: streams = hdsparse(self.config, self.http.request( "get", filename, params={"hdcore": "3.7.0"}), filename, output=self.output) for n in list(streams.keys()): yield streams[n] if streamj["streams"]["hls"]: streams = hlsparse(self.config, self.http.request("get", streamj["streams"]["hls"]), streamj["streams"]["hls"], output=self.output) for n in list(streams.keys()): yield streams[n]
def get(self): parse = urlparse(self.url) if parse.path[:8] == "/kanaler": end_time_stamp = (datetime.utcnow() - timedelta(seconds=20)).replace(microsecond=0) start_time_stamp = end_time_stamp - timedelta(minutes=1) url = "https://bbr-l2v.akamaized.net/live/{0}/master.m3u8?in={1}&out={2}?".format(parse.path[9:], start_time_stamp.isoformat(), end_time_stamp.isoformat()) self.options.live = True self.options.hls_time_stamp = True streams = hlsparse(self.options, self.http.request("get", url), url) if streams: for n in list(streams.keys()): yield streams[n] return data = self.get_urldata() vid = findvid(self.url, data) if not vid: yield ServiceError("Can't find video id for {0}.".format(self.url)) return url = "http://prima.tv4play.se/api/web/asset/{0}/play".format(vid) data = self.http.request("get", url, cookies=self.cookies) if data.status_code == 401: xml = ET.XML(data.content) code = xml.find("code").text if code == "SESSION_NOT_AUTHENTICATED": yield ServiceError("Can't access premium content") elif code == "ASSET_PLAYBACK_INVALID_GEO_LOCATION": yield ServiceError("Can't download this video because of geoblock.") else: yield ServiceError("Can't find any info for that video.") return if data.status_code == 404: yield ServiceError("Can't find the video api.") return xml = ET.XML(data.content) ss = xml.find("items") if is_py2_old: sa = list(ss.getiterator("item")) else: sa = list(ss.iter("item")) if xml.find("live").text: self.options.live = (xml.find("live").text != "false") if xml.find("drmProtected").text == "true": yield ServiceError("We can't download DRM protected content from this site.") return if xml.find("playbackStatus").text == "NOT_STARTED": yield ServiceError("Can't download something that is not started.") return if self.options.output_auto: directory = os.path.dirname(self.options.output) self.options.service = "tv4play" basename = self._autoname(vid) if not basename: yield ServiceError("Cant find vid id for autonaming.") return title = "{0}-{1}-{2}".format(basename, vid, self.options.service) title = filenamify(title) if len(directory): self.options.output = os.path.join(directory, title) else: self.options.output = title if self.exclude(): yield ServiceError("Excluding video.") return for i in sa: if i.find("mediaFormat").text == "mp4": base = urlparse(i.find("base").text) parse = urlparse(i.find("url").text) if "rtmp" in base.scheme: swf = "http://www.tv4play.se/flash/tv4playflashlets.swf" self.options.other = "-W {0} -y {1}".format(swf, i.find("url").text) yield RTMP(copy.copy(self.options), i.find("base").text, i.find("bitrate").text) elif parse.path[len(parse.path) - 3:len(parse.path)] == "f4m": streams = hdsparse(self.options, self.http.request("get", i.find("url").text, params={"hdcore": "3.7.0"}), i.find("url").text) if streams: for n in list(streams.keys()): yield streams[n] elif i.find("mediaFormat").text == "webvtt": yield subtitle(copy.copy(self.options), "wrst", i.find("url").text) url = "https://prima.tv4play.se/api/web/asset/{0}/play?protocol=hls3".format(vid) data = self.http.request("get", url, cookies=self.cookies).content xml = ET.XML(data) ss = xml.find("items") if is_py2_old: sa = list(ss.getiterator("item")) else: sa = list(ss.iter("item")) for i in sa: if i.find("mediaFormat").text == "mp4": parse = urlparse(i.find("url").text) if parse.path.endswith("m3u8"): streams = hlsparse(self.options, self.http.request("get", i.find("url").text), i.find("url").text) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): old = False parse = urlparse(self.url) if parse.netloc == "www.svtplay.se" or parse.netloc == "svtplay.se": if parse.path[:6] != "/video" and parse.path[:6] != "/klipp": yield ServiceError( "This mode is not supported anymore. need the url with the video" ) return vid = self.find_video_id() if vid is None: yield ServiceError("Cant find video id for this video") return if re.match("^[0-9]+$", vid): old = True url = "http://www.svt.se/videoplayer-api/video/%s" % vid data = self.http.request("get", url) if data.status_code == 404: yield ServiceError("Can't get the json file for %s" % url) return data = data.json() if "live" in data: self.options.live = data["live"] if old: params = {"output": "json"} try: dataj = self.http.request("get", self.url, params=params).json() except ValueError: dataj = data old = False else: dataj = data if self.options.output_auto: self.options.service = "svtplay" self.options.output = self.outputfilename( dataj, self.options.output, ensure_unicode(self.get_urldata())) if self.exclude(): yield ServiceError("Excluding video") return if "subtitleReferences" in data: for i in data["subtitleReferences"]: if i["format"] == "websrt": yield subtitle(copy.copy(self.options), "wrst", i["url"]) if old and dataj["video"]["subtitleReferences"]: try: suburl = dataj["video"]["subtitleReferences"][0]["url"] except KeyError: pass if suburl and len(suburl) > 0: yield subtitle(copy.copy(self.options), "wrst", suburl) if len(data["videoReferences"]) == 0: yield ServiceError( "Media doesn't have any associated videos (yet?)") return for i in data["videoReferences"]: if i["format"] == "hls" or i["format"] == "ios": streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if i["format"] == "hds" or i["format"] == "flash": match = re.search(r"\/se\/secure\/", i["url"]) if not match: streams = hdsparse( self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if i["format"] == "dash264": streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): data = self.get_urldata() premium = False parse = urlparse(self.url) domain = re.search(r"(dplay\.\w\w)", parse.netloc).group(1) match = re.search(r"<link rel='shortlink' href='[^']+/\?p=(\d+)", data) if not match: match = re.search(r'data-video-id="([^"]+)"', data) if not match: yield ServiceError("Can't find video id") return vid = match.group(1) data = self.http.request("get", "http://%s/api/v2/ajax/videos?video_id=%s" % (parse.netloc, vid)).text dataj = json.loads(data) if dataj["data"] is None: yield ServiceError("Cant find video. wrong url without video?") return if self.options.username and self.options.password: premium = self._login(self.options) if not premium: yield ServiceError("Wrong username or password") return what = self._playable(dataj, premium) if what == 1: yield ServiceError("Premium content") return if what == 2: yield ServiceError("DRM protected. Can't do anything") return if self.options.output_auto: directory = os.path.dirname(self.options.output) self.options.service = "dplay" name = self._autoname(dataj) if name is None: yield ServiceError("Cant find vid id for autonaming") return title = "%s-%s-%s" % (name, vid, self.options.service) if len(directory): self.options.output = os.path.join(directory, title) else: self.options.output = title if self.exclude(): yield ServiceError("Excluding video") return subt = "subtitles_%s_srt" % self._country2lang() suburl = dataj["data"][0][subt] if len(suburl) > 0: yield subtitle(copy.copy(self.options), "raw", suburl) data = self.http.request("get", "http://geo.%s/geo.js" % domain).text dataj = json.loads(data) geo = dataj["countryCode"] timestamp = (int(time.time()) + 3600) * 1000 cookie = {"dsc-geo": quote('{"countryCode":"%s","expiry":%s}' % (geo, timestamp))} if self.options.cookies: self.options.cookies.update(cookie) else: self.options.cookies = cookie data = self.http.request( "get", "https://secure.%s/secure/api/v2/user/authorization/stream/%s?stream_type=hds" % (domain, vid), cookies=self.options.cookies, ) if data.status_code == 403 or data.status_code == 401: yield ServiceError("Geoblocked video") return dataj = json.loads(data.text) if "hds" in dataj: streams = hdsparse( copy.copy(self.options), self.http.request("get", dataj["hds"], params={"hdcore": "3.8.0"}), dataj["hds"], ) if streams: for n in list(streams.keys()): yield streams[n] data = self.http.request( "get", "https://secure.%s/secure/api/v2/user/authorization/stream/%s?stream_type=hls" % (domain, vid), cookies=self.options.cookies, ) dataj = json.loads(data.text) if "hls" in dataj: streams = hlsparse(self.options, self.http.request("get", dataj["hls"]), dataj["hls"]) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): parse = urlparse(self.url) if parse.netloc == "www.svtplay.se" or parse.netloc == "svtplay.se": if parse.path[:6] != "/video" and parse.path[:6] != "/klipp": yield ServiceError("This mode is not supported anymore. need the url with the video") return match = re.search("__svtplay'] = ({.*});", self.get_urldata()) if not match: yield ServiceError("Cant find video info.") return janson = json.loads(match.group(1))["videoTitlePage"] if "live" in janson["video"]: self.optionslive = janson["video"]["live"] if self.options.output_auto: self.options.service = "svtplay" self.options.output = self.outputfilename(janson, self.options.output) if self.exclude(): yield ServiceError("Excluding video") return if "subtitles" in janson["video"]: for i in janson["video"]["subtitles"]: if i["format"] == "WebSRT": yield subtitle(copy.copy(self.options), "wrst", i["url"]) if "videoReferences" in janson["video"]: if len(janson["video"]["videoReferences"]) == 0: yield ServiceError("Media doesn't have any associated videos (yet?)") return for i in janson["video"]["videoReferences"]: parse = urlparse(i["url"]) query = parse_qs(parse.query) if i["playerType"] == "hls" or i["playerType"] == "ios": streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = hlsparse(self.options, self.http.request("get", alt.request.url), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n] if i["playerType"] == "playerType" or i["playerType"] == "flash": match = re.search(r"\/se\/secure\/", i["url"]) if not match: streams = hdsparse(self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = hdsparse(self.options, self.http.request("get", alt.request.url, params={"hdcore": "3.7.0"}), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n] if i["playerType"] == "dash264" or i["playerType"] == "dashhbbtv": streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = dashparse(self.options, self.http.request("get", alt.request.url), alt.request.url) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): data = self.get_urldata() vid = findvid(self.url, data) if vid is None: yield ServiceError("Can't find video id for %s" % self.url) return # if self.options.username and self.options.password: # work = self._login(self.options.username, self.options.password) # if isinstance(work, Exception): # yield work # return url = "http://prima.tv4play.se/api/web/asset/%s/play" % vid data = self.http.request("get", url, cookies=self.cookies) if data.status_code == 401: xml = ET.XML(data.content) code = xml.find("code").text if code == "SESSION_NOT_AUTHENTICATED": yield ServiceError("Can't access premium content") elif code == "ASSET_PLAYBACK_INVALID_GEO_LOCATION": yield ServiceError( "Can't download this video because of geoblock.") else: yield ServiceError("Can't find any info for that video") return if data.status_code == 404: yield ServiceError("Can't find the video api") return xml = ET.XML(data.content) ss = xml.find("items") if is_py2_old: sa = list(ss.getiterator("item")) else: sa = list(ss.iter("item")) if xml.find("live").text: if xml.find("live").text != "false": self.options.live = True if xml.find("drmProtected").text == "true": yield ServiceError( "We cant download DRM protected content from this site.") return if xml.find("playbackStatus").text == "NOT_STARTED": yield ServiceError("Can't download something that is not started") return if self.options.output_auto: directory = os.path.dirname(self.options.output) self.options.service = "tv4play" basename = self._autoname(vid) if basename is None: yield ServiceError("Cant find vid id for autonaming") return title = "%s-%s-%s" % (basename, vid, self.options.service) title = filenamify(title) if len(directory): self.options.output = os.path.join(directory, title) else: self.options.output = title if self.exclude(): yield ServiceError("Excluding video") return for i in sa: if i.find("mediaFormat").text == "mp4": base = urlparse(i.find("base").text) parse = urlparse(i.find("url").text) if "rtmp" in base.scheme: swf = "http://www.tv4play.se/flash/tv4playflashlets.swf" self.options.other = "-W %s -y %s" % (swf, i.find("url").text) yield RTMP(copy.copy(self.options), i.find("base").text, i.find("bitrate").text) elif parse.path[len(parse.path) - 3:len(parse.path)] == "f4m": streams = hdsparse( self.options, self.http.request("get", i.find("url").text, params={"hdcore": "3.7.0"}), i.find("url").text) if streams: for n in list(streams.keys()): yield streams[n] elif i.find("mediaFormat").text == "webvtt": yield subtitle(copy.copy(self.options), "wrst", i.find("url").text) url = "https://prima.tv4play.se/api/web/asset/%s/play?protocol=hls3" % vid data = self.http.request("get", url, cookies=self.cookies).content xml = ET.XML(data) ss = xml.find("items") if is_py2_old: sa = list(ss.getiterator("item")) else: sa = list(ss.iter("item")) for i in sa: if i.find("mediaFormat").text == "mp4": parse = urlparse(i.find("url").text) if parse.path.endswith("m3u8"): streams = hlsparse( self.options, self.http.request("get", i.find("url").text), i.find("url").text) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): vid = self.find_video_id() if vid is None: yield ServiceError("Cant find video id for this video") return url = "http://api.svt.se/videoplayer-api/video/{}".format(vid) data = self.http.request("get", url) if data.status_code == 404: yield ServiceError("Can't get the json file for {}".format(url)) return data = data.json() if "live" in data: self.config.set("live", data["live"]) self.outputfilename(data) if "subtitleReferences" in data: for i in data["subtitleReferences"]: if i["format"] == "websrt": yield subtitle(copy.copy(self.config), "wrst", i["url"], output=self.output) if len(data["videoReferences"]) == 0: yield ServiceError("Media doesn't have any associated videos (yet?)") return for i in data["videoReferences"]: parse = urlparse(i["url"]) query = parse_qs(parse.query) if i["format"] == "hls" or i["format"] == "ios": streams = hlsparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output) for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = hlsparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output) for n in list(streams.keys()): yield streams[n] if i["format"] == "hds" or i["format"] == "flash": match = re.search(r"\/se\/secure\/", i["url"]) if not match: streams = hdsparse(self.config, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"], output=self.output) for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = hdsparse( self.config, self.http.request("get", alt.request.url, params={"hdcore": "3.7.0"}), alt.request.url, output=self.output, ) for n in list(streams.keys()): yield streams[n] if i["format"] == "dash264" or i["format"] == "dashhbbtv": streams = dashparse(self.config, self.http.request("get", i["url"]), i["url"], output=self.output) for n in list(streams.keys()): yield streams[n] if "alt" in query and len(query["alt"]) > 0: alt = self.http.get(query["alt"][0]) if alt: streams = dashparse(self.config, self.http.request("get", alt.request.url), alt.request.url, output=self.output) for n in list(streams.keys()): yield streams[n]
def get(self, options): if re.findall("svt.se", self.url): data = self.get_urldata() match = re.search(r"data-json-href=\"(.*)\"", data) if match: filename = match.group(1).replace("&", "&").replace("&format=json", "") url = "http://www.svt.se%s" % filename else: yield ServiceError("Can't find video file for: %s" % self.url) return else: url = self.url if "svt.se" in url: params = {"format": "json"} else: params = {"output": "json"} data = self.http.request("get", url, params=params) if data.status_code == 404: yield ServiceError("Can't get the json file for %s" % url) return data = data.json() if "live" in data["video"]: options.live = data["video"]["live"] if options.output_auto: options.service = "svtplay" options.output = outputfilename(data, options.output, ensure_unicode(self.get_urldata())) if self.exclude(options): yield ServiceError("Excluding video") return if data["video"]["subtitleReferences"]: try: suburl = data["video"]["subtitleReferences"][0]["url"] except KeyError: pass if suburl and len(suburl) > 0: yield subtitle(copy.copy(options), "wrst", suburl) if options.force_subtitle: return if len(data["video"].get("videoReferences", [])) == 0: yield ServiceError("Media doesn't have any associated videos (yet?)") return for i in data["video"]["videoReferences"]: parse = urlparse(i["url"]) if parse.path.find("m3u8") > 0: streams = hlsparse(options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] elif parse.path.find("f4m") > 0: match = re.search(r"\/se\/secure\/", i["url"]) if not match: streams = hdsparse(options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] elif parse.scheme == "rtmp": embedurl = "%s?type=embed" % url data = self.http.request("get", embedurl).text 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(copy.copy(options), i["url"], i["bitrate"]) else: yield HTTP(copy.copy(options), i["url"], "0")
def get(self): vid = self._get_video_id() if vid is None: yield ServiceError("Can't find video file for: %s" % self.url) return url = "http://playapi.mtgx.tv/v3/videos/%s" % vid self.options.other = "" data = self.http.request("get", url) if data.status_code == 403: yield ServiceError( "Can't play this because the video is geoblocked.") return dataj = json.loads(data.text) if "msg" in dataj: yield ServiceError(dataj["msg"]) return if dataj["type"] == "live": self.options.live = True if self.exclude(): yield ServiceError("Excluding video") return streams = self.http.request( "get", "http://playapi.mtgx.tv/v3/videos/stream/%s" % vid) if streams.status_code == 403: yield ServiceError( "Can't play this because the video is geoblocked.") return streamj = json.loads(streams.text) if "msg" in streamj: yield ServiceError( "Can't play this because the video is either not found or geoblocked." ) return if self.options.output_auto: directory = os.path.dirname(self.options.output) self.options.service = "tv3play" basename = self._autoname(dataj) title = "%s-%s-%s" % (basename, vid, self.options.service) if len(directory): self.options.output = os.path.join(directory, title) else: self.options.output = title if dataj["sami_path"]: yield subtitle(copy.copy(self.options), "sami", dataj["sami_path"]) if dataj["subtitles_for_hearing_impaired"]: yield subtitle(copy.copy(self.options), "sami", dataj["subtitles_for_hearing_impaired"]) if streamj["streams"]["medium"]: filename = streamj["streams"]["medium"] if ".f4m" in filename: streams = hdsparse( self.options, self.http.request("get", filename, params={"hdcore": "3.7.0"}), filename) if streams: for n in list(streams.keys()): yield streams[n] else: parse = urlparse(filename) match = re.search("^(/[^/]+)/(.*)", parse.path) if not match: yield ServiceError("Can't get rtmpparse info") return filename = "%s://%s:%s%s" % (parse.scheme, parse.hostname, parse.port, match.group(1)) path = "-y %s" % match.group(2) self.options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf %s" % path yield RTMP(copy.copy(self.options), filename, 800) if streamj["streams"]["hls"]: streams = hlsparse( self.options, self.http.request("get", streamj["streams"]["hls"]), streamj["streams"]["hls"]) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): parse = urlparse(self.url) vid = self._get_video_id() if vid is None: if parse.path[:6] == "/sport": result = self._sport() for i in result: yield i return else: yield ServiceError("Can't find video file for: {0}".format(self.url)) return data = self._get_video_data(vid) if data.status_code == 403: yield ServiceError("Can't play this because the video is geoblocked.") return dataj = json.loads(data.text) if "msg" in dataj: yield ServiceError(dataj["msg"]) return if dataj["type"] == "live": self.config.set("live", True) self.output["id"] = vid self._autoname(dataj) streams = self.http.request("get", "http://playapi.mtgx.tv/v3/videos/stream/{0}".format(vid)) if streams.status_code == 403: yield ServiceError("Can't play this because the video is geoblocked.") return streamj = json.loads(streams.text) if "msg" in streamj: yield ServiceError("Can't play this because the video is either not found or geoblocked.") return if dataj["sami_path"]: if dataj["sami_path"].endswith("vtt"): subtype = "wrst" else: subtype = "sami" yield subtitle(copy.copy(self.config), subtype, dataj["sami_path"], output=self.output) if dataj["subtitles_webvtt"]: yield subtitle(copy.copy(self.config), "wrst", dataj["subtitles_webvtt"], output=self.output) if dataj["subtitles_for_hearing_impaired"]: if dataj["subtitles_for_hearing_impaired"].endswith("vtt"): subtype = "wrst" else: subtype = "sami" if self.config.get("get_all_subtitles"): yield subtitle(copy.copy(self.config), subtype, dataj["subtitles_for_hearing_impaired"], "-SDH", output=self.output) else: yield subtitle(copy.copy(self.config), subtype, dataj["subtitles_for_hearing_impaired"], output=self.output) if streamj["streams"]["medium"] and streamj["streams"]["medium"][:7] != "[empty]": filename = streamj["streams"]["medium"] if ".f4m" in filename: streams = hdsparse(self.config, self.http.request("get", filename, params={"hdcore": "3.7.0"}), filename, output=self.output) for n in list(streams.keys()): yield streams[n] if streamj["streams"]["hls"]: streams = hlsparse(self.config, self.http.request("get", streamj["streams"]["hls"]), streamj["streams"]["hls"], output=self.output) for n in list(streams.keys()): yield streams[n]
def _dashparse(config, text, url, cookies, **kwargs): streams = {} baseurl = None output = kwargs.pop("output", None) attributes = DASHattibutes() xml = ET.XML(text) if xml.find("./{urn:mpeg:dash:schema:mpd:2011}BaseURL") is not None: baseurl = xml.find("./{urn:mpeg:dash:schema:mpd:2011}BaseURL").text if "availabilityStartTime" in xml.attrib: attributes.set("availabilityStartTime", parse_dates(xml.attrib["availabilityStartTime"])) attributes.set("publishTime", parse_dates(xml.attrib["publishTime"])) if "mediaPresentationDuration" in xml.attrib: attributes.set("mediaPresentationDuration", parse_duration(xml.attrib["mediaPresentationDuration"])) if "timeShiftBufferDepth" in xml.attrib: attributes.set("timeShiftBufferDepth", parse_duration(xml.attrib["timeShiftBufferDepth"])) if "minimumUpdatePeriod" in xml.attrib: attributes.set("minimumUpdatePeriod", parse_duration(xml.attrib["minimumUpdatePeriod"])) attributes.set("type", xml.attrib["type"]) temp = xml.findall( './/{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@mimeType="audio/mp4"]' ) if len(temp) == 0: temp = xml.findall( './/{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@contentType="audio"]' ) audiofiles = adaptionset(attributes, temp, url, baseurl) temp = xml.findall( './/{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@mimeType="video/mp4"]' ) if len(temp) == 0: temp = xml.findall( './/{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@contentType="video"]' ) videofiles = adaptionset(attributes, temp, url, baseurl) temp = xml.findall( './/{urn:mpeg:dash:schema:mpd:2011}AdaptationSet[@contentType="text"]') subtitles = adaptionset(attributes, temp, url, baseurl) if not audiofiles or not videofiles: streams[0] = ServiceError( "Found no Audiofiles or Videofiles to download.") return streams if "channels" in kwargs: kwargs.pop("channels") if "codec" in kwargs: kwargs.pop("codec") for i in videofiles.keys(): bitrate = i + list(audiofiles.keys())[0] streams[bitrate] = DASH( copy.copy(config), url, bitrate, cookies=cookies, audio=audiofiles[list(audiofiles.keys())[0]]["files"], files=videofiles[i]["files"], output=output, segments=videofiles[i]["segments"], codec=videofiles[i]["codecs"], channels=audiofiles[list(audiofiles.keys())[0]]["channels"], **kwargs, ) for i in subtitles.keys(): if subtitles[i]["codecs"] == "stpp": streams[i] = subtitle(copy.copy(config), "stpp", url, subtitles[i]["lang"], output=copy.copy(output), files=subtitles[i]["files"], **kwargs) if subtitles[i]["mimetype"] == "text/vtt": streams[i] = subtitle(copy.copy(config), "webvtt", url, subtitles[i]["lang"], output=copy.copy(output), files=subtitles[i]["files"], **kwargs) return streams
def get(self, options): match = re.search(r".*video/([0-9]+)", self.url) if not match: log.error("Can't find video file") return video_id = match.group(1) if options.username and options.password: # get session cookie error, data = get_http_data("http://www.kanal5play.se/", cookiejar=self.cj) authurl = ( "https://kanal5swe.appspot.com/api/user/login?callback=jQuery171029989&email=%s&password=%s&_=136250" % (options.username, options.password) ) error, data = get_http_data(authurl) match = re.search(r"({.*})\);", data) jsondata = json.loads(match.group(1)) if jsondata["success"] is False: log.error(jsondata["message"]) return authToken = jsondata["userData"]["auth"] cc = Cookie( version=0, name="authToken", value=authToken, port=None, port_specified=False, domain="www.kanal5play.se", domain_specified=True, domain_initial_dot=True, path="/", path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={"HttpOnly": None}, ) self.cj.set_cookie(cc) options.cookies = self.cj url = "http://www.kanal5play.se/api/getVideo?format=FLASH&videoId=%s" % video_id error, data = get_http_data(url, cookiejar=self.cj) if error: log.error("Can't download video info") return data = json.loads(data) options.cookiejar = self.cj if not options.live: options.live = data["isLive"] if options.output_auto: directory = os.path.dirname(options.output) options.service = "kanal5" title = "%s-s%s-%s-%s-%s" % ( data["program"]["name"], data["seasonNumber"], data["episodeText"], data["id"], options.service, ) title = filenamify(title) if len(directory): options.output = "%s/%s" % (directory, title) else: options.output = title if self.exclude(options): return if data["hasSubtitle"]: yield subtitle(copy.copy(options), "json", "http://www.kanal5play.se/api/subtitles/%s" % video_id) if options.force_subtitle: return if "streams" in data.keys(): for i in data["streams"]: if i["drmProtected"]: log.error("We cant download drm files for this site.") return steambaseurl = data["streamBaseUrl"] bitrate = i["bitrate"] if bitrate > 1000: bitrate = bitrate / 1000 options2 = copy.copy(options) options2.other = "-W %s -y %s " % ("http://www.kanal5play.se/flash/K5StandardPlayer.swf", i["source"]) options2.live = True yield RTMP(options2, steambaseurl, bitrate) url = "http://www.kanal5play.se/api/getVideo?format=IPAD&videoId=%s" % video_id error, data = get_http_data(url, cookiejar=self.cj) if error: log.error("Cant get video info") return data = json.loads(data) if "streams" in data.keys(): for i in data["streams"]: streams = hlsparse(i["source"]) for n in list(streams.keys()): yield HLS(copy.copy(options), streams[n], n) if "reasonsForNoStreams" in data: log.error(data["reasonsForNoStreams"][0])
def get(self): vid = self._get_video_id() if vid is None: yield ServiceError("Can't find video file for: {0}".format(self.url)) return data = self. _get_video_data(vid) if data.status_code == 403: yield ServiceError("Can't play this because the video is geoblocked.") return dataj = json.loads(data.text) if "msg" in dataj: yield ServiceError(dataj["msg"]) return if dataj["type"] == "live": self.options.live = True if self.options.output_auto: self.options.output = self.outputfilename(dataj,vid, self.options.output) if self.exclude(): yield ServiceError("Excluding video") return streams = self.http.request("get", "http://playapi.mtgx.tv/v3/videos/stream/{0}".format(vid)) if streams.status_code == 403: yield ServiceError("Can't play this because the video is geoblocked.") return streamj = json.loads(streams.text) if "msg" in streamj: yield ServiceError("Can't play this because the video is either not found or geoblocked.") return if dataj["sami_path"]: if dataj["sami_path"].endswith("vtt"): subtype = "wrst" else: subtype = "sami" yield subtitle(copy.copy(self.options), subtype, dataj["sami_path"]) if dataj["subtitles_webvtt"]: yield subtitle(copy.copy(self.options), "wrst", dataj["subtitles_webvtt"]) if dataj["subtitles_for_hearing_impaired"]: if dataj["subtitles_for_hearing_impaired"].endswith("vtt"): subtype = "wrst" else: subtype = "sami" if self.options.get_all_subtitles: yield subtitle(copy.copy(self.options), subtype, dataj["subtitles_for_hearing_impaired"], "-SDH") else: yield subtitle(copy.copy(self.options), subtype, dataj["subtitles_for_hearing_impaired"]) if streamj["streams"]["medium"]: filename = streamj["streams"]["medium"] if ".f4m" in filename: streams = hdsparse(self.options, self.http.request("get", filename, params={"hdcore": "3.7.0"}), filename) if streams: for n in list(streams.keys()): yield streams[n] else: parse = urlparse(filename) match = re.search("^(/[^/]+)/(.*)", parse.path) if not match: yield ServiceError("Can't get rtmpparse info") return filename = "{0}://{1}:{2}{3}".format(parse.scheme, parse.hostname, parse.port, match.group(1)) path = "-y {0}".format(match.group(2)) self.options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf {0}".format(path) yield RTMP(copy.copy(self.options), filename, 800) if streamj["streams"]["hls"]: streams = hlsparse(self.options, self.http.request("get", streamj["streams"]["hls"]), streamj["streams"]["hls"]) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): vid = self._get_video_id() if vid is None: yield ServiceError("Can't find video file for: {0}".format( self.url)) return data = self._get_video_data(vid) if data.status_code == 403: yield ServiceError( "Can't play this because the video is geoblocked.") return dataj = json.loads(data.text) if "msg" in dataj: yield ServiceError(dataj["msg"]) return if dataj["type"] == "live": self.options.live = True if self.options.output_auto: self.options.output = self.outputfilename(dataj, vid, self.options.output) if self.exclude(): yield ServiceError("Excluding video") return streams = self.http.request( "get", "http://playapi.mtgx.tv/v3/videos/stream/{0}".format(vid)) if streams.status_code == 403: yield ServiceError( "Can't play this because the video is geoblocked.") return streamj = json.loads(streams.text) if "msg" in streamj: yield ServiceError( "Can't play this because the video is either not found or geoblocked." ) return if dataj["sami_path"]: if dataj["sami_path"].endswith("vtt"): subtype = "wrst" else: subtype = "sami" yield subtitle(copy.copy(self.options), subtype, dataj["sami_path"]) if dataj["subtitles_webvtt"]: yield subtitle(copy.copy(self.options), "wrst", dataj["subtitles_webvtt"]) if dataj["subtitles_for_hearing_impaired"]: if dataj["subtitles_for_hearing_impaired"].endswith("vtt"): subtype = "wrst" else: subtype = "sami" if self.options.get_all_subtitles: yield subtitle(copy.copy(self.options), subtype, dataj["subtitles_for_hearing_impaired"], "-SDH") else: yield subtitle(copy.copy(self.options), subtype, dataj["subtitles_for_hearing_impaired"]) if streamj["streams"]["medium"]: filename = streamj["streams"]["medium"] if ".f4m" in filename: streams = hdsparse( self.options, self.http.request("get", filename, params={"hdcore": "3.7.0"}), filename) if streams: for n in list(streams.keys()): yield streams[n] else: parse = urlparse(filename) match = re.search("^(/[^/]+)/(.*)", parse.path) if not match: yield ServiceError("Can't get rtmpparse info") return filename = "{0}://{1}:{2}{3}".format(parse.scheme, parse.hostname, parse.port, match.group(1)) path = "-y {0}".format(match.group(2)) self.options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf {0}".format( path) yield RTMP(copy.copy(self.options), filename, 800) if streamj["streams"]["hls"]: streams = hlsparse( self.options, self.http.request("get", streamj["streams"]["hls"]), streamj["streams"]["hls"]) if streams: for n in list(streams.keys()): yield streams[n]
def get(self): old = False parse = urlparse(self.url) if parse.netloc == "www.svtplay.se" or parse.netloc == "svtplay.se": if parse.path[:6] != "/video" and parse.path[:6] != "/klipp": yield ServiceError("This mode is not supported anymore. need the url with the video") return vid = self.find_video_id() if vid is None: yield ServiceError("Cant find video id for this video") return if re.match("^[0-9]+$", vid): old = True url = "http://www.svt.se/videoplayer-api/video/%s" % vid data = self.http.request("get", url) if data.status_code == 404: yield ServiceError("Can't get the json file for %s" % url) return data = data.json() if "live" in data: self.options.live = data["live"] if old: params = {"output": "json"} try: dataj = self.http.request("get", self.url, params=params).json() except ValueError: dataj = data old = False else: dataj = data if self.options.output_auto: self.options.service = "svtplay" self.options.output = self.outputfilename(dataj, self.options.output, ensure_unicode(self.get_urldata())) if self.exclude(): yield ServiceError("Excluding video") return if "subtitleReferences" in data: for i in data["subtitleReferences"]: if i["format"] == "websrt": yield subtitle(copy.copy(self.options), "wrst", i["url"]) if old and dataj["video"]["subtitleReferences"]: try: suburl = dataj["video"]["subtitleReferences"][0]["url"] except KeyError: pass if suburl and len(suburl) > 0: yield subtitle(copy.copy(self.options), "wrst", suburl) if len(data["videoReferences"]) == 0: yield ServiceError("Media doesn't have any associated videos (yet?)") return for i in data["videoReferences"]: if i["format"] == "hls" or i["format"] == "ios": streams = hlsparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if i["format"] == "hds" or i["format"] == "flash": match = re.search(r"\/se\/secure\/", i["url"]) if not match: streams = hdsparse(self.options, self.http.request("get", i["url"], params={"hdcore": "3.7.0"}), i["url"]) if streams: for n in list(streams.keys()): yield streams[n] if i["format"] == "dash264": streams = dashparse(self.options, self.http.request("get", i["url"]), i["url"]) if streams: for n in list(streams.keys()): yield streams[n]