Skip to content

Commit

Permalink
importer: use tarfile.open to handle compressed archives
Browse files Browse the repository at this point in the history
Call tarfile.open instead of tarfile.TarFile from the importer so that
we can import compressed tar archives.

Note that tarfile.TarFile does not handle compressed archives:
$ python3
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tarfile
>>> tf = tarfile.TarFile("Lagrimas.tar.bz2")
Traceback (most recent call last):
[...]
tarfile.ReadError: invalid header
>>>

But tarfile.open does deal with them:
$ python3
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tarfile
>>> tf = tarfile.open("Lagrimas.tar.bz2")
>>>

Tested:
$ ls Lagrimas/*.mp3 | wc -l
11
$ tar cjf Lagrimas.tar.bz2 Lagrimas/

- Before:
$ beet import Lagrimas.tar.bz2
extraction failed: invalid header
No files imported from /tmp/Lagrimas.tar.bz2

- After:
$ beet import Lagrimas.tar.bz2
[works]

Fixes #3606.
  • Loading branch information
cota committed May 31, 2020
1 parent 19ab28e commit dfc1380
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions beets/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,8 +1034,8 @@ def handlers(cls):
cls._handlers = []
from zipfile import is_zipfile, ZipFile
cls._handlers.append((is_zipfile, ZipFile))
from tarfile import is_tarfile, TarFile
cls._handlers.append((is_tarfile, TarFile))
from tarfile import is_tarfile, open
cls._handlers.append((is_tarfile, open))
try:
from rarfile import is_rarfile, RarFile
except ImportError:
Expand Down

0 comments on commit dfc1380

Please sign in to comment.