コード例 #1
0
    def rootMenu(self):
        rootOpds = Settings.getOPDSLocation()

        # If OPDS is not being used then just use the directory details
        if rootOpds in [None, ""]:
            self.showEbooksDirectory()
            return

        # Get the setting for the ebook directory
        eBookFolder = Settings.getEbookFolder()

        # If OPDS is enabled and there is no local folder set, then just use OPDS
        if eBookFolder in [None, ""]:
            self.opdsRootMenu()
            return

        # Both OPDS and local directory is enabled, so give the user the choice
        url = self._build_url({'mode': 'directory', 'directory': ' '})
        li = xbmcgui.ListItem(ADDON.getLocalizedString(32005),
                              iconImage='DefaultFolder.png')
        li.setProperty("Fanart_Image", FANART)
        li.addContextMenuItems([], replaceItems=True)
        xbmcplugin.addDirectoryItem(handle=self.addon_handle,
                                    url=url,
                                    listitem=li,
                                    isFolder=True)

        opds = Opds()
        iconImage = opds.getRootImage()
        opdsTitle = opds.getRootTitle()
        del opds
        url = self._build_url({'mode': 'opds', 'href': ' '})
        li = xbmcgui.ListItem(ADDON.getLocalizedString(32023),
                              iconImage=iconImage)
        li.setProperty("Fanart_Image", FANART)
        li.setInfo('video', {'Plot': "[B]%s[/B]" % opdsTitle})
        li.addContextMenuItems([], replaceItems=True)
        xbmcplugin.addDirectoryItem(handle=self.addon_handle,
                                    url=url,
                                    listitem=li,
                                    isFolder=True)

        xbmcplugin.endOfDirectory(self.addon_handle)
コード例 #2
0
    def showEbooksDirectory(self, directory=''):
        log("EBooksPlugin: Showing eBooks for directory %s" % str(directory))

        # Get the setting for the ebook directory
        eBookFolder = Settings.getEbookFolder()

        if eBookFolder in [None, ""]:
            # Prompt the user to set the eBooks Folder
            eBookFolder = xbmcgui.Dialog().browseSingle(
                0, ADDON.getLocalizedString(32005), 'files')

            # Check to make sure the directory is set now
            if eBookFolder in [None, ""]:
                xbmcgui.Dialog().ok(ADDON.getLocalizedString(32001),
                                    ADDON.getLocalizedString(32006))
                return

            # Save the directory in settings for future use
            log("EBooksPlugin: Setting eBooks folder to %s" % eBookFolder)
            Settings.setEbookFolder(eBookFolder)

        # We may be looking at a subdirectory
        if directory.strip() not in [None, ""]:
            eBookFolder = directory

        dirs, files = xbmcvfs.listdir(eBookFolder)
        dirs.sort()
        files.sort()

        # For each directory list allow the user to navigate into it
        for adir in dirs:
            if adir.startswith('.'):
                continue

            log("EBooksPlugin: Adding directory %s" % adir)

            nextDir = os_path_join(eBookFolder, adir)
            displayName = "[%s]" % adir

            try:
                displayName = "[%s]" % adir.encode("utf-8")
            except:
                displayName = "[%s]" % adir
            try:
                nextDir = nextDir.encode("utf-8")
            except:
                pass

            # Check if there is a folder image in the directory
            folderImage = 'DefaultFolder.png'
            fanartImage = FANART
            subdirs, filesInDir = xbmcvfs.listdir(nextDir)
            for fileInDir in filesInDir:
                if fileInDir.lower() in [
                        'folder.jpg', 'cover.jpg', 'folder.png', 'cover.png'
                ]:
                    folderImage = os_path_join(nextDir, fileInDir)
                elif fileInDir.lower() in ['fanart.jpg', 'fanart.png']:
                    fanartImage = os_path_join(nextDir, fileInDir)

            url = self._build_url({'mode': 'directory', 'directory': nextDir})
            li = xbmcgui.ListItem(displayName, iconImage=folderImage)
            li.setProperty("Fanart_Image", fanartImage)
            plotDisplay = "[B]%s[/B]" % adir
            li.setInfo('video', {'Plot': plotDisplay})
            li.addContextMenuItems([], replaceItems=True)
            xbmcplugin.addDirectoryItem(handle=self.addon_handle,
                                        url=url,
                                        listitem=li,
                                        isFolder=True)

        # Now list all of the books
        for eBookFile in files:
            log("EBooksPlugin: Processing file %s" % eBookFile)
            # Check to ensure that this is an eBook
            if not Settings.isEbookFormat(eBookFile):
                log("EBooksPlugin: Skipping non ebook file: %s" % eBookFile)
                continue

            fullpath = os_path_join(eBookFolder, eBookFile)

            # Check in the database to see if this book is already recorded
            bookDB = EbooksDB()
            bookDetails = bookDB.getBookDetails(fullpath)

            title = ""
            author = ""
            description = ""
            isRead = False
            if bookDetails in [None, ""]:
                # Need the details of this book
                # Get the details of this book
                eBook = EBookBase.createEBookObject(fullpath)
                title = eBook.getTitle()
                author = eBook.getAuthor()
                description = eBook.getDescription()
                eBook.tidyUp()
                del eBook

                # Add this book to the list
                bookDB.addBook(fullpath, title, author, description)
            else:
                isRead = bookDetails['complete']
                title = bookDetails['title']
                author = bookDetails['author']
                description = bookDetails['description']
            del bookDB

            displayString = eBookFile
            try:
                displayString = title.encode("utf-8")
            except:
                displayString = title
            if author not in [None, ""]:
                try:
                    author = author.encode("utf-8")
                except:
                    pass
                try:
                    displayString = "%s - %s" % (author, displayString)
                except:
                    pass
            try:
                # With some text, logging is causing issues
                log("EBookBase: Display title is %s for %s" %
                    (displayString, fullpath))
            except:
                pass

            if isRead:
                try:
                    displayString = '* %s' % displayString
                except:
                    log("EBookBase: Unable to mark as read")

            coverTargetName = EBookBase.getCoverImage(fullpath, eBookFile)
            if coverTargetName in [None, ""]:
                coverTargetName = Settings.getFallbackCoverImage()

            try:
                fullpath = fullpath.encode("utf-8")
            except:
                pass

            if coverTargetName not in [None, ""]:
                try:
                    coverTargetName = coverTargetName.encode("utf-8")
                except:
                    pass

            url = self._build_url({
                'mode': 'chapters',
                'filename': fullpath,
                'cover': coverTargetName
            })
            li = xbmcgui.ListItem(displayString, iconImage=coverTargetName)
            li.setProperty("Fanart_Image", EBookBase.getFanArt(fullpath))
            if description not in [None, ""]:
                li.setInfo('video', {'Plot': description})
            li.addContextMenuItems(self._getContextMenu(fullpath),
                                   replaceItems=True)
            xbmcplugin.addDirectoryItem(handle=self.addon_handle,
                                        url=url,
                                        listitem=li,
                                        isFolder=True)

        xbmcplugin.endOfDirectory(self.addon_handle)