コード例 #1
0
    def convert_subtitles(self, subtitles, output):
        subtitle_data = subtitles
        subtitle_data = subtitle_data.replace("\n","").replace("\r","")
        subtitle_data = BeautifulStoneSoup(subtitle_data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
        subtitle_array = []
        srt_output = ''

        print "HULU: --> Converting subtitles to SRT"
        heading = 'Subtitles'
        message = 'Converting subtitles'
        duration = 4000
        #xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) )
        lines = subtitle_data.findAll('sync') #split the file into lines
        for line in lines:
            if(line['encrypted'] == 'true'):
                sub = self.decrypt_subs(line.string)
                sub = self.clean_subs(sub)
                sub = unicode(BeautifulStoneSoup(sub,convertEntities=BeautifulStoneSoup.HTML_ENTITIES).contents[0]).encode( "utf-8" )

            else:
                sub = unicode(BeautifulStoneSoup(sub,convertEntities=BeautifulStoneSoup.HTML_ENTITIES).contents[0]).encode( "utf-8" )

            begin_time = int(line['start'])
            seconds = int(math.floor(begin_time/1000))
            milliseconds = int(begin_time - (seconds * 1000))
            timestamp = self.convert_time(seconds)
            timestamp = "%s,%03d" % (timestamp, milliseconds)

            index = len(subtitle_array)-1
            if(index > -1 and subtitle_array[index]['end'] == None):
                millsplit = subtitle_array[index]['start'].split(',')
                itime = millsplit[0].split(':')
                start_seconds = (int(itime[0])*60*60)+(int(itime[1])*60)+int(itime[2])
                end_seconds = start_seconds + 4
                if end_seconds < seconds:
                    endmilliseconds = int(millsplit[1])
                    endtimestamp = self.convert_time(end_seconds)
                    endtimestamp = "%s,%03d" % (endtimestamp, endmilliseconds)
                    subtitle_array[index]['end'] = endtimestamp
                else:
                    subtitle_array[index]['end'] = timestamp

            if sub != '&#160; ':
                sub = sub.replace('&#160;', ' ')
                temp_dict = {'start':timestamp, 'end':None, 'text':sub}
                subtitle_array.append(temp_dict)

        for i, subtitle in enumerate(subtitle_array):
            line = str(i+1)+"\n"+str(subtitle['start'])+" --> "+str(subtitle['end'])+"\n"+str(subtitle['text'])+"\n\n"
            srt_output += line

        file = open(os.path.join(os.getcwd().replace(';', ''),'resources','cache',output+'.srt'), 'w')
        file.write(srt_output)
        file.close()
        print "HULU: --> Successfully converted subtitles to SRT"
        heading = 'Subtitles'
        message = 'Conversion Complete'
        duration = 4000
        #xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) )
        return True
コード例 #2
0
    def Play(self, stream_name, stream_id, subtitle):
        #path = self.tinyurl(stream_id)
        #play = ba.CreatePlay()
        #play.SetPath(quote_plus(path))
        #play.SetDomain('bartsidee.nl')
        #play.SetJSactions(quote_plus('http://bartsidee.nl/boxee/apps/js/hulu.js'))

        #grab eid from failsafe url
        html = ba.FetchUrl(stream_id)
        p=re.compile('content_id", (.+?)\);')
        ecid=p.findall(html)[0]
        pid = ecid

        if subtitle: self.checkCaptions(pid)

        #getSMIL
        try:
            #smilURL = "http://s.hulu.com/select.ashx?pid=" + pid + "&auth=" + self.pid_auth(pid) + "&v=713434170&np=1&pp=hulu&dp_id=hulu&cb=499"
            smilURL = 'http://s.hulu.com/select?video_id=' + pid + '&v=850037518&ts=1294866343&np=1&vp=1&pp=hulu&dp_id=hulu&bcs=' + self.content_sig(pid)
            print 'HULU --> SMILURL: ' + smilURL
            smilXML = ba.FetchUrl(smilURL)
            tmp = self.decrypt_SMIL(smilXML)
            smilSoup = BeautifulStoneSoup(tmp, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
            print smilSoup.prettify()
        except:
            print "error retreiving smil"
            return

        #getRTMP
        video=smilSoup.findAll('video')
        streams=[]
        selectedStream = None
        cdn = None
        qtypes=['ask', 'p011', 'p010', 'p008', 'H264 Medium', 'H264 650K', 'H264 400K', 'High', 'Medium','Low']
        #label streams
        qt = 4
        if qt < 0 or qt > 9: qt = 0
        while qt < 9:
            qtext = qtypes[qt]
            for vid in video:
                #if qt == 0:
                streams.append([vid['profile'],vid['cdn'],vid['server'],vid['stream'],vid['token']])
                if qt > 6 and 'H264' in vid['profile']: continue
                if qtext in vid['profile']:
                    if vid['cdn'] == 'akamai':
                        selectedStream = [vid['server'],vid['stream'],vid['token']]
                        print selectedStream
                        cdn = vid['cdn']
                        break

            if qt == 0 or selectedStream != None: break
            qt += 1

        if selectedStream != None:
            #form proper streaming url
            server = selectedStream[0]
            stream = selectedStream[1]
            token = selectedStream[2]

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

            if "level3" in cdn:
                appName += "?" + token
                stream = stream[0:len(stream)-4]
                newUrl = server + " app=" + appName

            elif "limelight" in cdn:
                appName += '?' + token
                stream = stream[0:len(stream)-4]
                newUrl = server + '?' + token + " app=" + appName

            elif "akamai" in cdn:
                appName += '?' + token
                newUrl = server + '?' + token
                #newUrl = server + "?_fcs_vhost=" + hostname + "&" + token

            else:
                #xbmcgui.Dialog().ok('Unsupported Content Delivery Network',cdn+' is unsupported at this time')
                return

            print "item url -- > " + newUrl
            print "app name -- > " + appName
            print "playPath -- > " + stream

            #define item
            SWFPlayer = 'http://www.hulu.com/site-player/86070/player.swf'
            #newUrl += " playpath=" + stream + " swfurl=" + SWFPlayer

            #newUrl += " swfvfy=true"
            playPath = stream
            rtmpURL = newUrl
            authPath = ''

            play = ba.CreatePlay()
            play.SetContent_type('video/x-flv')
            play.SetRTMPPath(playPath)
            play.SetRTMPDomain(rtmpURL)
            play.SetRTMPAuth(authPath)
            play.SetRTMPSwf(SWFPlayer)
            print "finish"
            return play