Skip to content

Commit

Permalink
- Fix video playing issue
Browse files Browse the repository at this point in the history
- Some translations
  • Loading branch information
KOL committed Mar 22, 2016
1 parent 644de2b commit f4390c2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<key>CFBundleSignature</key>
<string>hook</string>
<key>CFBundleVersion</key>
<string>4.2</string>
<string>4.3</string>

<key>PlexPluginVersionUrl</key>
<string>http://bit.ly/1FuE3dz</string>
Expand Down
73 changes: 33 additions & 40 deletions Contents/Services/Shared Code/video.pys
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ USER_AGENT = (
'Mobile/11B554a Safari/9537.54'
)

RE_DATA = Regex('ytplayer.config\s*=\s*({(?:.+)});\s*ytplayer.load\s*=')


def GetServiceURL(vid, token='', hl=''):
return 'http://tv.youtube.plugins.plex.com/%s%s%s%s%s' % (
Expand All @@ -73,38 +75,42 @@ def GetServiceURL(vid, token='', hl=''):


def GetMetaUrlByServiceURL(url):
return 'https://www.youtube.com/watch?v=%s&spf=navigate' % GetOID(url)
return 'https://www.youtube.com/watch?v=%s' % GetOID(url)


def GetVideoData(url):
try:
res = JSON.ObjectFromURL(GetMetaUrlByServiceURL(url))
res = HTML.ElementFromURL(GetMetaUrlByServiceURL(url))
except:
raise Ex.MediaNotAvailable

ret = {}
for item in res:
if 'data' in item and 'swfcfg' in item['data']:
ret.update(item['data'])
elif 'body' in item and 'watch7-container' in item['body']:
try:
cont = HTML.ElementFromString(item['body']['watch7-container'])
ret['date_published'] = cont.xpath(
'//meta[@itemprop="datePublished"]'
)[0].get('content')
cont = cont.xpath(
'//div[@id="watch-description-text"]'
)[0]
for br in cont.xpath('*//br'):
br.tail = '\n' + br.tail if br.tail else '\n'
ret['description'] = cont.text_content()
except:
pass

if ret:
return ret

raise Ex.MediaNotAvailable

try:
ret = JSON.ObjectFromString(RE_DATA.search(
res.xpath(
'//script[contains(., "ytplayer.config")]'
)[0].text_content()
).group(1))
except Exception as e:
Log.Error('Cannot get video data: %s' % e)
raise Ex.MediaNotAvailable

try:
cont = res.xpath('//div[@id="watch7-container"]')[0]
ret['date_published'] = cont.xpath(
'//meta[@itemprop="datePublished"]'
)[0].get('content')
cont = cont.xpath(
'//div[@id="watch-description-text"]'
)[0]
for br in cont.xpath('*//br'):
br.tail = '\n' + br.tail if br.tail else '\n'
ret['description'] = cont.text_content()
except:
pass

return ret


def GetOID(url):
Expand All @@ -113,21 +119,16 @@ def GetOID(url):

def MetaFromInfo(item):
try:
meta = item['swfcfg']['args']
return item['args']
except:
try:
meta = item['player_data']['player_vars']
except:
return None

return meta
return None


def GetVideoUrls(url):
info = GetVideoData(url)
meta = MetaFromInfo(info)
try:
player_url = info['swfcfg']['assets']['js']
player_url = info['assets']['js']
except:
player_url = None

Expand Down Expand Up @@ -172,14 +173,6 @@ def GetVideoUrls(url):
if itag in RESOLUTIONS or itag in AUDIO:
ret[itag] = GetUrlFromStream(item, player_url)

# Fresh uploaded video
else:
try:
for item in info['player_data']['fmt_stream_map']:
ret[int(item['itag'])] = GetUrlFromStream(item, player_url)
except:
pass

if not len(ret):
raise Ex.MediaNotAvailable

Expand Down
4 changes: 3 additions & 1 deletion Contents/Strings/fr-BE.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@
"Action complete": "Action terminée",
"An error has occurred": "Une erreur est survenue",
"Sign out": "Déconnexion",
"Subscriptions list sorting order": "Ordre de tri de la liste des abonnements"
"Subscriptions list sorting order": "Ordre de tri de la liste des abonnements",
"Always play highest quality": "Toujours utiliser la meilleurs qualité",
"Search Channel": "Rechercher dans les chaînes"
}
4 changes: 3 additions & 1 deletion Contents/Strings/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@
"Action complete": "Action terminée",
"An error has occurred": "Une erreur est survenue",
"Sign out": "Déconnexion",
"Subscriptions list sorting order": "Ordre de tri de la liste des abonnements"
"Subscriptions list sorting order": "Ordre de tri de la liste des abonnements",
"Always play highest quality": "Toujours utiliser la meilleurs qualité",
"Search Channel": "Rechercher dans les chaînes"
}

0 comments on commit f4390c2

Please sign in to comment.