def find_all_episodes(self, options): parse = urlparse(self.url) show = parse.path[parse.path.find("/", 1)+1:] if not re.search("%", show): show = quote_plus(show) error, data = get_http_data("http://webapi.tv4play.se/play/video_assets?type=episode&is_live=false&platform=web&node_nids=%s&per_page=99999" % show) if error: log.error("Can't get api page") return jsondata = json.loads(data) episodes = [] n = 1 for i in jsondata["results"]: try: days = int(i["availability"]["availability_group_free"]) except (ValueError, TypeError): days = 999 if days > 0: video_id = i["id"] url = "http://www.tv4play.se/program/%s?video_id=%s" % ( show, video_id) episodes.append(url) if n == options.all_last: break n += 1 return episodes
def _get_static_video(self, options, videoid): access = self._get_access_token(videoid) if options.output_auto: data = self.http.request( "get", "https://api.twitch.tv/kraken/videos/v%s" % videoid) if data.status_code == 404: yield ServiceError("Can't find the video") return info = json.loads(data.text) name = "twitch-%s-%s" % (info["channel"]["name"], filenamify(info["title"])) directory = os.path.dirname(options.output) if os.path.isdir(directory): name = os.path.join(directory, name) options.output = name if "token" not in access: raise TwitchUrlException('video', self.url) nauth = quote_plus(str(access["token"])) authsig = access["sig"] url = "http://usher.twitch.tv/vod/%s?nauth=%s&nauthsig=%s" % ( videoid, nauth, authsig) streams = hlsparse(options, self.http.request("get", url), url) if streams: for n in list(streams.keys()): yield streams[n]
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(r'href="(/sida/[\.\/=a-z0-9&;\?]+\d+)" aria-label', data) if not match: log.error("Can't find audio info") return path = quote_plus(match.group(1)) dataurl = "http://sverigesradio.se/sida/ajax/getplayerinfo?url=%s&isios=false&playertype=html5" % path error, data = get_http_data(dataurl) if error: log.error("Cant get stream info") return playerinfo = json.loads(data)["playerInfo"] for i in playerinfo["AudioSources"]: url = i["Url"] if not url.startswith('http'): url = 'http:%s' % url yield HTTP(copy.copy(options), url, i["Quality"]/1000)
def _get_static_video(self, options, videoid): access = self._get_access_token(videoid) if options.output_auto: data = self.http.request("get", "https://api.twitch.tv/kraken/videos/v%s" % videoid) if data.status_code == 404: yield ServiceError("Can't find the video") return info = json.loads(data.text) name = "twitch-%s-%s" % (info["channel"]["name"], filenamify(info["title"])) directory = os.path.dirname(options.output) if os.path.isdir(directory): name = os.path.join(directory, name) options.output = name if "token" not in access: raise TwitchUrlException('video', self.url) nauth = quote_plus(str(access["token"])) authsig = access["sig"] url = "http://usher.twitch.tv/vod/%s?nauth=%s&nauthsig=%s" % ( videoid, nauth, authsig) streams = hlsparse(options, self.http.request("get", url), url) if streams: for n in list(streams.keys()): yield streams[n]
def _get_show_info(self): parse = urlparse(self.url) show = parse.path[parse.path.find("/", 1)+1:] if not re.search("%", show): show = quote_plus(show) data = self.http.request("get", "http://webapi.tv4play.se/play/video_assets?type=episode&is_live=false&platform=web&node_nids=%s&per_page=99999" % show).text jsondata = json.loads(data) return jsondata
def _get_showname(self, url): parse = urlparse(self.url) if parse.path.count("/") > 2: match = re.search("^/([^/]+)/", parse.path) show = match.group(1) else: show = parse.path[parse.path.find("/", 1)+1:] if not re.search("%", show): show = quote_plus(show) return show
def _get_showname(self, url): parse = urlparse(self.url) if parse.path.count("/") > 2: match = re.search("^/([^/]+)/", parse.path) show = match.group(1) else: show = parse.path[parse.path.find("/", 1) + 1:] if not re.search("%", show): if is_py2 and isinstance(show, unicode): show = show.encode("utf-8") show = quote_plus(show) return show
def _get_showname(self, url): parse = urlparse(self.url) if parse.path.count("/") > 2: match = re.search("^/([^/]+)/", parse.path) show = match.group(1) else: show = parse.path[parse.path.find("/", 1)+1:] if not re.search("%", show): if is_py2 and isinstance(show, unicode): show = show.encode("utf-8") show = quote_plus(show) return show
def get(self, options): match = re.search(r'href="(/sida/[\.\/=a-z0-9&;\?]+\d+)" aria-label', self.get_urldata()) if not match: log.error("Can't find audio info") sys.exit(2) path = quote_plus(match.group(1)) dataurl = "http://sverigesradio.se/sida/ajax/getplayerinfo?url=%s&isios=false&playertype=html5" % path data = get_http_data(dataurl) playerinfo = json.loads(data)["playerInfo"] for i in playerinfo["AudioSources"]: url = i["Url"] if not url.startswith('http'): url = 'http:%s' % url yield HTTP(copy.copy(options), url, i["Quality"])
def find_all_episodes(self, options): parse = urlparse(self.url) show = quote_plus(parse.path[parse.path.find("/", 1)+1:]) data = get_http_data("http://webapi.tv4play.se/play/video_assets?type=episode&is_live=false&platform=web&node_nids=%s&per_page=99999" % show) jsondata = json.loads(data) episodes = [] for i in jsondata["results"]: try: days = int(i["availability"]["availability_group_free"]) except ValueError: days = 999 if days > 0: id = i["id"] url = "http://www.tv4play.se/program/%s?video_id=%s" % (show, id) episodes.append(url) return sorted(episodes)
def find_all_episodes(self, options): parse = urlparse(self.url) show = parse.path[parse.path.find("/", 1)+1:] if not re.search("%", show): show = quote_plus(show) data = get_http_data("http://webapi.tv4play.se/play/video_assets?type=episode&is_live=false&platform=web&node_nids=%s&per_page=99999" % show) jsondata = json.loads(data) episodes = [] for i in jsondata["results"]: try: days = int(i["availability"]["availability_group_free"]) except ValueError: days = 999 if days > 0: video_id = i["id"] url = "http://www.tv4play.se/program/%s?video_id=%s" % ( show, video_id) episodes.append(url) return sorted(episodes)
def get(self): data = self.get_urldata() if self.exclude(self.options): yield ServiceError("Excluding video") return match = re.search(r'href="(/sida/[\.\/=a-z0-9&;\?]+play(?:audio|episode)=\d+)"', data) if not match: yield ServiceError("Can't find audio info") return path = quote_plus(match.group(1)) dataurl = "http://sverigesradio.se/sida/ajax/getplayerinfo?url=%s&isios=false&playertype=html5" % path data = self.http.request("get", dataurl).text playerinfo = json.loads(data)["playerInfo"] for i in playerinfo["AudioSources"]: url = i["Url"] if not url.startswith('http'): url = 'http:%s' % url yield HTTP(copy.copy(self.options), url, i["Quality"]/1000)
def get(self): data = self.get_urldata() if self.exclude(): yield ServiceError("Excluding video") return match = re.search(r'href="(/sida/[\.\/=a-z0-9&;\?]+play(?:audio|episode)=\d+)"', data) if not match: yield ServiceError("Can't find audio info") return path = quote_plus(match.group(1)) dataurl = "http://sverigesradio.se/sida/ajax/getplayerinfo?url=%s&isios=false&playertype=html5" % path data = self.http.request("get", dataurl).text playerinfo = json.loads(data)["playerInfo"] for i in playerinfo["AudioSources"]: url = i["Url"] if not url.startswith('http'): url = 'http:%s' % url yield HTTP(copy.copy(self.options), url, i["Quality"]/1000)
def _get_static_video(self, options, videoid): access = self._get_access_token(videoid) if options.output_auto: info = json.loads(get_http_data("https://api.twitch.tv/kraken/videos/v%s" % videoid)[1]) if info["description"]: options.output = "twitch-%s-%s_%s" % (info["channel"]["name"], filenamify(info["title"]), filenamify(info["description"])) else: options.output = "twitch-%s-%s" % (info["channel"]["name"], filenamify(info["title"])) if "token" not in access: raise JustinUrlException('video', self.url) nauth = quote_plus(str(access["token"])) authsig = access["sig"] url = "http://usher.twitch.tv/vod/%s?nauth=%s&nauthsig=%s" % ( videoid, nauth, authsig) streams = hlsparse(url) if streams: for n in list(streams.keys()): yield HLS(copy.copy(options), streams[n], n)
def _get_hls_url(self, channel): access = self._get_access_token(channel, "channels") query = "token=%s&sig=%s&allow_source=true&allow_spectre=true" % ( quote_plus(access['token']), access['sig']) return "%s/%s.m3u8?%s" % (self.hls_base_url, channel, query)
def get(self, options): error, data = self.get_urldata() if error: log.error("Can't get the page") return vid = findvid(self.url, data) if vid is None: log.error("Can't find video id for %s", self.url) return if options.username and options.password: # Need a dummy cookie to save cookies.. cc = Cookie(version=0, name='dummy', value="", port=None, port_specified=False, domain='www.tv4play.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 error, data = get_http_data("https://www.tv4play.se/session/new?https=", cookiejar=self.cj) auth_token = re.search('name="authenticity_token" ([a-z]+="[^"]+" )?value="([^"]+)"', data) if not auth_token: log.error("Can't find authenticity_token needed for user / passwdord") return url = "https://www.tv4play.se/session" postdata3 = quote_plus("user_name=%s&password=%s&authenticity_token=%s" % (options.username, options.password, auth_token.group(2)), "=&") error, data = get_http_data(url, post=postdata3, cookiejar=self.cj) fail = re.search("<p class='failed-login'>([^<]+)</p>", data) if fail: log.error(fail.group(1)) return url = "http://premium.tv4play.se/api/web/asset/%s/play" % vid error, data = get_http_data(url, cookiejar=self.cj) if error: xml = ET.XML(data) code = xml.find("code").text if code == "SESSION_NOT_AUTHENTICATED": log.error("Can't access premium content") elif code == "ASSET_PLAYBACK_INVALID_GEO_LOCATION": log.error("Can't downoad this video because of geoblocked.") else: log.error("Can't find any info for that video") return xml = ET.XML(data) 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": log.error("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 = "%s/%s" % (directory, title) else: options.output = title if self.exclude(options): 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), 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 error, data = get_http_data(url, cookiejar=self.cj) if error: return 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) for n in list(streams.keys()): yield HLS(copy.copy(options), streams[n], n)
def _get_hls_url(self, channel): access = self._get_access_token(channel, "channels") query = "token=%s&sig=%s" % (quote_plus(access['token']), access['sig']) return "%s/%s.m3u8?%s" % (self.hls_base_url, channel, query)
def _get_hls_url(self, channel): access = self._get_access_token(channel, "channels") query = "token={0}&sig={1}&allow_source=true&allow_spectre=true".format( quote_plus(access['token']), access['sig']) return "{0}/{1}.m3u8?{2}".format(self.hls_base_url, channel, query)
def _get_hls_url(self, channel): access = self._get_access_token(channel, "channels") query = "token={0}&sig={1}&allow_source=true&allow_spectre=true".format(quote_plus(access['token']), access['sig']) return "{0}/{1}.m3u8?{2}".format(self.hls_base_url, channel, query)