def __initialize__(self, addon_id, addon_ver=None):
     self.addon_context = AddonContext(addon_id=addon_id, addon_ver=addon_ver)
     self.ga_client = GAClient(addon_context=self.addon_context)
     self.ga_client.reportAppLaunch()
Beispiel #2
0
 def __initialize__(self, addon_id, addon_ver=None):
     self.addon_context = AddonContext(addon_id=addon_id,
                                       addon_ver=addon_ver)
     self.ga_client = GAClient(addon_context=self.addon_context)
     self.ga_client.reportAppLaunch()
class Container(SingletonClass):
    
    def __initialize__(self, addon_id, addon_ver=None):
        self.addon_context = AddonContext(addon_id=addon_id, addon_ver=addon_ver)
        self.ga_client = GAClient(addon_context=self.addon_context)
        self.ga_client.reportAppLaunch()
        
    def getAddonContext(self):
        return self.addon_context
        
    def getTurtleRequest(self):
        params = None
        if len(sys.argv) >= 3:
            params = str(sys.argv[2])
        self.request_obj = DataObjects.Request(params=params)
        self.response_obj = DataObjects.Response()
        return self.request_obj
    
    def getTurtleResponse(self):
        return self.response_obj
        
    def reloadTurtleRequest(self, params):
        self.request_obj = DataObjects.Request(params=params)
        self.response_obj = DataObjects.Response()
        
    def getTurtleRoute(self, actionId):
        return self.addon_context.getTurtleRoute(actionId)
        
    def moveTurtle(self, moveObj):
        if moveObj.get_pmessage() is not None:
            ProgressDisplayer().displayMessage(50, pmessage=moveObj.get_pmessage())
        components = moveObj.module_path.split('.')
        module = __import__(moveObj.module_path)
        if components is not None and isinstance(components, list):
            for index in range(1, len(components)):
                module = getattr(module, components[index])
        function = getattr(module, moveObj.function_name)
        function(self.request_obj, self.response_obj)
        
        
    def judgeTurtleNextAction(self, actionObj):
        ProgressDisplayer().displayMessage(80, line1='Preparing items for display or play', line2='Total items: ' + str(len(self.response_obj.get_item_list())))
        if self.response_obj.get_redirect_action_name() is None:
            isAnyPlayableItem = False
            isItemsList = False
            playlist_type = None
            for item in self.response_obj.get_item_list():
                nextActionId = actionObj.get_next_action_map()[item.get_next_action_name()]
                if nextActionId == '__play__':
                    if item.get_moving_data().has_key('pluginUrl'):
                        XBMCInterfaceUtils.executePlugin(item.get_moving_data()['pluginUrl'])
                    else:
                        if not isAnyPlayableItem and not XBMCInterfaceUtils.isPlaying():
                            XBMCInterfaceUtils.clearPlayList()  # Clear playlist item only when at least one video item is found.
                        playlist_type = XBMCInterfaceUtils.addPlayListItem(item)
                        isAnyPlayableItem = True
                elif nextActionId == '__service_response__':
                    # Do Nothing , get response object from container for parameters to be returned
                    pass
                elif nextActionId == '__download__':
                    downloadPath = self.addon_context.addon.getSetting('downloadPath')
                    if downloadPath is None or downloadPath == '':
                        XBMCInterfaceUtils.displayDialogMessage("Download path not provided", "Please provide download path in add-on settings.", "The download path should be a local directory.")
                        self.addon_context.addon.openSettings(sys.argv[ 0 ])
                        downloadPath = self.addon_context.addon.getSetting('downloadPath')
                    if downloadPath is not None and downloadPath != '':
                        XBMCInterfaceUtils.downloadVideo(item, downloadPath)
                elif nextActionId == '__resolved__':
                    XBMCInterfaceUtils.setResolvedMediaUrl(item)
                else:
                    isItemsList = True
                    is_Folder = self.addon_context.isNextActionFolder(actionObj.get_action_id(), item.get_next_action_name())
                    downloadAction = self.addon_context.getDownloadActionIfDownloadable(actionObj.get_action_id(), item.get_next_action_name())
                    if(downloadAction is not None):
                        XBMCInterfaceUtils.addContextMenuItem(item, 'Download Video', downloadAction)
                    XBMCInterfaceUtils.addFolderItem(item, nextActionId, is_Folder)
                del item  # deletes item
            if isAnyPlayableItem == True:
                ProgressDisplayer().end()
                try:
                    if playlist_type is not None:
                        XBMCInterfaceUtils.play(list_type=playlist_type)
                    else:
                        XBMCInterfaceUtils.play()
                except Exception, e:
                    Logger.logFatal(e)
            elif isItemsList:
                if self.response_obj.get_xbmc_sort_method() is not None:
                    XBMCInterfaceUtils.sortMethod(self.response_obj.get_xbmc_sort_method())
                if self.response_obj.get_xbmc_content_type() is not None:
                    XBMCInterfaceUtils.setContentType(self.response_obj.get_xbmc_content_type())
                XBMCInterfaceUtils.setSortMethods()

        else:
