当前位置: 首页>>代码示例>>Python>>正文


Python Settings.getTempLocation方法代码示例

本文整理汇总了Python中settings.Settings.getTempLocation方法的典型用法代码示例。如果您正苦于以下问题:Python Settings.getTempLocation方法的具体用法?Python Settings.getTempLocation怎么用?Python Settings.getTempLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在settings.Settings的用法示例。


在下文中一共展示了Settings.getTempLocation方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createEBookObject

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import getTempLocation [as 别名]
    def createEBookObject(filePath):
        localFilePath = filePath
        removeWhenComplete = False
        if filePath.startswith('smb://') or filePath.startswith('nfs://'):
            try:
                # Copy the file to the local disk
                justFileName = os_path_split(filePath)[-1]
                copiedFile = os_path_join(Settings.getTempLocation(), justFileName)
                copy = xbmcvfs.copy(filePath, copiedFile)
                if copy:
                    log("EBookBase: copy successful for %s" % copiedFile)
                    localFilePath = copiedFile
                    removeWhenComplete = True
                else:
                    log("EBookBase: copy failed from %s to %s" % (filePath, copiedFile))
            except:
                log("EBookBase: Failed to copy file %s to local directory" % filePath)

        elif filePath.startswith('http://') or filePath.startswith('https://'):
            log("EBookBase: Book source is %s" % filePath)
            try:
                justFileName = 'opds.epub'
                if '/mobi/' in filePath:
                    justFileName = 'opds.mobi'
                elif '/pdf/' in filePath:
                    justFileName = 'opds.pdf'
                copiedFile = os_path_join(Settings.getTempLocation(), justFileName)
                fp, h = urllib.urlretrieve(filePath, copiedFile)
                log(h)
                localFilePath = copiedFile
                removeWhenComplete = True
            except:
                log("EBookBase: Failed to download file %s to local directory" % filePath)

        bookType = None
        # Check which type of EBook it is
        if localFilePath.lower().endswith('.epub'):
            bookType = EPubEBook(localFilePath, removeWhenComplete)
        elif localFilePath.lower().endswith('.mobi'):
            bookType = MobiEBook(localFilePath, removeWhenComplete)
        elif localFilePath.lower().endswith('.pdf'):
            bookType = PdfEBook(localFilePath, removeWhenComplete)
        else:
            log("EBookBase: Unknown book type for %s (%s)" % (filePath, localFilePath))

        return bookType
开发者ID:robwebset,项目名称:script.ebooks,代码行数:48,代码来源:ebook.py

示例2: extractCoverImage

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import getTempLocation [as 别名]
    def extractCoverImage(self):
        log("MobiEBook: Extracting cover for %s" % self.filePath)
        # Get the location that the book is to be extracted to
        extractDir = os_path_join(Settings.getTempLocation(), 'mobi_extracted')

        # Check if the mobi extract directory already exists
        if dir_exists(extractDir):
            try:
                shutil.rmtree(extractDir, True)
            except:
                log("MobiEBook: Failed to delete directory %s" % extractDir)

        # Extract the contents of the book so we can get the cover image
        try:
            kindleunpack.unpackBook(self.filePath, extractDir, None, '2', True)
        except:
            log("MobiEBook: Failed to extract cover for %s with error: %s" % (self.filePath, traceback.format_exc()), xbmc.LOGERROR)

        coverTargetName = None
        if dir_exists(extractDir):
            coverImages = self._findCoverImage(extractDir)

            if len(coverImages) > 0:
                coverImageSrc = coverImages[0]
                log("MobiEBook: Found cover file %s" % coverImageSrc)
                coverFileName, oldExt = os.path.splitext(self.fileName)
                cacheCoverName = "%s.jpg" % coverFileName
                coverTargetName = os_path_join(Settings.getCoverCacheLocation(), cacheCoverName)

                # Now move the file to the covers cache directory
                copy = xbmcvfs.copy(coverImageSrc, coverTargetName)
                if copy:
                    log("MobiEBook: copy successful for %s" % coverTargetName)
                else:
                    log("MobiEBook: copy failed from %s to %s" % (coverImageSrc, coverTargetName))
            else:
                log("MobiEBook: No cover image found for %s" % self.filePath)

            # Now tidy up the extracted data
            try:
                shutil.rmtree(extractDir, True)
            except:
                log("MobiEBook: Failed to tidy up directory %s" % extractDir)
        else:
            log("MobiEBook: Failed to extract Mobi file %s" % self.filePath)

        return coverTargetName
开发者ID:robwebset,项目名称:script.ebooks,代码行数:49,代码来源:ebook.py

