Skip to content

Commit

Permalink
Merge pull request #9 from anxdpanic/pr_isengard
Browse files Browse the repository at this point in the history
  • Loading branch information
anxdpanic authored Sep 13, 2020
2 parents 2735a42 + a1f4ed4 commit 5d4bc2f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.youtube" name="YouTube" version="6.8.4" provider-name="anxdpanic, bromix">
<addon id="plugin.video.youtube" name="YouTube" version="6.8.5~beta1" provider-name="anxdpanic, bromix">
<requires>
<import addon="xbmc.python" version="2.20.0"/>
<import addon="script.module.six" version="1.11.0"/>
Expand All @@ -16,6 +16,7 @@
[fix] notifications for some languages on Kodi 19
[fix] searching for some languages
[fix] loading on some versions of python 3
[fix] some videos failing to play with an Invalid URL exception
[upd] use xbmcvfs.translatePath if available, clean up for Kodi 19
</news>
<assets>
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
6.8.5
[fix] notifications for some languages on Kodi 19
[fix] searching for some languages
[fix] loading on some versions of python 3
[fix] some videos failing to play with an Invalid URL exception
[upd] use xbmcvfs.translatePath if available, clean up for Kodi 19

6.8.4
Expand Down
30 changes: 20 additions & 10 deletions resources/lib/youtube_plugin/youtube/helper/video_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ def get_player_config(self, html):

def get_player_js(self, video_id, js=''):
def _normalize(javascript_url):
if javascript_url in ['http://', 'https://']:
javascript_url = ''
if javascript_url and not javascript_url.startswith('http'):
javascript_url = 'https://www.youtube.com/%s' % \
javascript_url.lstrip('/').replace('www.youtube.com/', '')
Expand All @@ -614,7 +616,9 @@ def _normalize(javascript_url):

cached_js = self._data_cache.get_item(DataCache.ONE_HOUR * 4, 'player_javascript')
if cached_js and cached_js.get('player_javascript', {}).get('url'):
return cached_js.get('player_javascript', {}).get('url')
cached_url = cached_js.get('player_javascript', {}).get('url')
if cached_url not in ['http://', 'https://']:
return cached_url

if js:
return _normalize(js)
Expand All @@ -628,16 +632,22 @@ def _normalize(javascript_url):
_player_config = '{}'
player_config = dict()

lead = 'yt.setConfig({\'PLAYER_CONFIG\': '
tail = ',\'EXPERIMENT_FLAGS\':'
if html.find(tail) == -1:
tail = '});'
pos = html.find(lead)
if pos >= 0:
html2 = html[pos + len(lead):]
pos = html2.find(tail)
def find_config(lead, tail):
if html.find(tail) == -1:
tail = '});'
pos = html.find(lead)
if pos >= 0:
_player_config = html2[:pos]
html2 = html[pos + len(lead):]
pos = html2.find(tail)
if pos >= 0:
return html2[:pos]
return None

_player_config = find_config('yt.setConfig({\'PLAYER_CONFIG\': ', ',\'EXPERIMENT_FLAGS\':')
if _player_config is None:
_player_config = find_config(',\'PLAYER_CONFIG\': ', 'yt.setConfig({INNERTUBE_API_VERSION:')
if _player_config is None:
_player_config = '{}'

try:
player_config.update(json.loads(_player_config))
Expand Down

0 comments on commit 5d4bc2f

Please sign in to comment.