forked from rectalogic/xbmc-fancast-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
episodeplayer.py
49 lines (44 loc) · 2.02 KB
/
episodeplayer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
import re
import urllib
import xmlhelper as xml
import xbmc, xbmcplugin, xbmcgui
def Main(params):
EpisodePlayer(params['videoId'], params['title'])
class EpisodePlayer:
def __init__(self, videoId, title):
videoUrl = self.getVideoUrl(videoId)
item = xbmcgui.ListItem(title)
item.setProperty("SWFPlayer", "http://www.hulu.com/player.swf")
# play won't accept unicode strings, so convert
xbmc.Player(xbmc.PLAYER_CORE_DVDPLAYER).play(str(videoUrl), item)
def getVideoUrl(self, videoId):
"""Get video URL for videoId"""
try:
doc = xml.loadXml("http://www.fancast.com/player.widget?videoId=%s" % videoId)
root = xml.validateDocument(doc, 'entity')
mediaUrl = xml.getChildData(root, None, 'mediaUrl')
doc.unlink()
doc = xml.loadXml(mediaUrl)
root = xml.validateDocument(doc, 'playlist')
# We may have multiple urls in playlist, look for rtmp
# This may pick the wrong video
urls = root.getElementsByTagName('url')
for url in urls:
rtmpUrl = url.firstChild.wholeText
if (rtmpUrl.startswith("rtmp:")):
break
huluBreak = rtmpUrl.find('<break>')
if (huluBreak >= 0):
# Hulu style rtmp URL
return rtmpUrl[0:huluBreak]
else:
# Fancast style rtmp URL
# Need to split application and filename out of rtmp url:
# rtmp://cp40359.edgefcs.net/ondemand/fancast/Comcast_CIM_Prod_Fancast_Partner/836/252/COMEDYCENTRAL_COLBERTREPORT_4125.flv
# Changes to:
# rtmp://cp40359.edgefcs.net/ondemand?slist=fancast/Comcast_CIM_Prod_Fancast_Partner/836/252/COMEDYCENTRAL_COLBERTREPORT_4125
match = re.compile('^(.*ondemand)/(.*).flv$').match(rtmpUrl)
return "%s?slist=%s" % (match.group(1), match.group(2))
finally:
if (doc): doc.unlink()