Beispiel #4
0
class Container(SingletonClass):
    def __initialize__(self, addon_id, addon_ver=None):
        self.addon_context = AddonContext(addon_id=addon_id,
                                          addon_ver=addon_ver)
        self.ga_client = GAClient(addon_context=self.addon_context)
        self.ga_client.reportAppLaunch()

    def getAddonContext(self):
        return self.addon_context

    def getTurtleRequest(self):
        params = None
        if len(sys.argv) >= 3:
            params = str(sys.argv[2])
        self.request_obj = DataObjects.Request(params=params)
        self.response_obj = DataObjects.Response()
        return self.request_obj

    def getTurtleResponse(self):
        return self.response_obj

    def reloadTurtleRequest(self, params):
        self.request_obj = DataObjects.Request(params=params)
        self.response_obj = DataObjects.Response()

    def getTurtleRoute(self, actionId):
        return self.addon_context.getTurtleRoute(actionId)

    def moveTurtle(self, moveObj):
        if moveObj.get_pmessage() is not None:
            ProgressDisplayer().displayMessage(50,
                                               pmessage=moveObj.get_pmessage())
        components = moveObj.module_path.split('.')
        module = __import__(moveObj.module_path)
        if components is not None and isinstance(components, list):
            for index in range(1, len(components)):
                module = getattr(module, components[index])
        function = getattr(module, moveObj.function_name)
        function(self.request_obj, self.response_obj)

    def judgeTurtleNextAction(self, actionObj):
        ProgressDisplayer().displayMessage(
            80,
            line1='Preparing items for display or play',
            line2='Total items: ' +
            str(len(self.response_obj.get_item_list())))
        if self.response_obj.get_redirect_action_name() is None:
            isAnyPlayableItem = False
            isItemsList = False
            playlist_type = None
            for item in self.response_obj.get_item_list():
                nextActionId = actionObj.get_next_action_map()[
                    item.get_next_action_name()]
                if nextActionId == '__play__':
                    if item.get_moving_data().has_key('pluginUrl'):
                        XBMCInterfaceUtils.executePlugin(
                            item.get_moving_data()['pluginUrl'])
                    else:
                        if not isAnyPlayableItem and not XBMCInterfaceUtils.isPlaying(
                        ):
                            XBMCInterfaceUtils.clearPlayList(
                            )  # Clear playlist item only when at least one video item is found.
                        playlist_type = XBMCInterfaceUtils.addPlayListItem(
                            item)
                        isAnyPlayableItem = True
                elif nextActionId == '__service_response__':
                    # Do Nothing , get response object from container for parameters to be returned
                    pass
                elif nextActionId == '__download__':
                    downloadPath = self.addon_context.addon.getSetting(
                        'downloadPath')
                    if downloadPath is None or downloadPath == '':
                        XBMCInterfaceUtils.displayDialogMessage(
                            "Download path not provided",
                            "Please provide download path in add-on settings.",
                            "The download path should be a local directory.")
                        self.addon_context.addon.openSettings(sys.argv[0])
                        downloadPath = self.addon_context.addon.getSetting(
                            'downloadPath')
                    if downloadPath is not None and downloadPath != '':
                        XBMCInterfaceUtils.downloadVideo(item, downloadPath)
                elif nextActionId == '__resolved__':
                    XBMCInterfaceUtils.setResolvedMediaUrl(item)
                else:
                    isItemsList = True
                    is_Folder = self.addon_context.isNextActionFolder(
                        actionObj.get_action_id(), item.get_next_action_name())
                    downloadAction = self.addon_context.getDownloadActionIfDownloadable(
                        actionObj.get_action_id(), item.get_next_action_name())
                    if (downloadAction is not None):
                        XBMCInterfaceUtils.addContextMenuItem(
                            item, 'Download Video', downloadAction)
                    XBMCInterfaceUtils.addFolderItem(item, nextActionId,
                                                     is_Folder)
                del item  # deletes item
            if isAnyPlayableItem == True:
                ProgressDisplayer().end()
                try:
                    if playlist_type is not None:
                        XBMCInterfaceUtils.play(list_type=playlist_type)
                    else:
                        XBMCInterfaceUtils.play()
                except Exception, e:
                    Logger.logFatal(e)
            elif isItemsList:
                if self.response_obj.get_xbmc_sort_method() is not None:
                    XBMCInterfaceUtils.sortMethod(
                        self.response_obj.get_xbmc_sort_method())
                if self.response_obj.get_xbmc_content_type() is not None:
                    XBMCInterfaceUtils.setContentType(
                        self.response_obj.get_xbmc_content_type())
                XBMCInterfaceUtils.setSortMethods()

        else: