Esempio n. 1
0
    def _showEbooks(self, books):
        # List all of the books
        for bookDetails in books:
            log("EBooksPlugin: Processing title: %s, author: %s, link: %s, cover: %s"
                % (bookDetails['title'], bookDetails['author'],
                   bookDetails['link'], bookDetails['cover']))

            # Check in the database to see if this book is already recorded
            bookDB = EbooksDB()
            dbBookDetails = bookDB.getBookDetails(bookDetails['link'])

            isRead = False
            if dbBookDetails in [None, ""]:
                # Add this book to the list
                bookDB.addBook(bookDetails['link'], bookDetails['title'],
                               bookDetails['author'],
                               bookDetails['description'])
            else:
                isRead = dbBookDetails['complete']

            del bookDB

            displayString = bookDetails['title']
            if bookDetails['author'] not in [None, ""]:
                displayString = "%s - %s" % (bookDetails['author'],
                                             displayString)
            log("EBookBase: Display title is %s for %s" %
                (displayString, bookDetails['link']))

            if isRead:
                displayString = '* %s' % displayString

            coverTargetName = bookDetails['cover']
            if coverTargetName in [None, ""]:
                coverTargetName = Settings.getFallbackCoverImage()

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

        xbmcplugin.endOfDirectory(self.addon_handle)
Esempio n. 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)