⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chn_class.py

📁 XOT: XBMC Online TV Framework
💻 PY
📖 第 1 页 / 共 3 页
字号:
                            item.complete = False
                        
                        # check if the list has not changed during upate:
                        #if item.guid == self.listItems[position].guid:
                        if item.Equals(self.listItems[position]):
                            logFile.info("Updating item (GUIDs match)")                
                            self.listItems[position] = item
                        else:
                            logFile.error("Aborting Update because of GUID mismatch")
                    logFile.info("Starting playback of %s (mediaurl=%s)", item.name, item.mediaurl)
                    self.ShowData(item)
                    self.PlayVideoItem(item)
                elif item.type == 'folder':
                    logFile.debug("Detected Folder\nAppending current selected position (%s) to history.", position)
                    
                    # remember the selected position
                    self.folderHistorySelectedPosition.append(position)
                    
                    # add content items to the selected item
                    item.items = self.ProcessFolderList(item.url)
                    
                    # make those items the listItems
                    self.listItems = item.items
                    
                    # append the item to the history
                    self.folderHistory.append(item)
                    self.DisplayFolderList(self.listItems, 0)
                    
                else:
                    logFile.warning("Error updating %s (%s) for %s", item.name, item.type, self.channelName)
            else:
                logFile.warning("ControlID (%s) was not recognised! No action taken", controlID)
        except:
            logFile.critical("On Click error showing episodes", exc_info=True)
     
    #============================================================================== 
    def onUpDown(self, ignoreDisabled = False):
        """ NOT USER EDITABLE
        Action Method for handling selecting. If the ignoreDisalbe is set to True
        it makes the script ignore self.onUpDownUpdateEnabled and update anyway! 
        """
        logFile.debug("OnKeyUp/KeyDown Detected")
        try:
            # get the item that is focused
            _position = self.getCurrentListPosition()
            _item = self.listItems[_position]
            
            if _item.complete:
                #item is complete. Just show
                logFile.debug("No OnKeyUp/KeyDown for a complete item")
                self.ShowData(self.listItems[_position])
                return
            
            if _item.type == "folder":
                #item is folder. 
                logFile.debug("No OnKeyUp/KeyDown for a folder item")
                self.ShowData(self.listItems[_position])
                return
            
            if _item.complete == False and _item.type == "video" and (not self.onUpDownUpdateEnabled and not ignoreDisabled):
                # item is not complete, but the onupdown is disabled and we don't have to ignore that
                # just show the data
                logFile.debug("Item is not complete, but the onupdown is disabled and we don't have to ignore that. Only showing data")
                self.ShowData(self.listItems[_position])
                return
            
            if _item.complete == False and _item.type == "video" and (self.onUpDownUpdateEnabled or ignoreDisabled):
                # if video item and not complete, do an update if not already busy
                
                #===============================================================================
                # Locking block 
                #===============================================================================
                # aquire lock so that all new timers in the keyUp/Down actions will
                # be blocked! A timer is set to call the onUpDown again after waiting
                logFile.debug("1.==== Trying to acquire a lock")
                if (not self.videoUpdateLock.acquire(0)):
                    logFile.debug("2.==== Lock was already active")
                    try:
                        self.timerUpDown.cancel()
                    except:
                        pass
                    logFile.debug("Resetting the timer from within onUpDown")
                    self.timerUpDown = threading.Timer(self.timerTimeOut, self.onUpDown)
                    self.timerUpDown.start()
                    return
                logFile.debug("2.==== Lock Acquired")
                #============================================================================== 
                # Actual action happens now:
                logFile.debug("Item '%s' not completed yet. Updating Video", _item.name)
                
                #display please wait:
                self.ShowData(self.folderHistory[0])
                
                _item = self.UpdateVideoItem(_item)
                # if the mediaUrl is not filled: item is not complete
                if _item.mediaurl == "":
                    _item.complete = False
                
                # check if the list has not changed during upate:
                if _item.Equals(self.listItems[_position]):
                    logFile.info("Updating item (GUIDs match)")                
                    self.listItems[_position] = _item
                else:
                    logFile.error("Aborting Update because of GUID mismatch\n(%s and %s)", _item.guid, self.listItems[_position].guid)
                
                # release lock
                logFile.debug("3.==== UnLocking the lock")
                
                self.ShowData(self.listItems[_position]) 
                self.videoUpdateLock.release()    
                #===============================================================================
                # Locking block End 
                #===============================================================================
            else:
                #if nothing matched
                logFile.debug("OnUpDown: does not know what to do")
                return
        except:
            try:
                # release lock
                logFile.debug("3.==== Unlocking the lock after an excpetion")
                self.videoUpdateLock.release()
            except:
                pass
                
            logFile.critical("Cannot handle KeyUp/Down", exc_info=True)
            
    
    #============================================================================== 
    def onExit(self):
        """
        Action Method for handling exiting
        """
        self.listItems = []
        self.getControl(controls.EP_LIST).reset()
        self.close()
    
    #==============================================================================
    # ContextMenu functions
    #==============================================================================
    def onActionFromContextMenu(self):
        """ NOT USER EDITABLE
            Using of the ContextMenu. 
        """
        try:
            position = self.getCurrentListPosition()
            item = self.listItems[position]
            contextMenuItems = []
            
            if item.type == 'folder':
                contextMenuItems.append(contextmenu.ContextMenuItem("Add to favorites", "CtMnAddToFavorites"))
            elif item.type == 'video':
                pass
            else:
                return None
            
            logFile.debug(self.contextMenuItems)
            
            for menuItem in self.contextMenuItems:
                logFile.debug("%s (%s), %s %s", menuItem.label, menuItem.functionName, menuItem.itemTypes, menuItem.completeStatus)
                if menuItem.itemTypes == None or menuItem.itemTypes == item.type:
                    if menuItem.completeStatus == None or menuItem.completeStatus == item.complete:
                        contextMenuItems.append(menuItem)
                
            if len(contextMenuItems) == 0:
                return None 
            
            # build menuitems
            contextMenu = contextmenu.GUI(config.contextMenuSkin, config.rootDir, config.skinFolder, parent=self.getFocus(), menuItems = contextMenuItems)
            selectedItem = contextMenu.selectedItem
            del contextMenu
            
            # handle function from items
            if (selectedItem is not None):    
                selectedMenuItem = contextMenuItems[selectedItem]
                functionString = "self.%s(%s)" % (selectedMenuItem.functionName, position)
                logFile.debug("Calling %s", functionString)
                try:
                    exec(functionString)
                except:
                    logFile.error("onActionFromContextMenu :: Cannot execute '%s'.", functionString, exc_info = True)
            
            return None
        except:
            logFile.error("onActionFromContextMenu :: Error on contextmenu action", exc_info = True)
            return None
    
    #============================================================================== 
    def CtMnAddToFavorites(self, selectedIndex):
        """
            Add to favorites
        """
        item = self.listItems[selectedIndex]
        
        if item.type != 'folder':
            logFile.error("AddToFavorites :: Can only add folder items. Got %s-item", item.type)
            return 
        
        settings.AddToFavorites(item, self.channelName)        
        return      
      
    #==============================================================================
    # Custom Methodes, in chronological order   
    #==============================================================================
    def ParseMainList(self):
        """ 
        accepts an url and returns an list with items of type CListItem
        Items have a name and url. This is used for the filling of the progwindow
        """
        items = []
        _data = uriHandler.Open(self.mainListUri)
        
        # first process folder items.
        _episodeItems = common.DoRegexFindAll(self.episodeItemRegex, _data)
        for _episode in _episodeItems:
            _tmpItem = self.CreateEpisodeItem(_episode)
            # catch the return of None
            if _tmpItem:
                items.append(_tmpItem)
        
        # sort by name
        if self.episodeSort:
            items.sort(lambda x, y: cmp(x.name.lower(), y.name.lower()))
        
        return items
    
    #==============================================================================
    def SearchSite(self):
        """
        Creates an list of items by searching the site
        """
        items = []
        
        item = common.clistItem("Search Not Implented","", type="video")
        item.icon = self.icon
        items.append(item)
    
        return items
    
    #==============================================================================
    def CreateEpisodeItem(self, resultSet):
        """
        Accepts an arraylist of results. It returns an item. 
        """
        logFile.debug('starting CreateEpisodeItem for %s', self.channelName)
        
        # dummy class
        _item = common.clistItem("No CreateEpisode Implented!", "")
        _item.complete = True
        return _item
    
    #==============================================================================
    def ShowEpisodeWindow(self, url):
        """ NOT USER EDITABLE
        shows the epsiode window and thus triggers the onInit
        """
        self.initialUri = url
        self.windowInitialised = False
        self.doModal()
    
    #==============================================================================
    def PreProcessFolderList(self, data):
        """
        Accepts an data from the ProcessFolderList Methode, BEFORE the items are
        processed. Allows setting of parameters (like title etc). No return value!
        """
        logFile.info("Performing Pre-Processing")
        _items = []
        logFile.debug("Pre-Processing finished")
        return (data, _items)
          
    #==============================================================================
    def ProcessFolderList(self, url):
        """ NOT USER EDITABLE
        Accepts an URL and returns a list of items with at least name & url set
        Each item can be filled using the ParseFolderItem and ParseVideoItem 
        Methodes
        """
        self.clearList()
        if not self.pluginMode:
            self.ShowData(self.folderHistory[0])
        
        _preItems = []
        _folderItems = []
        _videoItems = []
        
        if (url == "searchSite"):
            logFile.debug("Starting to search")
            return self.SearchSite()
                        
        
        _data = uriHandler.Open(url)
        
        # first of all do the Pre handler
        (_data, _preItems) = self.PreProcessFolderList(_data)
        
        # then process folder items.
        if not self.folderItemRegex == '':

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -