Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_streams(self):
parsed = urlparse(self.url)
cls = PROTOCOL_MAP.get(parsed.scheme)
if not cls:
return
split = self.url.split(" ")
url = split[0]
urlnoproto = SCHEME_REGEX.match(url).group(1)
# Prepend http:// if needed.
if cls != RTMPStream and not SCHEME_REGEX.match(urlnoproto):
urlnoproto = "http://{0}".format(urlnoproto)
params = " ".join(split[1:])
params = self._parse_params(params)
def follow_vk_redirect(cls, url):
# If this is a 'videos' catalog URL
# with an video ID in the GET request, get that instead
parsed_url = urlparse(url)
if parsed_url.path.startswith('/videos'):
query = dict((v[0], v[1]) for v in [q.split('=') for q in parsed_url.query.split('&')] if v[0] == 'z')
try:
true_path = unquote(query['z']).split('/')[0]
return parsed_url.scheme + '://' + parsed_url.netloc + '/' + true_path
except KeyError:
# No redirect found in query string,
# so return the catalog url and fail later
return url
else:
return url
# get cookies
r = self.session.http.get(urlunparse((stream_page_scheme, stream_page_domain, stream_page_path, '', '', '')))
# redirect to profile page means stream is offline
if '/profile/' in r.url:
raise NoStreamsError(self.url)
if not r.ok:
self.logger.debug("Status code for {0}: {1}", r.url, r.status_code)
raise NoStreamsError(self.url)
if len(self.session.http.cookies) == 0:
raise PluginError("Can't get a cookies")
if urlparse(r.url).netloc != stream_page_domain:
# then redirected to regional subdomain
country_code = urlparse(r.url).netloc.split('.')[0].lower()
# time to set variables
baseurl = urlunparse((stream_page_scheme, urlparse(r.url).netloc, '', '', '', ''))
amf_gateway_url = urljoin(baseurl, CONST_AMF_GATEWAY_LOCATION)
stream_page_url = urljoin(baseurl, stream_page_path)
headers = {
'User-Agent': useragents.CHROME,
'Referer': stream_page_url,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Requested-With': 'XMLHttpRequest'
}
data = 'method=getRoomData&args%5B%5D={0}&args%5B%5D=false'.format(stream_page_path)
self.logger.debug('DATA: {0}'.format(str(data)))
# send request and close http-session
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
}
streams[name] = RTMPStream(self.session, params)
parsed_urls = set()
mobileurls_el = parsed_info.find("mobileurls")
if mobileurls_el is not None:
for mobileurl_el in mobileurls_el:
text = mobileurl_el.text
if not text:
continue
if text in parsed_urls:
continue
parsed_urls.add(text)
url = urlparse(text)
if url[0] == "http" and url[2].endswith("m3u8"):
streams.update(HLSStream.parse_variant_playlist(self.session, text))
return streams
def uri(self, uri):
if uri and urlparse(uri).scheme:
return uri
elif self.base_uri and uri:
return urljoin(self.base_uri, uri)
else:
return uri
def arglist_from_query(path):
old_data = parse_qsl(urlparse(path).query)
arglist = []
for k, v in old_data:
if k == 'q':
# backwards compatibility --q
k = 'default-stream'
arglist += ['--{0}'.format(unquote(k)), unquote(v)]
return arglist
def settings_url(self):
o = urlparse(self.url)
# SSL Verification - http.verify
http_verify = [
'.cdn.bg',
'sportal.bg',
]
if (o.netloc.endswith(tuple(http_verify)) and self.session.http.verify):
self.session.http.verify = False
log.warning('SSL Verification disabled.')
# http://www.latina.pe/tvenvivo
if (o.netloc.endswith('latina.pe') and o.path.startswith('/tvenvivo')):
self.session.http.get(self.url)