• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python helpers.sanitizeFileName函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sickbeard.helpers.sanitizeFileName函数的典型用法代码示例。如果您正苦于以下问题:Python sanitizeFileName函数的具体用法?Python sanitizeFileName怎么用?Python sanitizeFileName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: _makeURL

    def _makeURL(self, result):
        urls = []
        filename = u''
        if result.url.startswith('magnet'):
            try:
                torrent_hash = re.findall(r'urn:btih:([\w]{32,40})', result.url)[0].upper()

                try:
                    torrent_name = re.findall('dn=([^&]+)', result.url)[0]
                except Exception:
                    torrent_name = 'NO_DOWNLOAD_NAME'

                if len(torrent_hash) == 32:
                    torrent_hash = b16encode(b32decode(torrent_hash)).upper()

                if not torrent_hash:
                    logger.log(u"Unable to extract torrent hash from magnet: " + ex(result.url), logger.ERROR)
                    return urls, filename

                urls = [x.format(torrent_hash=torrent_hash, torrent_name=torrent_name) for x in self.btCacheURLS]
            except Exception:
                logger.log(u"Unable to extract torrent hash or name from magnet: " + ex(result.url), logger.ERROR)
                return urls, filename
        else:
            urls = [result.url]

        if self.providerType == GenericProvider.TORRENT:
            filename = ek(os.path.join, sickbeard.TORRENT_DIR,
                          helpers.sanitizeFileName(result.name) + '.' + self.providerType)

        elif self.providerType == GenericProvider.NZB:
            filename = ek(os.path.join, sickbeard.NZB_DIR,
                          helpers.sanitizeFileName(result.name) + '.' + self.providerType)

        return urls, filename
开发者ID:VinceVal,项目名称:SickRage,代码行数:35,代码来源:generic.py


示例2: _makeURL

    def _makeURL(self, result):
        urls = []
        filename = u''
        if result.url.startswith('magnet'):
            try:
                torrent_hash = re.findall('urn:btih:([\w]{32,40})', result.url)[0].upper()
                torrent_name = re.findall('dn=([^&]+)', result.url)[0]

                if len(torrent_hash) == 32:
                    torrent_hash = b16encode(b32decode(torrent_hash)).upper()

                if not torrent_hash:
                    logger.log("Unable to extract torrent hash from link: " + ex(result.url), logger.ERROR)
                    return (urls, filename)

                urls = [
                    'http://torcache.net/torrent/' + torrent_hash + '.torrent',
                    'http://zoink.ch/torrent/' + torrent_name + '.torrent',
                    'http://torrage.com/torrent/' + torrent_hash + '.torrent',
                ]
            except:
                urls = [result.url]
        else:
            urls = [result.url]

        if self.providerType == GenericProvider.TORRENT:
            filename = ek.ek(os.path.join, sickbeard.TORRENT_DIR,
                             helpers.sanitizeFileName(result.name) + '.' + self.providerType)

        elif self.providerType == GenericProvider.NZB:
            filename = ek.ek(os.path.join, sickbeard.NZB_DIR,
                             helpers.sanitizeFileName(result.name) + '.' + self.providerType)

        return (urls, filename)
开发者ID:bckwltn,项目名称:SickRage-MAC-MASTER,代码行数:34,代码来源:generic.py


