def performAction(self, actionId):
     ProgressDisplayer().start('Processing request...')
     while actionId is not None:
         Logger.logInfo('Action to be performed ::' + actionId)
         turtle_route = self.getTurtleRoute(actionId)
         for move in turtle_route.moves:
             self.moveTurtle(move)
         actionId = self.judgeTurtleNextAction(turtle_route)
         
     ProgressDisplayer().end()
Example #2
0
    def performAction(self, actionId):
        ProgressDisplayer().start('Processing request...')
        while actionId is not None:
            Logger.logInfo('Action to be performed ::' + actionId)
            turtle_route = self.getTurtleRoute(actionId)
            for move in turtle_route.moves:
                self.moveTurtle(move)
            actionId = self.judgeTurtleNextAction(turtle_route)

        ProgressDisplayer().end()
Example #3
0
def start(addon_id, service_name, context_root, default_port, allowed_port_range):
    server = None
    try:
        sys.argv = None  # To handle the situations where some library expects system arguments. Main change made for t0mm0 urlresolver library.
        
        global __addon_id__
        global __registered_services__
        global __context_root__
        global __port__
        global __port_range__
        global __service_name__
        __addon_id__ = addon_id
        __context_root__ = context_root
        __port__ = default_port
        __port_range__ = allowed_port_range
        __service_name__ = service_name
        containerObj = Container(addon_id=addon_id)
        iconimage = AddonUtils.getCompleteFilePath(baseDirPath=containerObj.getAddonContext().addonPath, filename='icon.png')
        serviceport = int(containerObj.getAddonContext().addon.getSetting('serviceport'))
        
        XBMCInterfaceUtils.setSuppressDialogMsg(True)
        
        if serviceport < __port_range__[0] or serviceport > __port_range__[1] :
            containerObj.getAddonContext().addon.setSetting('serviceport', str(__port__))
            serviceport = __port__
            XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service: Port updated', 'Service port set to default value 8181', iconimage=iconimage)

        server = JSONRPCServer(context_root=__context_root__, server_port=serviceport)
        server.registerService('serviceName', serviceMethod)
        defined_services = containerObj.getAddonContext().getTurtleServices()
        if len(defined_services) == 0:
            Logger.logError(__service_name__ + ' Service :: There are no services defined for registration, end this service program now.')
            return
        for service in defined_services:
            server.registerService(service.get_service_name(), serviceMethod)
            __registered_services__[service.get_service_name()] = service.get_action_id()
            Logger.logInfo(__service_name__ + ' Service :: service registered = %s @ %s' % (service.get_service_name(), __context_root__))
        server.start()
#         XBMCInterfaceUtils.displayNotification(__service_name__ + ' Service has started', 'Use web browser PlayIt extension to play video.', iconimage=iconimage)
        
        while not xbmc.abortRequested:
            time.sleep(1)
        Logger.logInfo(__service_name__ + ' Service :: ABORT request received from XBMC. PlayIt service will stop now.')
    except Exception, e:
        Logger.logFatal(__service_name__ + ' Service :: ERROR OCCURRED: ' + str(e))
        ExceptionHandler.handle(e)
