}, "start_offset": int, "end_offset": int, }) _viewer_info_schema = validate.Schema( {validate.optional("login"): validate.text}, validate.get("login")) _viewer_token_schema = validate.Schema( {validate.optional("token"): validate.text}, validate.get("token")) _quality_options_schema = validate.Schema( { "quality_options": validate.all([{ "quality": validate.any(validate.text, None), "source": validate.url(scheme="https", path=validate.endswith(".mp4")) }]) }, validate.get("quality_options")) class UsherService(object): def _create_url(self, endpoint, **extra_params): url = "https://usher.ttvnw.net{0}".format(endpoint) params = { "player": "twitchweb", "p": int(random() * 999999), "type": "any", "allow_source": "true", "allow_audio_only": "true", "allow_spectre": "false", }
validate.optional("code"): validate.text, validate.optional("message"): validate.text, validate.optional("data"): object, }) _media_schema = validate.Schema( { "stream_data": validate.any( None, { "streams": validate.all([{ "quality": validate.any(validate.text, None), "url": validate.url(scheme="http", path=validate.endswith(".m3u8")), validate.optional("video_encode_id"): validate.text }]) }) }, validate.get("stream_data")) _login_schema = validate.Schema({ "auth": validate.text, "expires": validate.all(validate.text, validate.transform(parse_timestamp)), "user": { "username": validate.any(validate.text, None), "email": validate.text } })
def test_endswith(self): assert validate(endswith(u"åäö"), u"xyzåäö")
_swf_url_re = re.compile(r"swfobject.embedSWF\(\"([^\"]+)\",") _schema = validate.Schema( validate.union({ "urls": validate.all(validate.transform(_file_re.findall), validate.map(unquote), [validate.url()]), "swf": validate.all( validate.transform(_swf_url_re.search), validate.any( None, validate.all( validate.get(1), validate.url(scheme="http", path=validate.endswith("swf"))))) })) class Aliez(Plugin): @classmethod def can_handle_url(self, url): return _url_re.match(url) def _get_streams(self): res = http.get(self.url, schema=_schema) streams = {} for url in res["urls"]: parsed = urlparse(url) if parsed.scheme.startswith("rtmp"): params = {"rtmp": url, "pageUrl": self.url, "live": True}
COOKIE_PARAMS = ("devicetype=desktop&" "preferred-player-odm=hlslink&" "preferred-player-live=hlslink") _id_re = re.compile(r"/(?:program|direkte|serie/[^/]+)/([^/]+)") _url_re = re.compile(r"https?://(tv|radio).nrk.no/") _api_baseurl_re = re.compile(r'''apiBaseUrl:\s*["'](?P<baseurl>[^"']+)["']''') _schema = validate.Schema( validate.transform(_api_baseurl_re.search), validate.any( None, validate.all(validate.get("baseurl"), validate.url(scheme="http")))) _mediaelement_schema = validate.Schema( {"mediaUrl": validate.url(scheme="http", path=validate.endswith(".m3u8"))}) class NRK(Plugin): @classmethod def can_handle_url(self, url): return _url_re.match(url) def _get_streams(self): # Get the stream type from the url (tv/radio). stream_type = _url_re.match(self.url).group(1).upper() cookie = {"NRK_PLAYER_SETTINGS_{0}".format(stream_type): COOKIE_PARAMS} # Construct API URL for this program. baseurl = http.get(self.url, cookies=cookie, schema=_schema) program_id = _id_re.search(self.url).group(1)
SWF_URL = "http://play.streamingvideoprovider.com/player2.swf" API_URL = "http://player.webvideocore.net/index.php" _url_re = re.compile( r"http(s)?://(\w+\.)?streamingvideoprovider.co.uk/(?P<channel>[^/&?]+)") _hls_re = re.compile(r"'(http://.+\.m3u8)'") _rtmp_schema = validate.Schema(validate.xml_findtext("./info/url"), validate.url(scheme="rtmp")) _hls_schema = validate.Schema( validate.transform(_hls_re.search), validate.any( None, validate.all( validate.get(1), validate.url(scheme="http", path=validate.endswith("m3u8"))))) class Streamingvideoprovider(Plugin): @classmethod def can_handle_url(self, url): return _url_re.match(url) def _get_hls_stream(self, channel_name): params = { "l": "info", "a": "ajax_video_info", "file": channel_name, "rid": time() } playlist_url = http.get(API_URL, params=params, schema=_hls_schema)