-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
how to find file info in not-first rar file? #56
Comments
If you open first rar with RarFile, you get all files from all volumes. |
Thanks for replying. I think that is only true if all rar files are nicely and correctly named
I wrote a unrar / bash script to find the contents:
So:
So only the contents of the first rar file ... :-( If not possible with rarfile module, I'll use For reference: myrarstuff.py
inspect-all-files.sh
|
Heh, this is definitely not a common usecase... I think you simply need to comment out those errors in RarFile, so they don't get thrown. Secondly, you need to install info_callback so you can see all headers that pass by. If you collect headers of all partial files from the start and end of archives, you can then try to match them and put volumes into sequence. |
OK, like Lines 195 to 205 in cf92552
Thank you for you help! |
Indeed I modified the RarFile we use in our application to have an extra parameter to ignore first-volume errors and be more robust against mid-volume file-listings: |
Nice, that works: sabnzbd/sabnzbd#1331 (comment) |
@markokr I tried to apply a similar patch to the new RarFile but it's been quite hard. We use RarFile a lot in our application SABnzbd and I would really like to include the original version, instead of the old modified RarFile version we still use now :) |
Sounds reasonable request, I'll look into it. |
Please test with 'master', add part_only=True flag to RarFile |
Thanks for looking into this! But doesn't seem to work: >>> import rarfile
>>> rarfile.__version__
'4.1a1'
>>> aa=rarfile.RarFile(r"C:\Users\saf\Downloads\84868a4ced3d9ff30597d5b54d066a53.part11.rar",part_only=True)
>>> aa.infolist()
[]
>>> aa.namelist()
[] Our own modified old RarFile: >>> import sabnzbd.utils.rarfile as rf_sab
>>> bb=rf_sab.RarFile(r"C:\Users\saf\Downloads\84868a4ced3d9ff30597d5b54d066a53.part11.rar",single_file_check=True)
>>> bb.namelist()
['84868a4ced3d9ff30597d5b54d066a53.mkv']
>>> bb.infolist()
[<sabnzbd.utils.rarfile.Rar5FileInfo object at 0x0000027B1ABFC040>] |
Please use info_callback to collect archive records. .namelist()/.infolist() operate on sanitized file list, eg. no versioned files, it will not be robust for volume mapping. |
Thank you for the import rarfile as rf
class SabRarFile(rf.RarFile):
def __init__(self, *args, **kwargs):
"""Patch RarFile-call when using `part_only`
to store filenames inside the RAR-files"""
if kwargs.get("part_only"):
kwargs["info_callback"] = self.info_callback
# Let RarFile handle the rest!
super().__init__(*args, **kwargs)
def info_callback(self, rar_obj: rf.RarInfo):
"""Called for every RarInfo-object found"""
# We only care about files inside the Rar
# For Rar5 there is a separate object, for Rar3 we need to check if a filename was parsed
if isinstance(rar_obj, (rf.Rar5FileInfo, rf.Rar3Info)) and rar_obj.filename:
# Avoid duplicates
if rar_obj not in self._file_parser._info_list:
self._file_parser._info_list.append(rar_obj)
self._file_parser._info_map[rar_obj.filename.rstrip("/")] = rar_obj Which works as we need it: # Rar3
bb = SabRarFile(r"C:\Users\saf\Downloads\SkypeMeetingsApp.part2.rar", part_only=True)
print(bb.namelist())
print(bb.infolist())
['SkypeMeetingsApp.msi']
[<rarfile.Rar3Info object at 0x00000276877D3BB0>]
# Rar5
bb=SabRarFile(r"C:\Users\saf\Downloads\84868a4ced3d9ff30597d5b54d066a53.part11.rar", part_only=True)
print(bb.namelist())
print(bb.infolist())
['84868a4ced3d9ff30597d5b54d066a53.mkv']
[<rarfile.Rar5FileInfo object at 0x0000021C25C387C0>] |
When you create a new |
With rarfile, how can I find the files in a rar file other than the first?
With the
unrar
tool it's easy:But with rarfile I get an error:
FWIW: the filenames are in plaintext in the part5.rar file:
and
The text was updated successfully, but these errors were encountered: