Skip to content

Commit

Permalink
Merge StreamInfo._get_player_page into StreamInfo._get_player_config
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Dec 7, 2024
1 parent e1495d7 commit 1bee383
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions resources/lib/youtube_plugin/youtube/helper/stream_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ def _get_stream_format(self, itag, info=None, max_height=None, **kwargs):
))
return yt_format

def _get_player_page(self, client_name='web', embed=False):
def _get_player_config(self, client_name='web', embed=False):
if embed:
url = ''.join(('https://www.youtube.com/embed/', self.video_id))
else:
Expand All @@ -970,7 +970,16 @@ def _get_player_page(self, client_name='web', embed=False):
'auth': False,
},
)
return result
if not result:
return None

# pattern source is from youtube-dl
# https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L313
# LICENSE: The Unlicense
match = re_compile(r'ytcfg\.set\s*\(\s*({.+?})\s*\)\s*;').search(result)
if match:
return json_loads(match.group(1))
return None

@staticmethod
def _get_player_client(config):
Expand All @@ -990,28 +999,14 @@ def _get_player_key(self, html):
return player_key
return None

@staticmethod
def _get_player_config(page_text):
if not page_text:
return None

# pattern source is from youtube-dl
# https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L313
# LICENSE: The Unlicense
match = re_compile(r'ytcfg\.set\s*\(\s*({.+?})\s*\)\s*;').search(page_text)
if match:
return json_loads(match.group(1))
return None

def _get_player_js(self):
data_cache = self._context.get_data_cache()
cached = data_cache.get_item('player_js_url', data_cache.ONE_HOUR * 4)
cached = cached and cached.get('url', '')
js_url = cached if cached not in {'', 'http://', 'https://'} else None

if not js_url:
player_page_text = self._get_player_page()
player_config = self._get_player_config(player_page_text)
player_config = self._get_player_config()
if not player_config:
return ''
js_url = player_config.get('PLAYER_JS_URL')
Expand Down

0 comments on commit 1bee383

Please sign in to comment.