def loadFavorites(self):
     self.favorites = []
     try:
         doc = None
         doc = xml.loadXml(FAVORITES_PATH)
         root = xml.validateDocument(doc, 'rss')
         items = root.getElementsByTagName('item')
         for item in items:
             self.favorites.append(Favorite(xml.getChildData(item, None, 'title'),
                                            xml.getChildData(item, None, 'link')))
     except:
         print "ERROR: %s::%s (%d) - %s" % (self.__class__.__name__, sys.exc_info()[2].tb_frame.f_code.co_name, sys.exc_info()[2].tb_lineno, sys.exc_info()[1])
     if (doc): doc.unlink()
    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()
 def loadFavorites(self):
     self.favorites = []
     try:
         doc = None
         doc = xml.loadXml(FAVORITES_PATH)
         root = xml.validateDocument(doc, 'rss')
         items = root.getElementsByTagName('item')
         for item in items:
             self.favorites.append(
                 Favorite(xml.getChildData(item, None, 'title'),
                          xml.getChildData(item, None, 'link')))
     except:
         print "ERROR: %s::%s (%d) - %s" % (
             self.__class__.__name__,
             sys.exc_info()[2].tb_frame.f_code.co_name,
             sys.exc_info()[2].tb_lineno, sys.exc_info()[1])
     if (doc): doc.unlink()
