def _get_streams(self): res = self.session.http.get(self.url) m = self._playback_re.search(res.text) if m: hls_url = m.group(0) if is_py3: hls_url = bytes(unquote_plus(hls_url), "utf-8").decode("unicode_escape") else: hls_url = unquote_plus(hls_url).decode("unicode_escape") else: if self._livestream_re.search(res.text) is not None: raise PluginError('Stream is offline') m = self._username_re.search(res.text) if m: hls_url = "https://live.prd.dlive.tv/hls/live/{}.m3u8".format( m.group(0)) else: raise PluginError('Could not find username') return HLSStream.parse_variant_playlist(self.session, hls_url)
def _parse_streams(self, res): for match in self._src_re.finditer(res.text): stream_url = match.group("url") if "\\/" in stream_url: # if the URL is json encoded, decode it stream_url = parse_json("\"{}\"".format(stream_url)) if ".mpd" in stream_url: for s in DASHStream.parse_manifest(self.session, stream_url).items(): yield s elif ".mp4" in stream_url: yield match.group(1), HTTPStream(self.session, stream_url) else: log.debug("Non-dash/mp4 stream: {0}".format(stream_url)) match = self._dash_manifest_re.search(res.text) if match: # facebook replaces "<" characters with the substring "\\x3C" manifest = match.group("manifest").replace("\\/", "/") if is_py3: manifest = bytes(unquote_plus(manifest), "utf-8").decode("unicode_escape") else: manifest = unquote_plus(manifest).decode("string_escape") # Ignore unsupported manifests until DASH SegmentBase support is implemented if "SegmentBase" in manifest: log.error("Skipped DASH manifest with SegmentBase streams") else: for s in DASHStream.parse_manifest(self.session, manifest).items(): yield s
def parse_proxy_url(purl): proxy_options = {} if purl: p = urlparse(purl) proxy_options['proxy_type'] = p.scheme proxy_options['http_proxy_host'] = p.hostname if p.port: proxy_options['http_proxy_port'] = p.port if p.username: proxy_options['http_proxy_auth'] = (unquote_plus(p.username), unquote_plus(p.password or "")) return proxy_options
def parse_proxy_url(purl): """Adapted from UStreamTV plugin (ustreamtv.py)""" proxy_options = {} if purl: p = urlparse(purl) proxy_options['proxy_type'] = p.scheme proxy_options['http_proxy_host'] = p.hostname if p.port: proxy_options['http_proxy_port'] = p.port if p.username: proxy_options['http_proxy_auth'] = \ (unquote_plus(p.username), unquote_plus(p.password or "")) return proxy_options
def _parse_streams(self, res): _found_stream_url = False for meta in itertags(res.text, "meta"): if meta.attributes.get("property") == "og:video:url": stream_url = html_unescape(meta.attributes.get("content")) if ".mpd" in stream_url: for s in DASHStream.parse_manifest(self.session, stream_url).items(): yield s _found_stream_url = True elif ".mp4" in stream_url: yield "vod", HTTPStream(self.session, stream_url) _found_stream_url = True break else: log.debug("No meta og:video:url") if _found_stream_url: return for match in self._src_re.finditer(res.text): stream_url = match.group("url") if "\\/" in stream_url: # if the URL is json encoded, decode it stream_url = parse_json("\"{}\"".format(stream_url)) if ".mpd" in stream_url: for s in DASHStream.parse_manifest(self.session, stream_url).items(): yield s elif ".mp4" in stream_url: yield match.group(1), HTTPStream(self.session, stream_url) else: log.debug("Non-dash/mp4 stream: {0}".format(stream_url)) match = self._dash_manifest_re.search(res.text) if match: # facebook replaces "<" characters with the substring "\\x3C" manifest = match.group("manifest").replace("\\/", "/") if is_py3: manifest = bytes(unquote_plus(manifest), "utf-8").decode("unicode_escape") else: manifest = unquote_plus(manifest).decode("string_escape") # Ignore unsupported manifests until DASH SegmentBase support is implemented if "SegmentBase" in manifest: log.error("Skipped DASH manifest with SegmentBase streams") else: for s in DASHStream.parse_manifest(self.session, manifest).items(): yield s
def _parse_streams(self, res): stream_url = validate.Schema( validate.parse_html(), validate.xml_xpath_string( ".//head/meta[@property='og:video:url'][@content][1]/@content") ).validate(res.text) if not stream_url: log.debug("No meta og:video:url") else: if ".mpd" in stream_url: for s in DASHStream.parse_manifest(self.session, stream_url).items(): yield s return elif ".mp4" in stream_url: yield "vod", HTTPStream(self.session, stream_url) return for match in self._src_re.finditer(res.text): stream_url = match.group("url") if "\\/" in stream_url: # if the URL is json encoded, decode it stream_url = parse_json("\"{}\"".format(stream_url)) if ".mpd" in stream_url: for s in DASHStream.parse_manifest(self.session, stream_url).items(): yield s elif ".mp4" in stream_url: yield match.group(1), HTTPStream(self.session, stream_url) else: log.debug("Non-dash/mp4 stream: {0}".format(stream_url)) match = self._dash_manifest_re.search(res.text) if match: # facebook replaces "<" characters with the substring "\\x3C" manifest = match.group("manifest").replace("\\/", "/") if is_py3: manifest = bytes(unquote_plus(manifest), "utf-8").decode("unicode_escape") else: manifest = unquote_plus(manifest).decode("string_escape") # Ignore unsupported manifests until DASH SegmentBase support is implemented if "SegmentBase" in manifest: log.error("Skipped DASH manifest with SegmentBase streams") else: for s in DASHStream.parse_manifest(self.session, manifest).items(): yield s
def parse_proxy_url(purl): """ Credit: streamlink/plugins/ustreamtv.py:UHSClient:parse_proxy_url() """ proxy_options = {} if purl: p = urlparse(purl) proxy_options['proxy_type'] = p.scheme proxy_options['http_proxy_host'] = p.hostname if p.port: proxy_options['http_proxy_port'] = p.port if p.username: proxy_options['http_proxy_auth'] = (unquote_plus(p.username), unquote_plus(p.password or "")) return proxy_options
def __init__( self, session, # type: Streamlink url, # type: str subprotocols=None, # type: Optional[List[str]] header=None, # type: Optional[Union[List, Dict]] cookie=None, # type: Optional[str] sockopt=None, # type: Optional[Tuple] sslopt=None, # type: Optional[Dict] host=None, # type: Optional[str] origin=None, # type: Optional[str] suppress_origin=False, # type: bool ping_interval=0, # type: Union[int, float] ping_timeout=None, # type: Optional[Union[int, float]] ): if rootlogger.level <= TRACE: enableTrace(True, log) if not header: header = [] if not any(True for h in header if h.startswith("User-Agent: ")): header.append("User-Agent: {0}".format( session.http.headers['User-Agent'])) proxy_options = {} http_proxy = session.get_option("http-proxy") # type: Optional[str] if http_proxy: p = urlparse(http_proxy) proxy_options["proxy_type"] = p.scheme proxy_options["http_proxy_host"] = p.hostname if p.port: # pragma: no branch proxy_options["http_proxy_port"] = p.port if p.username: # pragma: no branch proxy_options["http_proxy_auth"] = unquote_plus( p.username), unquote_plus(p.password or "") self._reconnect = False self._reconnect_lock = RLock() self.session = session self._ws_init(url, subprotocols, header, cookie) self._ws_rundata = dict(sockopt=sockopt, sslopt=sslopt, host=host, origin=origin, suppress_origin=suppress_origin, ping_interval=ping_interval, ping_timeout=ping_timeout, **proxy_options) self._id += 1 super(WebsocketClient, self).__init__( name="Thread-{0}-{1}".format(self.__class__.__name__, self._id)) self.daemon = True