Example #4
0
def retrieveVideoInfo(video_id):
    
    video_info = VideoInfo()
    video_info.set_video_hosting_info(getVideoHostingInfo())
    video_info.set_video_id(video_id)
    try:
        
        HttpUtils.HttpClient().enableCookies()
        video_info.set_video_image('http://i.ytimg.com/vi/' + video_id + '/default.jpg')
        html = HttpUtils.HttpClient().getHtmlContent(url='http://www.youtube.com/get_video_info?video_id=' + video_id + '&asv=3&el=detailpage&hl=en_US')
        stream_map = None
        
        html = html.decode('utf8')
        html = html.replace('\n', '')
        html = html.replace('\r', '')
        html = unicode(html + '&').encode('utf-8')
        if re.search('status=fail', html):
            # XBMCInterfaceUtils.displayDialogMessage('Video info retrieval failed', 'Reason: ' + ((re.compile('reason\=(.+?)\.').findall(html))[0]).replace('+', ' ') + '.')
            Logger.logInfo('YouTube video is removed for Id = ' + video_id + ' reason = ' + html)
            video_info.set_video_stopped(True)
            return video_info
        
        title = urllib.unquote_plus(re.compile('title=(.+?)&').findall(html)[0]).replace('/\+/g', ' ')
        video_info.set_video_name(title)
        stream_info = None
        if not re.search('url_encoded_fmt_stream_map=&', html):
            stream_info = re.compile('url_encoded_fmt_stream_map=(.+?)&').findall(html)
        stream_map = None
        if (stream_info is None or len(stream_info) == 0) and re.search('fmt_stream_map": "', html):
            stream_map = re.compile('fmt_stream_map": "(.+?)"').findall(html)[0].replace("\\/", "/")
        elif stream_info is not None:
            stream_map = stream_info[0]
            
        if stream_map is None:
            params = HttpUtils.getUrlParams(html)
            Logger.logDebug('ENTERING live video scenario...')
            for key in params:
                Logger.logDebug(key + " : " + urllib.unquote_plus(params[key]))
            hlsvp = urllib.unquote_plus(params['hlsvp'])
            playlistItems = HttpUtils.HttpClient().getHtmlContent(url=hlsvp).splitlines()
            qualityIdentified = None
            for item in playlistItems:
                Logger.logDebug(item)
                if item.startswith('#EXT-X-STREAM-INF'):
                    if item.endswith('1280x720'):
                        qualityIdentified = VIDEO_QUAL_HD_720
                    elif item.endswith('1080'):
                        qualityIdentified = VIDEO_QUAL_HD_1080
                    elif item.endswith('854x480'):
                        qualityIdentified = VIDEO_QUAL_SD
                    elif item.endswith('640x360'):
                        qualityIdentified = VIDEO_QUAL_LOW
                elif item.startswith('http') and qualityIdentified is not None:
                    videoUrl = HttpUtils.HttpClient().addHttpCookiesToUrl(item, extraExtraHeaders={'Referer':'https://www.youtube.com/watch?v=' + video_id})
                    video_info.add_video_link(qualityIdentified, videoUrl)
                    qualityIdentified = None
            video_info.set_video_stopped(False)
            return video_info
        
        stream_map = urllib.unquote_plus(stream_map)
        Logger.logDebug(stream_map)
        formatArray = stream_map.split(',')
        streams = {}
        for formatContent in formatArray:
            if formatContent == '':
                continue
            formatUrl = ''
            try:
                formatUrl = urllib.unquote(re.compile("url=([^&]+)").findall(formatContent)[0]) + "&title=" + urllib.quote_plus(title)   
            except Exception, e:
                Logger.logFatal(e)     
            if re.search("rtmpe", stream_map):
                try:
                    conn = urllib.unquote(re.compile("conn=([^&]+)").findall(formatContent)[0]);
                    host = re.compile("rtmpe:\/\/([^\/]+)").findall(conn)[0];
                    stream = re.compile("stream=([^&]+)").findall(formatContent)[0];
                    path = 'videoplayback';
                    
                    formatUrl = "-r %22rtmpe:\/\/" + host + "\/" + path + "%22 -V -a %22" + path + "%22 -f %22WIN 11,3,300,268%22 -W %22http:\/\/s.ytimg.com\/yt\/swfbin\/watch_as3-vfl7aCF1A.swf%22 -p %22http:\/\/www.youtube.com\/watch?v=" + video_id + "%22 -y %22" + urllib.unquote(stream) + "%22"
                except Exception, e:
                    Logger.logFatal(e)
            if formatUrl == '':
                continue
            Logger.logDebug('************************')
            Logger.logDebug(formatContent)
            formatQual = ''
            if(formatUrl[0: 4] == "http" or formatUrl[0: 2] == "-r"):
                formatQual = re.compile("itag=([^&]+)").findall(formatContent)[0]
                if not re.search("signature=", formatUrl):
                    sig = re.compile("sig=([^&]+)").findall(formatContent)
                    if sig is not None and len(sig) == 1:
                        formatUrl += "&signature=" + sig[0]
                    else:
                        sig = re.compile("s=([^&]+)").findall(formatContent)
                        if sig is not None and len(sig) == 1:
                            formatUrl += "&signature=" + parseSignature(sig[0])
        
            qual = formatQual
            url = HttpUtils.HttpClient().addHttpCookiesToUrl(formatUrl, addHeaders=False,addCookies=False, extraExtraHeaders={'Referer':'https://www.youtube.com/watch?v=' + video_id})
            streams[int(qual)] = url