Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init(self):
"""Descramble the stream data and build Stream instances.
The initialization process takes advantage of Python's
"call-by-reference evaluation," which allows dictionary transforms to
be applied in-place, instead of holding references to mutations at each
interstitial step.
:rtype: None
"""
logger.info('init started')
self.vid_info = {k: v for k, v in parse_qsl(self.vid_info)}
if self.age_restricted:
self.player_config_args = self.vid_info
else:
self.player_config_args = extract.get_ytplayer_config(
self.watch_html,
)['args']
# Fix for KeyError: 'title' issue #434
if 'title' not in self.player_config_args:
i_start = (
self.watch_html
.lower()
.index('<title>') + len('<title>')
)
i_end = self.watch_html.lower().index('</title>')
title = self.watch_html[i_start:i_end].strip()
:param dict dct:
Dictionary containing query string encoded values.
:param str key:
Name of the key in dictionary.
**Example**:
>>> d = {'foo': 'bar=1&var=test,em=5&t=url%20encoded'}
>>> apply_descrambler(d, 'foo')
>>> print(d)
{'foo': [{'bar': '1', 'var': 'test'}, {'em': '5', 't': 'url encoded'}]}
"""
stream_data[key] = [
{k: unquote(v) for k, v in parse_qsl(i)}
for i in stream_data[key].split(',')
]
logger.debug(
'applying descrambler\n%s',
pprint.pformat(stream_data[key], indent=2),
)
>>> d = {'foo': 'bar=1&var=test,em=5&t=url%20encoded'}
>>> apply_descrambler(d, 'foo')
>>> print(d)
{'foo': [{'bar': '1', 'var': 'test'}, {'em': '5', 't': 'url encoded'}]}
"""
if key == 'url_encoded_fmt_stream_map' and not stream_data.get('url_encoded_fmt_stream_map'):
formats = json.loads(stream_data['player_response'])['streamingData']['formats']
formats.extend(json.loads(stream_data['player_response'])['streamingData']['adaptiveFormats'])
stream_data[key] = [{u'url': format_item[u'url'],
u'type': format_item[u'mimeType'],
u'quality': format_item[u'quality'],
u'itag': format_item[u'itag']} for format_item in formats]
else:
stream_data[key] = [
{k: unquote(v) for k, v in parse_qsl(i)}
for i in stream_data[key].split(',')
]
PLog(
'applying descrambler\n%s')
# 14.05.2020 für Addon nicht benötigt:
def init(self):
"""Descramble the stream data and build Stream instances.
The initialization process takes advantage of Python's
"call-by-reference evaluation," which allows dictionary transforms to
be applied in-place, instead of holding references to mutations at each
interstitial step.
:rtype: None
"""
logger.info('init started')
self.vid_info = {k: v for k, v in parse_qsl(self.vid_info)}
if self.age_restricted:
self.player_config_args = self.vid_info
else:
self.player_config_args = extract.get_ytplayer_config(
self.watch_html,
)['args']
self.vid_descr = extract.get_vid_descr(self.watch_html)
# https://github.com/nficano/pytube/issues/165
stream_maps = ['url_encoded_fmt_stream_map']
if 'adaptive_fmts' in self.player_config_args:
stream_maps.append('adaptive_fmts')
# unscramble the progressive and adaptive stream manifests.
for fmt in stream_maps:
if not self.age_restricted and fmt in self.vid_info:
def init(self):
"""Descramble the stream data and build Stream instances.
The initialization process takes advantage of Python's
"call-by-reference evaluation," which allows dictionary transforms to
be applied in-place, instead of holding references to mutations at each
interstitial step.
:rtype: None
"""
PLog('init YouTube started')
self.vid_info = {k: v for k, v in parse_qsl(self.vid_info)}
if self.age_restricted:
self.player_config_args = self.vid_info
else:
self.player_config_args = extract.get_ytplayer_config(
self.watch_html,
)['args']
# Fix for KeyError: 'title' issue #434
if 'title' not in self.player_config_args:
i_start = (
self.watch_html
.lower()
.index('<title>') + len('<title>')
)
i_end = self.watch_html.lower().index('</title>')
title = self.watch_html[i_start:i_end].strip()