示例3: _runFFmpegCommand

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import getTempLocation [as 别名]
    def _runFFmpegCommand(self, inputFileName, coverTargetName=None):
        # Check to see if ffmpeg is enabled
        ffmpegCmds = FfmpegBase.createHandler()

        if ffmpegCmds in [None, ""]:
            log("AudioBookHandler: ffmpeg not enabled")
            return None

        log("AudioBookHandler: Running ffmpeg for %s" % inputFileName)

        # FFmpeg will not recognise paths that start with smb:// or nfs://
        # These paths are specific to Kodi, so we need to copy the file locally
        # before we can run the FFmpeg command
        fullFileName = inputFileName
        copiedFile = self._getCopiedFileIfNeeded(inputFileName)
        if copiedFile not in [None, ""]:
            fullFileName = copiedFile

        # Check if we need the image
        coverTempName = None
        if coverTargetName not in [None, '']:
            coverTempName = os_path_join(Settings.getTempLocation(), 'maincover.jpg')
            # Remove the temporary name if it is already there
            if xbmcvfs.exists(coverTempName):
                xbmcvfs.delete(coverTempName)

        # Now make the call to gather the information
        ffmpegOutput = ffmpegCmds.getMediaInfo(fullFileName, coverTempName)
        del ffmpegCmds

        # If we had to copy the file locally, make sure we delete it
        self._removeCopiedFile(copiedFile)

        # Check if there is an image in the temporary location
        if coverTempName not in [None, ""]:
            if xbmcvfs.exists(coverTempName):
                # Now move the file to the covers cache directory
                copy = xbmcvfs.copy(coverTempName, coverTargetName)
                if copy:
                    log("AudioBookHandler: copy successful for %s" % coverTargetName)
                else:
                    log("AudioBookHandler: copy failed from %s to %s" % (coverTempName, coverTargetName))

                # Tidy up the image that we actually do not need
                xbmcvfs.delete(coverTempName)

        return ffmpegOutput
开发者ID:robwebset,项目名称:script.audiobooks,代码行数:49,代码来源:audiobook.py

示例4: _getCopiedFileIfNeeded

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import getTempLocation [as 别名]
    def _getCopiedFileIfNeeded(self, fullPath):
        copiedFile = None
        if fullPath.startswith('smb://') or fullPath.startswith('nfs://'):
            try:
                # Copy the file to the local disk
                justFileName = os_path_split(fullPath)[-1]
                copiedFile = os_path_join(Settings.getTempLocation(), justFileName)
                copy = xbmcvfs.copy(fullPath, copiedFile)
                if copy:
                    log("AudioBookHandler: copy successful for %s" % copiedFile)
                else:
                    log("AudioBookHandler: copy failed from %s to %s" % (fullPath, copiedFile))
                    copiedFile = None
            except:
                log("AudioBookHandler: Failed to copy file %s to local directory" % fullPath)
                copiedFile = None

        return copiedFile
开发者ID:robwebset,项目名称:script.audiobooks,代码行数:20,代码来源:audiobook.py

示例5: __init__

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import getTempLocation [as 别名]
    def __init__(self, base_url, addon_handle):
        self.base_url = base_url
        self.addon_handle = addon_handle

        self.tmpdestination = Settings.getTempLocation()
        self.coverCache = Settings.getCoverCacheLocation()
开发者ID:pospon,项目名称:script.audiobooks,代码行数:8,代码来源:plugin.py

示例6: getChapterContents

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import getTempLocation [as 别名]
    def getChapterContents(self, chapterLink):
        log("MobiEBook: Getting chapter contents for %s" % chapterLink)

        # Find out the name of the page that this chapter is stored in
        sections = chapterLink.split('#')

        bookFileName = None
        chapterStartFlag = None
        if len(sections) > 0:
            bookFileName = sections[0]

        if len(sections) > 1:
            chapterStartFlag = sections[1]

        # Get the content of the chapter, this will be in HTML
        chapterContent = ""

        # Get the location that the book is to be extracted to
        extractDir = os_path_join(Settings.getTempLocation(), 'mobi_extracted')

        # Check if the mobi extract directory already exists
        if dir_exists(extractDir):
            try:
                shutil.rmtree(extractDir, True)
            except:
                log("MobiEBook: Failed to delete directory %s" % extractDir)

        # Extract the contents of the book so we can get the chapter contents
        try:
            kindleunpack.unpackBook(self.filePath, extractDir, None, '2', True)
        except:
            log("MobiEBook: Failed to unpack book for %s with error: %s" % (self.filePath, traceback.format_exc()), xbmc.LOGERROR)

        # Find the file containing the book contents
        bookFileLocation = self._findBookFile(extractDir, bookFileName)

        bookContents = ""
        if bookFileLocation not in [None, ""]:
            # Read the contents of the file
            try:
                # Read the contents of the book file into a string
                bookFile = xbmcvfs.File(bookFileLocation, 'r')
                bookContents = bookFile.read()
                bookFile.close()
            except:
                log("MobiEBook: Failed to read contents of book %s with error: %s" % (bookFileName, traceback.format_exc()), xbmc.LOGERROR)
        else:
            log("MobiEBook: Failed to find book content file %s" % bookFileName)

        # Cleanup the extract directory
        if dir_exists(extractDir):
            try:
                shutil.rmtree(extractDir, True)
            except:
                log("MobiEBook: Failed to delete directory %s" % extractDir)

        chapterContent = ""
        if bookContents not in [None, ""]:
            if chapterStartFlag is not None:
                # Split out the chapter (For now just add the whole book)
                # Split based on page markers
                pageBreaks = bookContents.split('<mbp:pagebreak/>')
                anchorHtml = "<a id=\"%s\"" % chapterStartFlag
                # Find which section contains this anchor
                for page in pageBreaks:
                    if anchorHtml in page.decode("utf-8"):
                        log("MobiEBook: Found page for chapter marker %s" % chapterStartFlag)
                        chapterContent = self._mobiHtmlParsing(page)
                        break
            else:
                log("MobiEBook: Chapter start flag, showing whole book")
                chapterContent = self._mobiHtmlParsing(bookContents)

        if chapterContent not in [None, ""]:
            chapterContent = self.convertHtmlIntoKodiText(chapterContent)

        return chapterContent