Beispiel #4
0
 def parseRss(self, doc):
     """Parse RSS XML dom and populate display list."""
     try:
         root = xml.validateDocument(doc, 'rss')
         items = root.getElementsByTagName('item')
         totalItems = len(items)
         for item in items:
             try:
                 title = (xml.getChildData(item, None, 'title')).encode("utf-8")
                 feedUrl = xml.getChildData(item, None, 'link')
                 url = sys.argv[0] + "?" + urllib.urlencode({'module': 'episodelist',
                                                             'title': title,
                                                             'episodeFeedUrl': feedUrl})
                 item = xbmcgui.ListItem(title, iconImage="DefaultFolder.png",
                                         thumbnailImage="DefaultVideo.png")
                 if not xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url,
                                                    listitem=item, totalItems=totalItems, isFolder=True):
                     return False
             except:
                 print "Skipping '%s' - %s" % (title.encode('utf-8'), sys.exc_info()[1])
         return True
     finally:
         if (doc): doc.unlink()
    def parseRss(self, doc, filter):
        """Parse RSS XML dom and populate display list."""
        if (filter == 'movies'):
            filterNS = 'http://search.yahoo.com/mrss/'
            filterName = 'category'
            filterValue = 'movies'

        try:
            mediaNS = 'http://search.yahoo.com/mrss/'
            cimNS = 'http://labs.comcast.net/'
            root = xml.validateDocument(doc, 'rss')
            items = root.getElementsByTagName('item')
            totalItems = len(items)
            for item in items:
                try:
                    # Skip element if filter supplied and element value does not match
                    if (filter):
                        tagValue = xml.getChildData(item, filterNS, filterName)
                        if (filterValue != tagValue):
                            next

                    title = xml.getChildData(item, mediaNS, 'title')
                    thumbnail = xml.getChildData(item, mediaNS, 'thumbnail', 'url')
                    pubDate = xml.getChildData(item, cimNS, 'origAirDate', isRequired=False)
                    if (not pubDate):
                        pubDate = xml.getChildData(item, None, 'pubDate', isRequired=False)
                    if (pubDate):
                        try:
                            # convert date to DD-MM-YYYY so sorting by date works correctly.
                            # I found this date format in the Apple Movie Trailers II plugin
                            sdate = time.strptime(pubDate[5:16], "%d %b %Y")
                            pubDate = "%02d-%02d-%04d" % (sdate.tm_mday, sdate.tm_mon, sdate.tm_year)
                        except:
                            pass
                    description = xml.getChildData(item, None, 'description', isRequired=False)
                    url = sys.argv[0] + "?" + urllib.urlencode({ 'module': 'episodeplayer',
                                                                 'videoId': xml.getChildData(item, cimNS, 'videoId'),
                                                                 'title': title})
                    item = xbmcgui.ListItem(title, iconImage="DefaultVideo.png", thumbnailImage=thumbnail)
                    item.setInfo(type="Video",
                                 infoLabels={ "Title": title,
                                              "Plot": description,
                                              "Date": pubDate })
                    if not xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url,
                                                       listitem=item, totalItems=totalItems):
                        return False
                except:
                    print "Skipping '%s' - %s" % (title.encode('utf-8'), sys.exc_info()[1])
        finally:
            if (doc): doc.unlink()
        return True
    def parseRss(self, doc, filter):
        """Parse RSS XML dom and populate display list."""
        if (filter == 'movies'):
            filterNS = 'http://search.yahoo.com/mrss/'
            filterName = 'category'
            filterValue = 'movies'

        try:
            mediaNS = 'http://search.yahoo.com/mrss/'
            cimNS = 'http://labs.comcast.net/'
            root = xml.validateDocument(doc, 'rss')
            items = root.getElementsByTagName('item')
            totalItems = len(items)
            for item in items:
                try:
                    # Skip element if filter supplied and element value does not match
                    if (filter):
                        tagValue = xml.getChildData(item, filterNS, filterName)
                        if (filterValue != tagValue):
                            next

                    title = (xml.getChildData(item, mediaNS,
                                              'title')).encode("utf-8")
                    thumbnail = xml.getChildData(item, mediaNS, 'thumbnail',
                                                 'url')
                    pubDate = xml.getChildData(item,
                                               cimNS,
                                               'origAirDate',
                                               isRequired=False)
                    if (not pubDate):
                        pubDate = xml.getChildData(item,
                                                   None,
                                                   'pubDate',
                                                   isRequired=False)
                    if (pubDate):
                        try:
                            # convert date to DD-MM-YYYY so sorting by date works correctly.
                            # I found this date format in the Apple Movie Trailers II plugin
                            sdate = time.strptime(pubDate[5:16], "%d %b %Y")
                            pubDate = "%02d-%02d-%04d" % (
                                sdate.tm_mday, sdate.tm_mon, sdate.tm_year)
                        except:
                            pass
                    description = xml.getChildData(item,
                                                   None,
                                                   'description',
                                                   isRequired=False)
                    url = sys.argv[0] + "?" + urllib.urlencode(
                        {
                            'module': 'episodeplayer',
                            'videoId': xml.getChildData(
                                item, cimNS, 'videoId'),
                            'title': title
                        })
                    item = xbmcgui.ListItem(title,
                                            iconImage="DefaultVideo.png",
                                            thumbnailImage=thumbnail)
                    item.setInfo(type="Video",
                                 infoLabels={
                                     "Title": title,
                                     "Plot": description,
                                     "Date": pubDate
                                 })
                    if not xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                                       url=url,
                                                       listitem=item,
                                                       totalItems=totalItems):
                        return False
                except:
                    print "Skipping '%s' - %s" % (title.encode('utf-8'),
                                                  sys.exc_info()[1])
        finally:
            if (doc): doc.unlink()
        return True
    def getVideoUrl(self, videoId, title):
        """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
                #code to determine proper streaming url from
                #http://code.google.com/p/xbmc-addons/source/browse/trunk/plugins/video/Hulu/resources/lib/stream_hulu.py#75
                rtmpUrl=rtmpUrl.replace('&amp;','&').replace('&lt;','<').replace('&gt;','>')
                mainParts = rtmpUrl.split("?")
                queryStringParts = mainParts[1].split("&")
                v9 = queryStringParts[0]
                v6 = queryStringParts[1]

                if "<break>" in queryStringParts[2]:
                    breakParts = queryStringParts[2].split("<break>")
                    v3 = breakParts[0];
                    fileName = breakParts[1]
                else:
                    v3 = queryStringParts[2]
                    breakFilenameURL = mainParts[0].split("://");
                    breakFilenamedir = breakFilenameURL[1].split("/");
                    breakFilenames = breakFilenameURL[1].split(breakFilenamedir[1] + "/")
                    fileName = breakFilenames[1]

                newQueryString = v9 + "&" + v6 + "&" + v3

                protocolSplit = rtmpUrl.split("://")
                pathSplit = protocolSplit[1].split("/");
                serverPath = pathSplit[0] + "/" + pathSplit[1];
                server = pathSplit[0];
                appName = pathSplit[1];
                videoIdentIp = server

                protocol = "rtmp";
                port = "1935";
                newUrl =  protocol + "://" + videoIdentIp + ":" + port + "/" + appName + "?_fcs_vhost=" + server
                if newQueryString <> "":
                    newUrl += "&" + newQueryString
                SWFPlayer = 'http://www.hulu.com/player.swf'
                item = xbmcgui.ListItem(title)
                item.setProperty("SWFPlayer", SWFPlayer)
                item.setProperty("PlayPath", fileName)
                item.setProperty("PageURL", "http://www.fancast.com/player.widget?videoId=%s" % videoId)
                playlist = xbmc.PlayList(1)
                playlist.clear()
                playlist.add(newUrl, item)
                play=xbmc.Player().play(playlist)
                xbmc.executebuiltin('XBMC.ActivateWindow(fullscreenvideo)')
            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)
                videoUrl = "%s?slist=%s" % (match.group(1), match.group(2))
                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)
        finally:
            if (doc): doc.unlink()
    def getVideoUrl(self, videoId, title):
        """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
                # code to determine proper streaming url from
                # http://code.google.com/p/xbmc-addons/source/browse/trunk/plugins/video/Hulu/resources/lib/stream_hulu.py#75
                rtmpUrl = rtmpUrl.replace("&amp;", "&").replace("&lt;", "<").replace("&gt;", ">")
                mainParts = rtmpUrl.split("?")
                queryStringParts = mainParts[1].split("&")
                v9 = queryStringParts[0]
                v6 = queryStringParts[1]

                if "<break>" in queryStringParts[2]:
                    breakParts = queryStringParts[2].split("<break>")
                    v3 = breakParts[0]
                    fileName = breakParts[1]
                else:
                    v3 = queryStringParts[2]
                    breakFilenameURL = mainParts[0].split("://")
                    breakFilenamedir = breakFilenameURL[1].split("/")
                    breakFilenames = breakFilenameURL[1].split(breakFilenamedir[1] + "/")
                    fileName = breakFilenames[1]

                newQueryString = v9 + "&" + v6 + "&" + v3

                protocolSplit = rtmpUrl.split("://")
                pathSplit = protocolSplit[1].split("/")
                serverPath = pathSplit[0] + "/" + pathSplit[1]
                server = pathSplit[0]
                appName = pathSplit[1]
                videoIdentIp = server

                protocol = "rtmp"
                port = "1935"
                newUrl = protocol + "://" + videoIdentIp + ":" + port + "/" + appName + "?_fcs_vhost=" + server
                if newQueryString <> "":
                    newUrl += "&" + newQueryString
                SWFPlayer = "http://www.hulu.com/player.swf"
                item = xbmcgui.ListItem(title)
                item.setProperty("SWFPlayer", SWFPlayer)
                item.setProperty("PlayPath", fileName)
                item.setProperty("PageURL", "http://www.fancast.com/player.widget?videoId=%s" % videoId)
                playlist = xbmc.PlayList(1)
                playlist.clear()
                playlist.add(newUrl, item)
                play = xbmc.Player().play(playlist)
                xbmc.executebuiltin("XBMC.ActivateWindow(fullscreenvideo)")
            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)
                videoUrl = "%s?slist=%s" % (match.group(1), match.group(2))
                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)
        finally:
            if doc:
                doc.unlink()