示例3: downloadResult

    def downloadResult(self, result):
        """
        Save the result to disk.
        """

        # check for auth
        if not self._doLogin():
            return False

        if self.providerType == GenericProvider.TORRENT:
            try:
                torrent_hash = re.findall('urn:btih:([\w]{32,40})', result.url)[0].upper()
                torrent_name = re.findall('dn=([^&]+)', result.url)[0]

                if len(torrent_hash) == 32:
                    torrent_hash = b16encode(b32decode(torrent_hash)).upper()

                if not torrent_hash:
                    logger.log("Unable to extract torrent hash from link: " + ex(result.url), logger.ERROR)
                    return False

                urls = [
                    'http://torcache.net/torrent/' + torrent_hash + '.torrent',
                    'http://zoink.ch/torrent/' + torrent_name + '.torrent',
                    'http://torrage.com/torrent/' + torrent_hash + '.torrent',
                ]
            except:
                urls = [result.url]

            filename = ek.ek(os.path.join, sickbeard.TORRENT_DIR,
                             helpers.sanitizeFileName(result.name) + '.' + self.providerType)
        elif self.providerType == GenericProvider.NZB:
            urls = [result.url]

            filename = ek.ek(os.path.join, sickbeard.NZB_DIR,
                             helpers.sanitizeFileName(result.name) + '.' + self.providerType)
        else:
            return

        for url in urls:
            logger.log(u"Downloading a result from " + self.name + " at " + url)
            if helpers.download_file(url, filename, session=self.session):
                if self._verify_download(filename):
                    if self.providerType == GenericProvider.TORRENT:
                        logger.log(u"Saved magnet link to " + filename, logger.INFO)
                    else:
                        logger.log(u"Saved result to " + filename, logger.INFO)
                    return True
                else:
                    logger.log(u"Could not download %s" % url, logger.WARNING)
                    helpers._remove_file_failed(filename)

        if len(urls):
            logger.log(u"Failed to download any results", logger.WARNING)

        return False
开发者ID:ingolfured,项目名称:SickRage,代码行数:56,代码来源:generic.py


示例4: download_result

    def download_result(self, result):
        """
        Save the result to disk.
        """

        # check for auth
        if not self._do_login():
            return False

        if GenericProvider.TORRENT == self.providerType:
            try:
                torrent_hash = re.findall('urn:btih:([0-9a-f]{32,40})', result.url)[0].upper()

                if 32 == len(torrent_hash):
                    torrent_hash = b16encode(b32decode(torrent_hash)).lower()

                if not torrent_hash:
                    logger.log('Unable to extract torrent hash from link: ' + ex(result.url), logger.ERROR)
                    return False

                urls = ['https://%s/%s.torrent' % (u, torrent_hash)
                        for u in ('torcache.net/torrent', 'torrage.com/torrent', 'getstrike.net/torrents/api/download')]
            except:
                urls = [result.url]

            filename = ek.ek(os.path.join, sickbeard.TORRENT_DIR,
                             helpers.sanitizeFileName(result.name) + '.' + self.providerType)
        elif GenericProvider.NZB == self.providerType:
            urls = [result.url]

            filename = ek.ek(os.path.join, sickbeard.NZB_DIR,
                             helpers.sanitizeFileName(result.name) + '.' + self.providerType)
        else:
            return

        for url in urls:
            if helpers.download_file(url, filename, session=self.session):
                logger.log(u'Downloading a result from ' + self.name + ' at ' + url)

                if GenericProvider.TORRENT == self.providerType:
                    logger.log(u'Saved magnet link to ' + filename, logger.MESSAGE)
                else:
                    logger.log(u'Saved result to ' + filename, logger.MESSAGE)

                if self._verify_download(filename):
                    return True
                elif ek.ek(os.path.isfile, filename):
                    ek.ek(os.remove, filename)

        logger.log(u'Failed to download result', logger.ERROR)
        return False
开发者ID:joshguerette,项目名称:SickGear,代码行数:51,代码来源:generic.py


示例5: downloadResult

    def downloadResult(self, result):

        logger.log(u"Downloading a result from " + self.name + " at " + result.url)

        data = self.getURL(result.url)

        if data == None:
            return False

        if self.providerType == GenericProvider.NZB:
            saveDir = sickbeard.NZB_DIR
            writeMode = "w"
        elif self.providerType == GenericProvider.TORRENT:
            saveDir = sickbeard.TORRENT_DIR
            writeMode = "wb"
        else:
            return False

        fileName = ek.ek(os.path.join, saveDir, helpers.sanitizeFileName(result.name) + "." + self.providerType)

        logger.log(u"Saving to " + fileName, logger.DEBUG)

        fileOut = open(fileName, writeMode)
        fileOut.write(data)
        fileOut.close()

        return True