开发者ID:robwebset,项目名称:script.ebooks,代码行数:79,代码来源:ebook.py

示例7: getChapterDetails

# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import getTempLocation [as 别名]
    def getChapterDetails(self):
        log("MobiEBook: Extracting chapter list for %s" % self.filePath)
        # Get the location that the book is to be extracted to
        extractDir = os_path_join(Settings.getTempLocation(), 'mobi_extracted')

        # Check if the mobi extract directory already exists
        if dir_exists(extractDir):
            try:
                shutil.rmtree(extractDir, True)
            except:
                log("MobiEBook: Failed to delete directory %s" % extractDir)

        # Extract the contents of the book so we can get the cover image
        try:
            kindleunpack.unpackBook(self.filePath, extractDir, None, '2', True)
        except:
            log("MobiEBook: Failed to unpack book for %s with error: %s" % (self.filePath, traceback.format_exc()), xbmc.LOGERROR)

        chapterDetails = []
        if dir_exists(extractDir):
            tocNcx = self._findTocNcx(extractDir)

            if tocNcx not in [None, ""]:
                log("MobiEBook: TOC file found: %s" % tocNcx)
                # Now we have the TOC file, we need to parse it, we already have
                # a tool for that, as it is the ePub format
                try:
                    # Read the contents of the TOC file into a string
                    tocFile = xbmcvfs.File(tocNcx, 'r')
                    tocStr = tocFile.read()
                    tocFile.close()

                    # Now load it into the parser
                    toc = epub.ncx.parse_toc(tocStr)

                    # Get all the chapters
                    for navPoint in toc.nav_map.nav_point:
                        # Get each of the chapter labels
                        for aLabelGroup in navPoint.labels:
                            if aLabelGroup not in [None, ""]:
                                for aLabel in aLabelGroup:
                                    if aLabel not in [None, ""]:
                                        log("MobiEBook: Adding chapter %s with src %s" % (aLabel, navPoint.src))
                                        detail = {'title': aLabel.encode("utf-8"), 'link': navPoint.src}
                                        chapterDetails.append(detail)
                                        # Only need the first string for this label group
                                        break
                    del toc
                except:
                    log("MobiEBook: Failed to process TOC %s with error: %s" % (tocNcx, traceback.format_exc()), xbmc.LOGERROR)

            else:
                log("MobiEBook: Failed to find TOC file")

            # Check if we have any chapters, if there are none, then we should show the whole book
            if (len(chapterDetails) < 1) or (not Settings.onlyShowWholeBookIfChapters()):
                htmlFiles = self._findHtmlFiles(extractDir)

                # Check if there are any html files
                if len(htmlFiles) > 0:
                    keyHtmlFile = None
                    for htmlFile in htmlFiles:
                        if htmlFile.endswith('book.html'):
                            keyHtmlFile
                            break
                    if keyHtmlFile is None:
                        keyHtmlFile = htmlFiles[0]

                    detail = {'title': ADDON.getLocalizedString(32016), 'link': keyHtmlFile}
                    chapterDetails.insert(0, detail)

            # Now tidy up the extracted data
            try:
                shutil.rmtree(extractDir, True)
            except:
                log("MobiEBook: Failed to tidy up directory %s" % extractDir)
        else:
            log("MobiEBook: Failed to extract Mobi file %s" % self.filePath)

        return chapterDetails
开发者ID:robwebset,项目名称:script.ebooks,代码行数:82,代码来源:ebook.py


注:本文中的settings.Settings.getTempLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。