Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from streamlink.stream import HLSStream
from streamlink.utils import update_scheme
from colorama import init, Fore, Back, Style
from termcolor import colored
import ConfigParser
config = ConfigParser.ConfigParser()
config.read('config.cfg')
init()
CONST_AMF_GATEWAY_LOCATION = '/tools/amf.php'
CONST_AMF_GATEWAY_PARAM = 'x-country'
CONST_DEFAULT_COUNTRY_CODE = 'en'
CONST_HEADERS = {}
CONST_HEADERS['User-Agent'] = useragents.CHROME
url_re = re.compile(r"(http(s)?://)?(\w{2}.)?(bongacams\.com)/([\w\d_-]+)")
amf_msg_schema = validate.Schema({
"status": "success",
"userData": {
"username": validate.text
},
"localData": {
"videoServerUrl": validate.text
},
"performerData": {
"username": validate.text,
}
})
def _get_streams(self):
headers = {
'User-Agent': useragents.CHROME,
'Referer': self.url
}
res = self.session.http.get(self.url, headers=headers)
match = _playlist_re.search(res.text)
if match is None:
return
url = match.group('url')
if url:
self.logger.debug('HLS URL: {0}'.format(url))
yield 'live', HLSStream(self.session, url, headers=headers)
def _get_streams(self):
user = self.login(self.options.get("email"), self.options.get("password"))
if user:
log.debug("Logged in to Schoolism as {0}", user)
res = self.session.http.get(self.url, headers={"User-Agent": useragents.SAFARI_8})
lesson_playlist = self.playlist_schema.validate(res.text)
part = self.options.get("part")
video_type = "Lesson" if "lesson" in self.url_re.match(self.url).group(1).lower() else "Assignment Feedback"
log.info("Attempting to play {0} Part {1}", video_type, part)
found = False
# make request to key-time api, to get key specific headers
_ = self.session.http.get(self.key_time_url, headers={"User-Agent": useragents.SAFARI_8})
for i, video in enumerate(lesson_playlist, 1):
if video["sources"] and i == part:
found = True
for source in video["sources"]:
if source['type'] == "video/mp4":
def _get_streams(self):
url_m = self._url_re.match(self.url)
domain = url_m.group(1) or url_m.group(2) or url_m.group(3)
# remap the domain to channel
channel = {"atv": "atvhd",
"ahaber": "ahaberhd",
"apara": "aparahd",
"aspor": "asporhd",
"anews": "anewshd",
"minikacocuk": "minikagococuk"}.get(domain, domain)
hls_url = self._hls_url.format(channel=channel)
# get the secure HLS URL
res = self.session.http.get(self._token_url,
params="url={0}".format(hls_url),
headers={"Referer": self.url,
"User-Agent": useragents.CHROME})
secure_hls_url = self.session.http.json(res, schema=self._token_schema)
self.logger.debug("Found HLS URL: {0}".format(secure_hls_url))
return HLSStream.parse_variant_playlist(self.session, secure_hls_url)
''', re.VERBOSE)
_video_id_re = re.compile(r'(\bdata-video="|[0-9]+k)\.mp4')
_api_schema = validate.Schema({
'ID_DM': validate.text,
'TYPE': validate.text,
'MEDIA': validate.Schema({
'VIDEOS': validate.Schema({
validate.text: validate.any(
validate.url(),
''
)
})
})
})
_user_agent = useragents.CHROME
@classmethod
def can_handle_url(cls, url):
return CanalPlus._url_re.match(url)
def _get_streams(self):
# Get video ID and channel from URL
match = self._url_re.match(self.url)
video_id = match.group('video_id')
if video_id is None:
# Retrieve URL page and search for video ID
res = self.session.http.get(self.url)
match = self._video_id_re.search(res.text)
if match is None:
return
video_id = match.group('video_id')
def _get_streams(self):
self.session.http.headers.update({"User-Agent": useragents.FIREFOX})
res = self.session.http.get(self.url)
for script in itertags(res.text, 'script'):
if script.attributes.get("id") == "playerScript":
log.debug("Found the playerScript script tag")
urlparts = urlparse(script.attributes.get("src"))
i = 0
for key, url in parse_qsl(urlparts.query):
if key == "streamUrl":
i += 1
for s in HLSStream.parse_variant_playlist(self.session, url, params=dict(id=i), verify=False).items():
yield s
def _get_streams(self):
if "eltrecetv.com.ar/vivo" in self.url.lower():
try:
self.session.http.headers = {'Referer': self.url,
'User-Agent': useragents.ANDROID}
res = self.session.http.get('https://api.iamat.com/metadata/atcodes/eltrece')
yt_id = parse_json(res.text)["atcodes"][0]["context"]["ahora"]["vivo"]["youtubeVideo"]
yt_url = "https://www.youtube.com/watch?v={0}".format(yt_id)
return self.session.streams(yt_url)
except BaseException:
self.logger.info("Live content is temporarily unavailable. Please try again later.")
else:
try:
self.session.http.headers = {'Referer': self.url,
'User-Agent': useragents.CHROME}
res = self.session.http.get(self.url)
_player_re = re.compile(r'''data-kaltura="([^"]+)"''')
match = _player_re.search(res.text)
if not match:
return
entry_id = parse_json(match.group(1).replace(""", '"'))["entryId"]
hls_url = "https://vodgc.com/p/111/sp/11100/playManifest/entryId/{0}/format/applehttp/protocol/https/a.m3u8".format(entry_id)
return HLSStream.parse_variant_playlist(self.session, hls_url)
except BaseException:
self.logger.error("The requested VOD content is unavailable.")
def __init__(self, url):
super(YouTube, self).__init__(url)
parsed = urlparse(self.url)
if parsed.netloc == 'gaming.youtube.com':
self.url = urlunparse(parsed._replace(netloc='www.youtube.com'))
self.author = None
self.title = None
self.video_id = None
self.session.http.headers.update({'User-Agent': useragents.CHROME})
def _get_streams(self):
page = self.session.http.get(self.url,
allow_redirects=True,
headers={"User-Agent": useragents.IPHONE_6})
videomatch = self._video_re.search(page.text)
if not videomatch:
log.error("No playlist found.")
return
videourl = videomatch.group(1)
log.debug("URL={0}".format(videourl))
yield "live", HLSStream(self.session, videourl)
def _get_streams(self):
match = _url_re.match(self.url)
channel = match.group("channel")
self.session.http.headers.update({"User-Agent": useragents.IPAD})
# Some problem with SSL on huya.com now, do not use https
hls_url = self.session.http.get(HUYA_URL % channel, schema=_hls_schema)
yield "live", HLSStream(self.session, update_scheme("http://", hls_url))