markokr/rarfile

retrieve "volume number" from rar file other than first rar file?

sanderjo opened this issue · 1 comments

I want to retrieve the "volume number" from a random rar file (with an obfuscated name), so other than first rar file.

The rar binary shows it's possible:

$ rar l mytestpost-brackets.part486.rar | grep Details
Details: RAR 5, volume 486

and also works for a random filename:

$ cp mytestpost-brackets.part345.rar some-blabla-rar-file
$ rar l some-blabla-rar-file | grep Details
Details: RAR 5, volume 345

So I tried with the unrar module.

Try on first rar file ... works:

$ ~/rar_info_via_module_rarfile.py mytestpost-brackets.part001.rar
500MB.bin 524288000 volume: 0

But any other rar file does not work:

$ ~/rar_info_via_module_rarfile.py mytestpost-brackets.part486.rar
Traceback (most recent call last):
  File "/home/sander/rar_info_via_module_rarfile.py", line 8, in <module>
    rf = rarfile.RarFile(sys.argv[1])
  File "/usr/local/lib/python2.7/dist-packages/rarfile.py", line 666, in __init__
    self._parse()
  File "/usr/local/lib/python2.7/dist-packages/rarfile.py", line 858, in _parse
    self._file_parser.parse()
  File "/usr/local/lib/python2.7/dist-packages/rarfile.py", line 973, in parse
    self._parse_real()
  File "/usr/local/lib/python2.7/dist-packages/rarfile.py", line 1027, in _parse_real
    raise NeedFirstVolume("Need to start from first volume")
rarfile.NeedFirstVolume: Need to start from first volume

Hmmm Need to start from first volume is not what I wanted to hear.

Any way to solve this?

The micro program I use, based on the first code snippet on https://rarfile.readthedocs.io/en/latest/api.html

#!/usr/bin/env python

import rarfile, sys

rf = rarfile.RarFile(sys.argv[1])
for f in rf.infolist():
    print f.filename, f.file_size, "volume:", f.volume

It's a rar5 only feature. Perhaps this info can be put into error message, but that's it. Main reason rarfile needs volume info is that it can predict next filename. There is nothing intelligent rarfile can do with obfuscated volume names.