开发者ID:andrenalin1981,项目名称:qpkg-sickbeard,代码行数:27,代码来源:generic.py


示例6: addDefaultShow

    def addDefaultShow(self, indexer, indexer_id, name, status):
        """
        Adds a new show with the default settings
        """
        if not helpers.findCertainShow(sickbeard.showList, int(indexer_id)):
            logger.log(u"Adding show " + str(indexer_id))
            root_dirs = sickbeard.ROOT_DIRS.split('|')

            try:
                location = root_dirs[int(root_dirs[0]) + 1]
            except:
                location = None

            if location:
                showPath = ek.ek(os.path.join, location, helpers.sanitizeFileName(name))
                dir_exists = helpers.makeDir(showPath)
                if not dir_exists:
                    logger.log(u"Unable to create the folder " + showPath + ", can't add the show", logger.ERROR)
                    return
                else:
                    helpers.chmodAsParent(showPath)

                sickbeard.showQueueScheduler.action.addShow(int(indexer), int(indexer_id), showPath, status,
                                                            int(sickbeard.QUALITY_DEFAULT),
                                                            int(sickbeard.FLATTEN_FOLDERS_DEFAULT))
            else:
                logger.log(u"There was an error creating the show, no root directory setting found", logger.ERROR)
                return
开发者ID:TonyMear,项目名称:SickRage,代码行数:28,代码来源:traktChecker.py


示例7: downloadResult

    def downloadResult(self, result):

        logger.log(u"Downloading a result from " + self.name+" at " + result.url)

        data = self.getURL(result.url)

        if data == None:
            return False

        if self.providerType == GenericProvider.NZB:
            saveDir = sickbeard.NZB_DIR
            writeMode = 'w'
        elif self.providerType == GenericProvider.TORRENT:
            saveDir = sickbeard.TORRENT_DIR
            writeMode = 'wb'
        else:
            return False

        fileName = ek.ek(os.path.join, saveDir, helpers.sanitizeFileName(result.name) + '.' + self.providerType)

        logger.log(u"Saving to " + fileName, logger.DEBUG)

        try:
            fileOut = open(fileName, writeMode)
            fileOut.write(data)
            fileOut.close()
        except IOError, e:
            logger.log("Unable to save the NZB: "+str(e).decode('utf-8'), logger.ERROR)
            return False
开发者ID:LethalCorpse,项目名称:Sick-Beard,代码行数:29,代码来源:generic.py


示例8: addDefaultShow

    def addDefaultShow(self, indexer, indexer_id, name, status):
        """
        Adds a new show with the default settings
        """
        if not helpers.findCertainShow(sickbeard.showList, int(indexer_id)):
            logger.log(u"Adding show " + str(indexer_id))
            root_dirs = sickbeard.ROOT_DIRS.split('|')

            try:
                location = root_dirs[int(root_dirs[0]) + 1]
            except:
                location = None

            if location:
                showPath = ek(os.path.join, location, helpers.sanitizeFileName(name))
                dir_exists = helpers.makeDir(showPath)
                if not dir_exists:
                    logger.log(u"Unable to create the folder %s , can't add the show" % showPath, logger.WARNING)
                    return
                else:
                    helpers.chmodAsParent(showPath)

                sickbeard.showQueueScheduler.action.addShow(int(indexer), int(indexer_id), showPath,
                                                            default_status=status,
                                                            quality=int(sickbeard.QUALITY_DEFAULT),
                                                            flatten_folders=int(sickbeard.FLATTEN_FOLDERS_DEFAULT),
                                                            paused=sickbeard.TRAKT_START_PAUSED,
                                                            default_status_after=status,
                                                            archive=sickbeard.ARCHIVE_DEFAULT)
            else:
                logger.log(u"There was an error creating the show, no root directory setting found", logger.WARNING)
                return
开发者ID:BreizhCat,项目名称:SickRage,代码行数:32,代码来源:traktChecker.py


示例9: downloadResult

    def downloadResult(self, result):
        """
        Save the result to disk.
        """

        logger.log(u"Downloading a result from " + self.name + " at " + result.url)

        data = self.getURL(result.url)

        if data is None:
            return False

        # use the appropriate watch folder
        if self.providerType == GenericProvider.NZB:
            saveDir = sickbeard.NZB_DIR
            writeMode = 'w'
        elif self.providerType == GenericProvider.TORRENT:
            saveDir = sickbeard.TORRENT_DIR
            writeMode = 'wb'
        else:
            return False

        # use the result name as the filename
        file_name = ek.ek(os.path.join, saveDir, helpers.sanitizeFileName(result.name) + '.' + self.providerType)

        logger.log(u"Saving to " + file_name, logger.DEBUG)

        try:
            with open(file_name, writeMode) as fileOut:
                fileOut.write(data)
            helpers.chmodAsParent(file_name)
        except EnvironmentError, e:
            logger.log("Unable to save the file: " + ex(e), logger.ERROR)
            return False
开发者ID:achlee,项目名称:SickRage,代码行数:34,代码来源:generic.py


示例10: downloadResult

    def downloadResult(self, nzb):

        id = self.getIDFromURL(nzb.url)
        if not id:
            logger.log("Unable to get an ID from " + str(nzb.url) + ", can't download from Newzbin's API", logger.ERROR)
            return False

        logger.log("Downloading an NZB from newzbin with id " + id)

        fileName = ek.ek(os.path.join, sickbeard.NZB_DIR, helpers.sanitizeFileName(nzb.name) + ".nzb")
        logger.log("Saving to " + fileName)

        urllib._urlopener = NewzbinDownloader()

        params = urllib.urlencode(
            {"username": sickbeard.NEWZBIN_USERNAME, "password": sickbeard.NEWZBIN_PASSWORD, "reportid": id}
        )
        try:
            urllib.urlretrieve(self.url + "api/dnzb/", fileName, data=params)
        except exceptions.NewzbinAPIThrottled:
            logger.log("Done waiting for Newzbin API throttle limit, starting downloads again")
            self.downloadResult(nzb)
        except (urllib.ContentTooShortError, IOError), e:
            logger.log("Error downloading NZB: " + str(sys.exc_info()) + " - " + ex(e), logger.ERROR)
            return False
开发者ID:ycros,项目名称:Sick-Beard,代码行数:25,代码来源:newzbin.py


示例11: _destination_file_name

 def _destination_file_name(self, new_name):
     existing_extension = self.file_name.rpartition('.')[-1]
     new_name = helpers.sanitizeFileName(new_name)
     
     if sickbeard.RENAME_EPISODES:
         return new_name + '.' + existing_extension
     else:
         return self.file_name 
开发者ID:Darkmadda,项目名称:Sick-Beard,代码行数:8,代码来源:postProcessor.py


示例12: renameFile

def renameFile(movedFilePath, newName):

    filePath = os.path.split(movedFilePath)
    oldFile = os.path.splitext(filePath[1])

    renamedFilePathname = ek.ek(os.path.join, filePath[0], helpers.sanitizeFileName(newName) + oldFile[1])

    logger.log(u"Renaming from " + movedFilePath + " to " + renamedFilePathname)

    try:
        ek.ek(os.rename, movedFilePath, renamedFilePathname)
    except (OSError, IOError), e:
        logger.log(u"Failed renaming " + movedFilePath + " to " + os.path.basename(renamedFilePathname) + ": " + str(e), logger.ERROR)
        return False
开发者ID:andrenalin1981,项目名称:qpkg-sickbeard,代码行数:14,代码来源:processTV.py


示例13: renameFile

def renameFile(curFile, newName):

    filePath = os.path.split(curFile)
    oldFile = os.path.splitext(filePath[1])

    newFilename = ek.ek(os.path.join, filePath[0], helpers.sanitizeFileName(newName) + oldFile[1])

    logger.log("Renaming from " + curFile + " to " + newFilename)

    try:
        ek.ek(os.rename, curFile, newFilename)
    except (OSError, IOError), e:
        logger.log("Failed renaming " + curFile + " to " + os.path.basename(newFilename) + ": " + str(e), logger.ERROR)
        return False
