python类makeLegalFilename()的实例源码

libtools.py 文件源码 项目:plugin.video.exodus 作者: lastship 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def create_folder(folder):
        try:
            folder = xbmc.makeLegalFilename(folder)
            control.makeFile(folder)

            try:
                if not 'ftp://' in folder: raise Exception()
                from ftplib import FTP
                ftparg = re.compile('ftp://(.+?):(.+?)@(.+?):?(\d+)?/(.+/?)').findall(folder)
                ftp = FTP(ftparg[0][2], ftparg[0][0], ftparg[0][1])
                try:
                    ftp.cwd(ftparg[0][4])
                except:
                    ftp.mkd(ftparg[0][4])
                ftp.quit()
            except:
                pass
        except:
            pass
libtools.py 文件源码 项目:plugin.video.lastship 作者: lastship 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def create_folder(folder):
        try:
            folder = xbmc.makeLegalFilename(folder)
            control.makeFile(folder)

            try:
                if not 'ftp://' in folder: raise Exception()
                from ftplib import FTP
                ftparg = re.compile('ftp://(.+?):(.+?)@(.+?):?(\d+)?/(.+/?)').findall(folder)
                ftp = FTP(ftparg[0][2], ftparg[0][0], ftparg[0][1])
                try:
                    ftp.cwd(ftparg[0][4])
                except:
                    ftp.mkd(ftparg[0][4])
                ftp.quit()
            except:
                pass
        except:
            pass
libtools.py 文件源码 项目:plugin.video.exodus 作者: huberyhe 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def create_folder(folder):
        try:
            folder = xbmc.makeLegalFilename(folder)
            control.makeFile(folder)

            try:
                if not 'ftp://' in folder: raise Exception()
                from ftplib import FTP
                ftparg = re.compile('ftp://(.+?):(.+?)@(.+?):?(\d+)?/(.+/?)').findall(folder)
                ftp = FTP(ftparg[0][2], ftparg[0][0], ftparg[0][1])
                try:
                    ftp.cwd(ftparg[0][4])
                except:
                    ftp.mkd(ftparg[0][4])
                ftp.quit()
            except:
                pass
        except:
            pass
libtools.py 文件源码 项目:plugin.video.exodus 作者: lastship 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def write_file(path, content):
        try:
            path = xbmc.makeLegalFilename(path)
            if not isinstance(content, basestring):
                content = str(content)

            file = control.openFile(path, 'w')
            file.write(str(content))
            file.close()
        except Exception as e:
            pass
libtools.py 文件源码 项目:plugin.video.exodus 作者: lastship 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def legal_filename(filename):
        try:
            filename = filename.strip()
            filename = re.sub(r'(?!%s)[^\w\-_\.]', '.', filename)
            filename = re.sub('\.+', '.', filename)
            filename = re.sub(re.compile('(CON|PRN|AUX|NUL|COM\d|LPT\d)\.', re.I), '\\1_', filename)
            xbmc.makeLegalFilename(filename)
            return filename
        except:
            return filename
libtools.py 文件源码 项目:plugin.video.lastship 作者: lastship 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def write_file(path, content):
        try:
            path = xbmc.makeLegalFilename(path)
            if not isinstance(content, basestring):
                content = str(content)

            file = control.openFile(path, 'w')
            file.write(str(content))
            file.close()
        except Exception as e:
            pass
libtools.py 文件源码 项目:plugin.video.lastship 作者: lastship 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def legal_filename(filename):
        try:
            filename = filename.strip()
            filename = re.sub(r'(?!%s)[^\w\-_\.]', '.', filename)
            filename = re.sub('\.+', '.', filename)
            filename = re.sub(re.compile('(CON|PRN|AUX|NUL|COM\d|LPT\d)\.', re.I), '\\1_', filename)
            xbmc.makeLegalFilename(filename)
            return filename
        except:
            return filename
downloadtools.py 文件源码 项目:tvalacarta 作者: tvalacarta 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def GetTitleFromFile(title):
    # Imprime en el log lo que va a descartar
    logger.info("tvalacarta.core.downloadtools GetTitleFromFile: titulo="+title )
    #logger.info("tvalacarta.core.downloadtools downloadtitle: title="+urllib.quote_plus( title ))
    plataforma = config.get_system_platform();
    logger.info("tvalacarta.core.downloadtools GetTitleFromFile: plataforma="+plataforma)

    #nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    if plataforma=="xbox":
        nombrefichero = title[:38] + title[-4:]
        nombrefichero = limpia_nombre_excepto_1(nombrefichero)
    else:
        nombrefichero = title
    return nombrefichero
libtools.py 文件源码 项目:plugin.video.exodus 作者: huberyhe 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def write_file(path, content):
        try:
            path = xbmc.makeLegalFilename(path)
            if not isinstance(content, basestring):
                content = str(content)

            file = control.openFile(path, 'w')
            file.write(str(content))
            file.close()
        except Exception as e:
            pass
libtools.py 文件源码 项目:plugin.video.exodus 作者: huberyhe 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def legal_filename(filename):
        try:
            filename = filename.strip()
            filename = re.sub(r'(?!%s)[^\w\-_\.]', '.', filename)
            filename = re.sub('\.+', '.', filename)
            filename = re.sub(re.compile('(CON|PRN|AUX|NUL|COM\d|LPT\d)\.', re.I), '\\1_', filename)
            xbmc.makeLegalFilename(filename)
            return filename
        except:
            return filename
downloadtools.py 文件源码 项目:pelisalacarta-ce 作者: pelisalacarta-ce 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def getfilefromtitle(url, title):
    # Imprime en el log lo que va a descartar
    logger.info("title=" + title)
    logger.info("url=" + url)
    # logger.info("pelisalacarta.core.downloadtools downloadtitle: title="+urllib.quote_plus( title ))
    plataforma = config.get_system_platform()
    logger.info("plataforma=" + plataforma)

    # nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    import scrapertools
    if plataforma == "xbox":
        nombrefichero = title[:38] + scrapertools.get_filename_from_url(url)[-4:]
        nombrefichero = limpia_nombre_excepto_1(nombrefichero)
    else:
        nombrefichero = title + scrapertools.get_filename_from_url(url)[-4:]
        logger.info("nombrefichero=%s" % nombrefichero)
        if "videobb" in url or "videozer" in url or "putlocker" in url:
            nombrefichero = title + ".flv"
        if "videobam" in url:
            nombrefichero = title + "." + url.rsplit(".", 1)[1][0:3]

        logger.info("nombrefichero=%s" % nombrefichero)

        nombrefichero = limpia_nombre_caracteres_especiales(nombrefichero)

    logger.info("nombrefichero=%s" % nombrefichero)

    fullpath = os.path.join(config.get_setting("downloadpath"), nombrefichero)
    logger.info("fullpath=%s" % fullpath)

    if config.is_xbmc() and fullpath.startswith("special://"):
        import xbmc
        fullpath = xbmc.translatePath(fullpath)

    return fullpath
downloadtools.py 文件源码 项目:pelisalacarta-ce 作者: pelisalacarta-ce 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def GetTitleFromFile(title):
    # Imprime en el log lo que va a descartar
    logger.info("titulo=" + title)
    # logger.info("pelisalacarta.core.downloadtools downloadtitle: title="+urllib.quote_plus( title ))
    plataforma = config.get_system_platform()
    logger.info("plataforma=" + plataforma)

    # nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    if plataforma == "xbox":
        nombrefichero = title[:38] + title[-4:]
        nombrefichero = limpia_nombre_excepto_1(nombrefichero)
    else:
        nombrefichero = title
    return nombrefichero
downloadtools.py 文件源码 项目:plugin.video.streamondemand-pureita 作者: orione7 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def getfilefromtitle(url,title):
    # Imprime en el log lo que va a descartar
    logger.info("streamondemand-pureita.core.downloadtools getfilefromtitle: title="+title )
    logger.info("streamondemand-pureita.core.downloadtools getfilefromtitle: url="+url )
    #logger.info("streamondemand-pureita.core.downloadtools downloadtitle: title="+urllib.quote_plus( title ))
    plataforma = config.get_system_platform();
    logger.info("streamondemand-pureita.core.downloadtools getfilefromtitle: plataforma="+plataforma)

    #nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    import scrapertools
    if plataforma=="xbox":
        nombrefichero = title[:38] + scrapertools.get_filename_from_url(url)[-4:]
        nombrefichero = limpia_nombre_excepto_1(nombrefichero)
    else:
        nombrefichero = title + scrapertools.get_filename_from_url(url)[-4:]
        logger.info("streamondemand-pureita.core.downloadtools getfilefromtitle: nombrefichero=%s" % nombrefichero)
        if "videobb" in url or "videozer" in url or "putlocker" in url:
            nombrefichero = title + ".flv"
        if "videobam" in url:
            nombrefichero = title+"."+url.rsplit(".",1)[1][0:3]
        if "filenium" in url:
            # Content-Disposition   filename="filenium_El.Gato.con.Botas.TSScreener.Latino.avi"
            import scrapertools
            content_disposition_header = scrapertools.get_header_from_response(url,header_to_get="Content-Disposition")
            logger.info("content_disposition="+content_disposition_header)
            partes=content_disposition_header.split("=")
            if len(partes)<=1:
                raise Exception('filenium', 'no existe')

            extension = partes[1][-5:-1]
            nombrefichero = title + extension
        logger.info("streamondemand-pureita.core.downloadtools getfilefromtitle: nombrefichero=%s" % nombrefichero)

        nombrefichero = limpia_nombre_caracteres_especiales(nombrefichero)

    logger.info("streamondemand-pureita.core.downloadtools getfilefromtitle: nombrefichero=%s" % nombrefichero)

    fullpath = os.path.join( config.get_setting("downloadpath") , nombrefichero )
    logger.info("streamondemand-pureita.core.downloadtools getfilefromtitle: fullpath=%s" % fullpath)

    return fullpath
downloadtools.py 文件源码 项目:plugin.video.streamondemand-pureita 作者: orione7 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def GetTitleFromFile(title):
    # Imprime en el log lo que va a descartar
    logger.info("streamondemand-pureita.core.downloadtools GetTitleFromFile: titulo="+title )
    #logger.info("streamondemand-pureita.core.downloadtools downloadtitle: title="+urllib.quote_plus( title ))
    plataforma = config.get_system_platform();
    logger.info("streamondemand-pureita.core.downloadtools GetTitleFromFile: plataforma="+plataforma)

    #nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    if plataforma=="xbox":
        nombrefichero = title[:38] + title[-4:]
        nombrefichero = limpia_nombre_excepto_1(nombrefichero)
    else:
        nombrefichero = title
    return nombrefichero
url.py 文件源码 项目:plugin.video.jen 作者: midraal 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __replace_gif(url):
    """ put gifs in local cache
    try to put gif in cache to enable motion
    Keyword Arguments:
    url -- url pointing to gif
    """
    if not url.endswith(".gif"):
        return url
    else:
        base_folder = xbmcaddon.Addon().getSetting("cache_folder")
        dest_folder = os.path.join(xbmc.translatePath(base_folder), "artcache")
        xbmcvfs.mkdirs(dest_folder)
        parts = url.split("/")
        dest = xbmc.makeLegalFilename(
            # TODO make sure this is unique
            os.path.join(dest_folder, parts[-2] + parts[-1]))
        if not xbmcvfs.exists(dest):
            try:
                response = requests.get(url, timeout=10, verify=False)
            except:
                return None
            if response.status_code == 200:
                with open(dest, 'wb') as out_file:
                    data = response.content
                    response.close()
                    out_file.write(data)
                    # shutil.copyfileobj(response.raw, out_file)
                    del data
                    del response
                if os.path.getsize(dest) == 0:
                    koding.dolog("0 size gif: " + repr(dest))
                    os.remove(dest)
                    return None
                else:
                    koding.dolog("size: " + repr(os.path.getsize(dest)))
            else:
                koding.Text_Box(xbmcaddon.Addon().getAddonInfo('name'),
                                _("gif not found: ") + url)
                return None
        xbmc.log("gif done: " + repr(dest))
        return dest
downloadtools.py 文件源码 项目:addon 作者: alfa-addon 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def getfilefromtitle(url, title):
    # Imprime en el log lo que va a descartar
    logger.info("title=" + title)
    logger.info("url=" + url)
    plataforma = config.get_system_platform()
    logger.info("plataforma=" + plataforma)

    # nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    import scrapertools

    nombrefichero = title + scrapertools.get_filename_from_url(url)[-4:]
    logger.info("nombrefichero=%s" % nombrefichero)
    if "videobb" in url or "videozer" in url or "putlocker" in url:
        nombrefichero = title + ".flv"
    if "videobam" in url:
        nombrefichero = title + "." + url.rsplit(".", 1)[1][0:3]

    logger.info("nombrefichero=%s" % nombrefichero)

    nombrefichero = limpia_nombre_caracteres_especiales(nombrefichero)

    logger.info("nombrefichero=%s" % nombrefichero)

    fullpath = os.path.join(config.get_setting("downloadpath"), nombrefichero)
    logger.info("fullpath=%s" % fullpath)

    if config.is_xbmc() and fullpath.startswith("special://"):
        import xbmc
        fullpath = xbmc.translatePath(fullpath)

    return fullpath
downloadtools.py 文件源码 项目:addon 作者: alfa-addon 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def GetTitleFromFile(title):
    # Imprime en el log lo que va a descartar
    logger.info("titulo=" + title)
    plataforma = config.get_system_platform()
    logger.info("plataforma=" + plataforma)

    # nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    nombrefichero = title
    return nombrefichero
url.py 文件源码 项目:repository.midraal 作者: midraal 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __replace_gif(url):
    """ put gifs in local cache
    try to put gif in cache to enable motion
    Keyword Arguments:
    url -- url pointing to gif
    """
    if not url.endswith(".gif"):
        return url
    else:
        base_folder = xbmcaddon.Addon().getSetting("cache_folder")
        dest_folder = os.path.join(xbmc.translatePath(base_folder), "artcache")
        xbmcvfs.mkdirs(dest_folder)
        parts = url.split("/")
        dest = xbmc.makeLegalFilename(
            # TODO make sure this is unique
            os.path.join(dest_folder, parts[-2] + parts[-1]))
        if not xbmcvfs.exists(dest):
            try:
                response = requests.get(url, timeout=10, verify=False)
            except:
                return None
            if response.status_code == 200:
                with open(dest, 'wb') as out_file:
                    data = response.content
                    response.close()
                    out_file.write(data)
                    # shutil.copyfileobj(response.raw, out_file)
                    del data
                    del response
                if os.path.getsize(dest) == 0:
                    koding.dolog("0 size gif: " + repr(dest))
                    os.remove(dest)
                    return None
                else:
                    koding.dolog("size: " + repr(os.path.getsize(dest)))
            else:
                koding.Text_Box(xbmcaddon.Addon().getAddonInfo('name'),
                                _("gif not found: ") + url)
                return None
        xbmc.log("gif done: " + repr(dest))
        return dest
downloadtools.py 文件源码 项目:tvalacarta 作者: tvalacarta 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def getfilefromtitle(url,title,folder=""):
    logger.info("tvalacarta.core.downloadtools getfilefromtitle: title="+title+" url="+url+" folder="+folder )

    #logger.info("tvalacarta.core.downloadtools downloadtitle: title="+urllib.quote_plus( title ))
    plataforma = config.get_system_platform();
    logger.info("tvalacarta.core.downloadtools getfilefromtitle: plataforma="+plataforma)

    #nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    import scrapertools
    if plataforma=="xbox":
        nombrefichero = title[:38] + scrapertools.get_filename_from_url(url)[-4:]
        nombrefichero = limpia_nombre_excepto_1(nombrefichero)
    else:
        nombrefichero = title + scrapertools.get_filename_from_url(url)[-4:]
        logger.info("tvalacarta.core.downloadtools getfilefromtitle: nombrefichero=%s" % nombrefichero)
        if "videobb" in url or "videozer" in url or "putlocker" in url:
            nombrefichero = title + ".flv"
        if "videobam" in url:
            nombrefichero = title+"."+url.rsplit(".",1)[1][0:3]
        if "dibujos.tv" in url:
            nombrefichero = title + ".mp4"
        if "filenium" in url:
            # Content-Disposition   filename="filenium_El.Gato.con.Botas.TSScreener.Latino.avi"
            import scrapertools
            content_disposition_header = scrapertools.get_header_from_response(url,header_to_get="Content-Disposition")
            logger.info("content_disposition="+content_disposition_header)
            partes=content_disposition_header.split("=")
            if len(partes)<=1:
                raise Exception('filenium', 'no existe')

            extension = partes[1][-5:-1]
            nombrefichero = title + extension
        logger.info("tvalacarta.core.downloadtools getfilefromtitle: nombrefichero=%s" % nombrefichero)

        nombrefichero = limpia_nombre_caracteres_especiales(nombrefichero)

    logger.info("tvalacarta.core.downloadtools getfilefromtitle: nombrefichero=%s" % nombrefichero)

    if folder=="":
        fullpath = os.path.join( config.get_setting("downloadpath") , nombrefichero )
    else:
        fullpath = os.path.join( config.get_setting("downloadpath") , folder , nombrefichero )

    logger.info("tvalacarta.core.downloadtools getfilefromtitle: fullpath=%s" % fullpath)

    return fullpath


问题


面经


文章

微信
公众号

扫码关注公众号