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


Python rarfile.is_rarfile方法代码示例

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


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

示例1: download_archive

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def download_archive(self, archive):
        """Download an archive's :attr:`~LegendasTVArchive.content`.

        :param archive: the archive to download :attr:`~LegendasTVArchive.content` of.
        :type archive: :class:`LegendasTVArchive`

        """
        logger.info('Downloading archive %s', archive.id)
        r = self.session.get(self.server_url + 'downloadarquivo/{}'.format(archive.id))
        raise_for_status(r)

        # open the archive
        archive_stream = io.BytesIO(r.content)
        if is_rarfile(archive_stream):
            logger.debug('Identified rar archive')
            archive.content = RarFile(archive_stream)
        elif is_zipfile(archive_stream):
            logger.debug('Identified zip archive')
            archive.content = ZipFile(archive_stream)
        else:
            raise ValueError('Not a valid archive') 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:23,代码来源:legendastv.py

示例2: download_subtitle

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def download_subtitle(self, subtitle):
        if isinstance(subtitle, NekurSubtitle):
            # download the subtitle            
            r = self.session.get(subtitle.download_link, timeout=10)
            r.raise_for_status()

            # open the archive
            archive_stream = io.BytesIO(r.content)
            if is_rarfile(archive_stream):
                archive = RarFile(archive_stream)
            elif is_zipfile(archive_stream):
                archive = ZipFile(archive_stream)
            else:
                subtitle.content = r.content
                if subtitle.is_valid():
                    return
                subtitle.content = None

                raise ProviderError('Unidentified archive type')

            subtitle.content = self.get_subtitle_from_archive(subtitle, archive) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:23,代码来源:nekur.py

示例3: download_subtitle

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def download_subtitle(self, subtitle):
        r = self.session.get(subtitle.download_link, headers={'Referer': self.api_url}, timeout=10)
        r.raise_for_status()

        # open the archive
        archive_stream = io.BytesIO(r.content)
        if is_rarfile(archive_stream):
            logger.debug('[#### Provider: titrari.ro] Archive identified as rar')
            archive = RarFile(archive_stream)
        elif is_zipfile(archive_stream):
            logger.debug('[#### Provider: titrari.ro] Archive identified as zip')
            archive = ZipFile(archive_stream)
        else:
            subtitle.content = r.content
            if subtitle.is_valid():
                return
            subtitle.content = None

            raise ProviderError('[#### Provider: titrari.ro] Unidentified archive type')

        subtitle.content = self.get_subtitle_from_archive(subtitle, archive) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:23,代码来源:titrari.py

示例4: download_subtitle

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def download_subtitle(self, subtitle):
        r = self.session.get(subtitle.page_link, timeout=10)
        r.raise_for_status()

        # open the archive
        archive_stream = io.BytesIO(r.content)
        if is_rarfile(archive_stream):
            logger.debug('Archive identified as rar')
            archive = RarFile(archive_stream)
        elif is_zipfile(archive_stream):
            logger.debug('Archive identified as zip')
            archive = ZipFile(archive_stream)
        else:
            raise ProviderError('Unidentified archive type')

        subtitle.content = self.get_subtitle_from_archive(subtitle, archive) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:18,代码来源:hosszupuska.py

示例5: download_subtitle

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def download_subtitle(self, subtitle):
        if isinstance(subtitle, SubtitriIdSubtitle):
            # download the subtitle
            r = self.session.get(subtitle.download_link, timeout=10)
            r.raise_for_status()

            # open the archive
            archive_stream = io.BytesIO(r.content)
            if is_rarfile(archive_stream):
                archive = RarFile(archive_stream)
            elif is_zipfile(archive_stream):
                archive = ZipFile(archive_stream)
            else:
                subtitle.content = r.content
                if subtitle.is_valid():
                    return
                subtitle.content = None

                raise ProviderError('Unidentified archive type')

            subtitle.content = self.get_subtitle_from_archive(subtitle, archive) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:23,代码来源:subtitriid.py

示例6: match

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def match(cls, file_path, result=None):
        if rarfile.is_rarfile(file_path):
            return cls.SCORE
        return super(RARIngestor, cls).match(file_path, result=result) 
开发者ID:occrp-attic,项目名称:ingestors,代码行数:6,代码来源:rar.py

示例7: _get_archive

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def _get_archive(content):
    # open the archive
    archive_stream = io.BytesIO(content)
    archive = None
    if rarfile.is_rarfile(archive_stream):
        logger.debug('Identified rar archive')
        archive = rarfile.RarFile(archive_stream)
    elif zipfile.is_zipfile(archive_stream):
        logger.debug('Identified zip archive')
        archive = zipfile.ZipFile(archive_stream)

    return archive 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:14,代码来源:betaseries.py

示例8: download_archive_and_add_subtitle_files

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def download_archive_and_add_subtitle_files(self, link, language, video, fps, num_cds):
        logger.info('Downloading subtitle %r', link)
        request = self.session.get(link, headers={
            'Referer': 'http://subs.sab.bz/index.php?'
            })
        request.raise_for_status()

        archive_stream = io.BytesIO(request.content)
        if is_rarfile(archive_stream):
            return self.process_archive_subtitle_files(RarFile(archive_stream), language, video, link, fps, num_cds)
        elif is_zipfile(archive_stream):
            return self.process_archive_subtitle_files(ZipFile(archive_stream), language, video, link, fps, num_cds)
        else:
            logger.error('Ignore unsupported archive %r', request.headers)
            return [] 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:17,代码来源:subssabbz.py

示例9: download_archive_and_add_subtitle_files

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def download_archive_and_add_subtitle_files(self, link, language, video, fps):
        logger.info('Downloading subtitle %r', link)
        request = self.session.get(link, headers={
            'Referer': 'http://yavka.net/subtitles.php'
            })
        request.raise_for_status()

        archive_stream = io.BytesIO(request.content)
        if is_rarfile(archive_stream):
            return self.process_archive_subtitle_files(RarFile(archive_stream), language, video, link, fps)
        elif is_zipfile(archive_stream):
            return self.process_archive_subtitle_files(ZipFile(archive_stream), language, video, link, fps)
        else:
            logger.error('Ignore unsupported archive %r', request.headers)
            return [] 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:17,代码来源:yavkanet.py

示例10: _get_archive

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def _get_archive(self, content):
        # open the archive
        archive_stream = io.BytesIO(content)
        if rarfile.is_rarfile(archive_stream):
            logger.debug('Identified rar archive')
            archive = rarfile.RarFile(archive_stream)
        elif zipfile.is_zipfile(archive_stream):
            logger.debug('Identified zip archive')
            archive = zipfile.ZipFile(archive_stream)
        else:
            raise APIThrottled('Unsupported compressed format')

        return archive 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:15,代码来源:subdivx.py

示例11: download_archive_and_add_subtitle_files

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def download_archive_and_add_subtitle_files(self, link, language, video, fps, num_cds):
        logger.info('Downloading subtitle %r', link)
        request = self.session.get(link, headers={
            'Referer': 'https://subsunacs.net/search.php'
            })
        request.raise_for_status()

        archive_stream = io.BytesIO(request.content)
        if is_rarfile(archive_stream):
            return self.process_archive_subtitle_files(RarFile(archive_stream), language, video, link, fps, num_cds)
        elif is_zipfile(archive_stream):
            return self.process_archive_subtitle_files(ZipFile(archive_stream), language, video, link, fps, num_cds)
        else:
            logger.error('Ignore unsupported archive %r', request.headers)
            return [] 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:17,代码来源:subsunacs.py

示例12: _get_archive

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def _get_archive(self, content):
        # open the archive
        archive_stream = io.BytesIO(content)
        if rarfile.is_rarfile(archive_stream):
            logger.debug('Legendasdivx.pt :: Identified rar archive')
            archive = rarfile.RarFile(archive_stream)
        elif zipfile.is_zipfile(archive_stream):
            logger.debug('Legendasdivx.pt :: Identified zip archive')
            archive = zipfile.ZipFile(archive_stream)
        else:
            logger.error('Legendasdivx.pt :: Unsupported compressed format')
            return None
        return archive 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:15,代码来源:legendasdivx.py

示例13: test_real

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def test_real(fn, psw):
    """Actual archive processing.
    """
    xprint("Archive: %s", fn)

    cb = None
    if cf_verbose > 1:
        cb = show_item

    rfarg = fn
    if cf_test_memory:
        rfarg = io.BytesIO(open(fn, 'rb').read())

    # check if rar
    if not rf.is_rarfile(rfarg):
        xprint(" --- %s is not a RAR file ---", fn)
        return

    # open
    r = rf.RarFile(rfarg, charset=cf_charset, info_callback=cb)
    # set password
    if r.needs_password():
        if psw:
            r.setpassword(psw)
        else:
            xprint(" --- %s requires password ---", fn)
            return

    # show comment
    if cf_show_comment and r.comment:
        for ln in r.comment.split('\n'):
            xprint("    %s", ln)
    elif cf_verbose > 0 and r.comment:
        cm = repr(r.comment)
        if cm[0] == 'u':
            cm = cm[1:]
        xprint("  comment=%s", cm)

    # process
    for n in r.namelist():
        inf = r.getinfo(n)
        if inf.isdir():
            continue
        if cf_verbose == 1:
            show_item(inf)
        if cf_test_read:
            test_read(r, inf)

    if cf_extract:
        r.extractall()
        for inf in r.infolist():
            r.extract(inf)

    if cf_test_unrar:
        r.testrar() 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:57,代码来源:dumprar.py

示例14: extract

# 需要导入模块: import rarfile [as 别名]
# 或者: from rarfile import is_rarfile [as 别名]
def extract(archive_file, path=".", delete_on_success=False,
            enable_rar=False):
    """
    Automatically detect archive type and extract all files to specified path.

    .. code:: python

        import os

        os.listdir(".")
        # ['test_structure.zip']

        reusables.extract("test_structure.zip")

        os.listdir(".")
        # [ 'test_structure', 'test_structure.zip']


    :param archive_file: path to file to extract
    :param path: location to extract to
    :param delete_on_success: Will delete the original archive if set to True
    :param enable_rar: include the rarfile import and extract
    :return: path to extracted files
    """

    if not os.path.exists(archive_file) or not os.path.getsize(archive_file):
        logger.error("File {0} unextractable".format(archive_file))
        raise OSError("File does not exist or has zero size")

    arch = None
    if zipfile.is_zipfile(archive_file):
        logger.debug("File {0} detected as a zip file".format(archive_file))
        arch = zipfile.ZipFile(archive_file)
    elif tarfile.is_tarfile(archive_file):
        logger.debug("File {0} detected as a tar file".format(archive_file))
        arch = tarfile.open(archive_file)
    elif enable_rar:
        import rarfile
        if rarfile.is_rarfile(archive_file):
            logger.debug("File {0} detected as "
                         "a rar file".format(archive_file))
            arch = rarfile.RarFile(archive_file)

    if not arch:
        raise TypeError("File is not a known archive")

    logger.debug("Extracting files to {0}".format(path))

    try:
        arch.extractall(path=path)
    finally:
        arch.close()

    if delete_on_success:
        logger.debug("Archive {0} will now be deleted".format(archive_file))
        os.unlink(archive_file)

    return os.path.abspath(path) 
开发者ID:cdgriffith,项目名称:Reusables,代码行数:60,代码来源:file_operations.py


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