开发者ID:RickDB,项目名称:Sick-Beard,代码行数:14,代码来源:processTV.py


示例14: downloadResult

 def downloadResult(self, result):
     try:
         logger.log(u"Downloading a result from " + self.name + " at " + result.url)
         
         torrentFileName = ek.ek(os.path.join, sickbeard.TORRENT_DIR, helpers.sanitizeFileName(result.name) + '.' + self.providerType)
         #add self referer to get application/x-bittorrent from torcache.net
         data = self.getURL(result.url, [("Referer", result.url)])
         if data == None:
             return False
         fileOut = open(torrentFileName, 'wb')
         logger.log(u"Saving to " + torrentFileName, logger.DEBUG)
         fileOut.write(data)
         fileOut.close()
         helpers.chmodAsParent(torrentFileName)
         return self._verify_download(torrentFileName)
     except Exception, e:
         logger.log("Unable to save the file: "+str(e).decode('utf-8'), logger.ERROR)
         return False
开发者ID:cagnulein,项目名称:Sick-Beard,代码行数:18,代码来源:kickass.py


示例15: downloadTorrent

def downloadTorrent (torrent):
    
    logger.log("Downloading a torrent from [email protected] at " + torrent.url)

    data = _getEZTVURL(torrent.url)
    
    if data == None:
        return False
    
    fileName = os.path.join(sickbeard.TORRENT_DIR, helpers.sanitizeFileName(torrent.name)+".torrent")
    
    logger.log("Saving to " + fileName, logger.DEBUG)
    
    fileOut = open(fileName, "wb")
    fileOut.write(data)
    fileOut.close()

    return True
开发者ID:RickDB,项目名称:Sick-Beard,代码行数:18,代码来源:eztv.py


示例16: downloadNZB

def downloadNZB(nzb):

	logger.log("Downloading an NZB from newzbin at " + nzb.url)

	fileName = os.path.join(sickbeard.NZB_DIR, helpers.sanitizeFileName(nzb.fileName()))
	logger.log("Saving to " + fileName, logger.DEBUG)

	urllib._urlopener = NewzbinDownloader()

	params = urllib.urlencode({"username": sickbeard.NEWZBIN_USERNAME, "password": sickbeard.NEWZBIN_PASSWORD, "reportid": nzb.extraInfo[0]})
	try:
		urllib.urlretrieve("http://v3.newzbin.com/api/dnzb/", fileName, data=params)
	except exceptions.NewzbinAPIThrottled:
		logger.log("Done waiting for Newzbin API throttle limit, starting downloads again")
		downloadNZB(nzb)
	except (urllib.ContentTooShortError, IOError), e:
		logger.log("Error downloading NZB: " + str(sys.exc_info()) + " - " + str(e), logger.ERROR)
		return False
开发者ID:basti1,项目名称:Sick-Beard,代码行数:18,代码来源:newzbin.py


示例17: test_encoding

    def test_encoding(self):
        rootDir = 'C:\\Temp\\TV'
        strings = [u'Les Enfants De La T\xe9l\xe9', u'RT� One']

        sickbeard.SYS_ENCODING = None

        try:
            locale.setlocale(locale.LC_ALL, "")
            sickbeard.SYS_ENCODING = locale.getpreferredencoding()
        except (locale.Error, IOError):
            pass

        # For OSes that are poorly configured I'll just randomly force UTF-8
        if not sickbeard.SYS_ENCODING or sickbeard.SYS_ENCODING in ('ANSI_X3.4-1968', 'US-ASCII', 'ASCII'):
            sickbeard.SYS_ENCODING = 'UTF-8'

        for s in strings:
            show_dir = ek(os.path.join, rootDir, sanitizeFileName(s))
            self.assertIsInstance(show_dir, unicode)
开发者ID:fabiankaeser,项目名称:SickRage,代码行数:19,代码来源:encoding_tests.py


