Пример #1
0
    def markReadStatus(self, fullpath, chapterLink, markRead):
        # If there is no chapter link then we are clearing the read flag for the whole book
        # If the request was just for a chapter, then we would have been given the previous
        # chapter that would have been marked as read
        bookDB = EbooksDB()
        bookDB.setReadChapter(fullpath, chapterLink, markRead)
        del bookDB

        xbmc.executebuiltin("Container.Refresh")
Пример #2
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)
Пример #3
0
    def readChapter(self, fullpath, chapterTitle, chapterLink, isFirstChapter,
                    isLastChapter):
        log("EBooksPlugin: Showing chapter %s" % chapterLink)

        # It could take a little while to get the part of the book required so show the busy dialog
        xbmc.executebuiltin("ActivateWindow(busydialog)")

        # Get the content of the chapter
        eBook = EBookBase.createEBookObject(fullpath)
        chapterContent = eBook.getChapterContents(chapterLink)

        xbmc.executebuiltin("Dialog.Close(busydialog)")

        readerWindow = TextViewer.createTextViewer(chapterTitle,
                                                   chapterContent,
                                                   isFirstChapter,
                                                   isLastChapter)
        # Display the window
        readerWindow.show()

        readStatusChanged = False
        readingChapter = chapterLink
        isShowingLastChapter = isLastChapter
        # Now wait until the text is finished with and the viewer is closed
        while (not readerWindow.isClosed()) and (not xbmc.abortRequested):
            xbmc.sleep(100)

            # Now that the chapter has been read, update the database record
            if readerWindow.isRead():
                readStatusChanged = True
                bookDB = EbooksDB()
                bookDB.setReadChapter(fullpath, readingChapter,
                                      isShowingLastChapter)
                del bookDB

            # Check if this chapter is read and a new chapter is to be started
            if readerWindow.isNext():
                xbmc.executebuiltin("ActivateWindow(busydialog)")
                # Find the next chapter
                chapters = self._getChapters(fullpath, eBook)
                nextChapterMatch = False
                for chapter in chapters:
                    # Check if this is the chapter we are moving to
                    if nextChapterMatch:
                        isShowingLastChapter = False
                        if chapter['lastChapter'] == 'true':
                            isShowingLastChapter = True
                        readingChapter = chapter['link']
                        readerWindow.updateScreen(
                            chapter['title'],
                            eBook.getChapterContents(readingChapter), False,
                            isShowingLastChapter)
                        break
                    if chapter['link'] == readingChapter:
                        nextChapterMatch = True
                xbmc.executebuiltin("Dialog.Close(busydialog)")

            if readerWindow.isPrevious():
                xbmc.executebuiltin("ActivateWindow(busydialog)")
                # Find the previous chapter
                chapters = self._getChapters(fullpath, eBook)
                previousChapter = None
                isFirstChapterVal = 'true'
                for chapter in chapters:
                    if chapter['link'] == readingChapter:
                        break
                    previousChapter = chapter['link']
                    isFirstChapterVal = chapter['firstChapter']
                # Check if this is the chapter we are moving to
                if previousChapter not in [None, "", readingChapter]:
                    isShowingLastChapter = False
                    isFirstChapter = False
                    if isFirstChapterVal == 'true':
                        isFirstChapter = True
                    readingChapter = previousChapter
                    readerWindow.updateScreen(
                        chapter['title'],
                        eBook.getChapterContents(readingChapter),
                        isFirstChapter, False)
                xbmc.executebuiltin("Dialog.Close(busydialog)")

        eBook.tidyUp()
        del eBook

        # If this chapter was marked as read then we need to refresh to pick up the record
        if readStatusChanged:
            xbmc.executebuiltin("Container.Refresh")

        del readerWindow
Пример #4
0
    def listChapters(self, fullpath, defaultImage):
        log("EBooksPlugin: Listing chapters for %s" % fullpath)

        # Get the current chapter that has been read from the database
        readChapter = None
        readAll = False
        bookDB = EbooksDB()
        bookDetails = bookDB.getBookDetails(fullpath)
        del bookDB

        bookAuthorAndTitle = ""
        if bookDetails is not None:
            readChapter = bookDetails['readchapter']
            readAll = bookDetails['complete']
            # Create the author/title combination
            bookAuthorAndTitle = "[B]%s[/B]\n[I]%s[/I]" % (
                bookDetails['title'], bookDetails['author'])

        eBook = EBookBase.createEBookObject(fullpath)
        # Get the chapters for this book
        chapters = self._getChapters(fullpath, eBook)

        if bookAuthorAndTitle in [None, ""]:
            bookAuthorAndTitle = "[B]%s[/B]\n[I]%s[/I]" % (eBook.getTitle(),
                                                           eBook.getAuthor())

        eBook.tidyUp()
        del eBook

        foundMatchedReadChapter = False
        # Add all the chapters to the display
        for chapter in chapters:
            url = self._build_url({
                'mode': 'readChapter',
                'filename': chapter['filename'],
                'title': chapter['title'],
                'link': chapter['link'],
                'firstChapter': chapter['firstChapter'],
                'lastChapter': chapter['lastChapter']
            })

            # Check if we have already reached this chapter, if so, and the new chapter does not
            # point to the same chapter, then we no-longer mark as read
            if foundMatchedReadChapter:
                if readChapter != chapter['link']:
                    readChapter = None

            readFlag = ''
            # Check if this chapter has been read
            if readAll or (readChapter not in [None, ""]):
                log("EBooksPlugin: Setting chapter as read %s" %
                    chapter['link'])
                readFlag = '* '  # Wanted to use a tick, but it didn't work - u'\u2713'
                # The following will only work it the plug-in is for videos, which in our
                # case it is not (So instead to prepend a character to indicate it has been read
                # li.setInfo('video', {'PlayCount': 1})
            displaytitle = "%s%s" % (readFlag, chapter['title'])

            # Check if this is the last chapter read, as we do not want to flag any more
            # as read if this is as far as we got
            if readChapter == chapter['link']:
                foundMatchedReadChapter = True

            li = xbmcgui.ListItem(displaytitle, iconImage=defaultImage)
            li.setProperty("Fanart_Image", EBookBase.getFanArt(fullpath))
            # Set the Author and book title as the Plot, that will be shown on some skins
            li.setInfo('video', {'Plot': bookAuthorAndTitle})
            li.addContextMenuItems(self._getContextMenu(
                fullpath, chapter['link'], chapter['previousLink'],
                chapter['lastChapter']),
                                   replaceItems=True)
            xbmcplugin.addDirectoryItem(handle=self.addon_handle,
                                        url=url,
                                        listitem=li,
                                        isFolder=False)

        xbmcplugin.endOfDirectory(self.addon_handle)
Пример #5
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)
Пример #6
0
# -*- coding: utf-8 -*-
import xbmcaddon

# Import the common settings
from resources.lib.settings import log
from resources.lib.database import EbooksDB


ADDON = xbmcaddon.Addon(id='script.ebooks')


#########################
# Main
#########################
if __name__ == '__main__':
    log("eBookService: Checking eBooks database version (version %s)" % ADDON.getAddonInfo('version'))

    ebooksDB = EbooksDB()
    ebooksDB.createOrUpdateDB()
    del ebooksDB