Python rarfile.is_rarfile() Examples
The following are 19
code examples of rarfile.is_rarfile().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rarfile
, or try the search function
.
Example #1
Source File: legendastv.py From bazarr with GNU General Public License v3.0 | 6 votes |
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')
Example #2
Source File: subtitriid.py From bazarr with GNU General Public License v3.0 | 6 votes |
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)
Example #3
Source File: nekur.py From bazarr with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: hosszupuska.py From bazarr with GNU General Public License v3.0 | 6 votes |
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)
Example #5
Source File: titrari.py From bazarr with GNU General Public License v3.0 | 6 votes |
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)
Example #6
Source File: legendasdivx.py From bazarr with GNU General Public License v3.0 | 5 votes |
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
Example #7
Source File: subsunacs.py From bazarr with GNU General Public License v3.0 | 5 votes |
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 []
Example #8
Source File: subdivx.py From bazarr with GNU General Public License v3.0 | 5 votes |
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
Example #9
Source File: subs4free.py From bazarr with GNU General Public License v3.0 | 5 votes |
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
Example #10
Source File: greeksubtitles.py From bazarr with GNU General Public License v3.0 | 5 votes |
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
Example #11
Source File: subs4series.py From bazarr with GNU General Public License v3.0 | 5 votes |
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
Example #12
Source File: yavkanet.py From bazarr with GNU General Public License v3.0 | 5 votes |
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 []
Example #13
Source File: subssabbz.py From bazarr with GNU General Public License v3.0 | 5 votes |
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 []
Example #14
Source File: betaseries.py From bazarr with GNU General Public License v3.0 | 5 votes |
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
Example #15
Source File: rar.py From ingestors with MIT License | 5 votes |
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)
Example #16
Source File: dumprar.py From Lector with GNU General Public License v3.0 | 4 votes |
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()
Example #17
Source File: file_operations.py From Reusables with MIT License | 4 votes |
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)
Example #18
Source File: dumprar.py From bazarr with GNU General Public License v3.0 | 4 votes |
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()
Example #19
Source File: dumprar.py From addon with GNU General Public License v3.0 | 4 votes |
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()