示例18: addDefaultShow

    def addDefaultShow(self, tvdbid, name, status):
        """
        Adds a new show with the default settings
        """
        showObj = helpers.findCertainShow(sickbeard.showList, int(tvdbid))
        if showObj != None:
            return
        logger.log(u"Adding show " + tvdbid)
        root_dirs = sickbeard.ROOT_DIRS.split('|')
        location = root_dirs[int(root_dirs[0]) + 1]

        showPath = ek.ek(os.path.join, location, helpers.sanitizeFileName(name))
        dir_exists = helpers.makeDir(showPath)
        if not dir_exists:
            logger.log(u"Unable to create the folder " + showPath + ", can't add the show", logger.ERROR)
            return
        else:
            helpers.chmodAsParent(showPath)
        sickbeard.showQueueScheduler.action.addShow(int(tvdbid), showPath, status, int(sickbeard.QUALITY_DEFAULT), int(sickbeard.FLATTEN_FOLDERS_DEFAULT),"fr", int(sickbeard.SUBTITLES_DEFAULT), sickbeard.AUDIO_SHOW_DEFAULT)
开发者ID:Araldwenn,项目名称:Sick-Beard,代码行数:19,代码来源:traktWatchListChecker.py


示例19: downloadResult

    def downloadResult(self, result):
        """
        Save the result to disk.
        """
        
        #Hack for rtorrent user (it will not work for other torrent client)
        if sickbeard.TORRENT_METHOD == "blackhole" and result.url.startswith('magnet'): 
            magnetFileName = ek.ek(os.path.join, sickbeard.TORRENT_DIR, helpers.sanitizeFileName(result.name) + '.' + self.providerType)
            magnetFileContent = 'd10:magnet-uri' + `len(result.url)` + ':' + result.url + 'e'

            try:
                fileOut = open(magnetFileName, 'wb')
                fileOut.write(magnetFileContent)
                fileOut.close()
                helpers.chmodAsParent(magnetFileName)
            except IOError, e:
                logger.log("Unable to save the file: "+ex(e), logger.ERROR)
                return False
            logger.log(u"Saved magnet link to "+magnetFileName+" ", logger.MESSAGE)
            return True
开发者ID:kevmeon,项目名称:Sick-Beard,代码行数:20,代码来源:thepiratebay.py


示例20: downloadResult

 def downloadResult(self, result):
     """
     Overridden to handle magnet links (using multiple fallbacks)
     """
     logger.log(u"Downloading a result from " + self.name+" at " + result.url)
     
     if result.url and result.url.startswith('magnet:'):
         torrent_hash = self.getHashFromMagnet(result.url)
         if torrent_hash:
             urls = [url_fmt % torrent_hash for url_fmt in MAGNET_TO_TORRENT_URLS]
         else:
             logger.log(u"Failed to handle magnet url %s, skipping..." % torrent_hash, logger.DEBUG)
             return False
     else:
         urls = [result.url]
         
     # use the result name as the filename
     fileName = ek.ek(os.path.join, sickbeard.TORRENT_DIR, helpers.sanitizeFileName(result.name) + '.' + self.providerType)
         
     for url in urls:
         logger.log(u"Trying d/l url: " + url, logger.DEBUG)
         data = self.getURL(url)
         
         if data == None:
             logger.log(u"Got no data for " + url, logger.DEBUG)
             # fall through to next iteration
         else:
             try:
                 fileOut = open(fileName, 'wb')
                 fileOut.write(data)
                 fileOut.close()
                 helpers.chmodAsParent(fileName)
             except IOError, e:
                 logger.log("Unable to save the file: "+ex(e), logger.ERROR)
                 return False
             
             if self._verify_download(fileName):
                 logger.log(u"Success with url: " + url, logger.DEBUG)
                 return True
             else:
                 logger.log(u"d/l url %s failed" % (url), logger.MESSAGE)
开发者ID:Halopend,项目名称:Sick-Beard,代码行数:41,代码来源:generic.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python helpers.sanitizeSceneName函数代码示例发布时间:2022-05-27
下一篇:
Python helpers.replaceExtension函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap