Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importer: use tarfile.open to handle compressed archives #3607

Merged
merged 1 commit into from
Jun 1, 2020

Conversation

cota
Copy link
Contributor

@cota cota commented May 31, 2020

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.

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome; thanks for fixing this!! Do you think you could add a quick changelog entry describing the change in docs/changelog.rst?

beets/importer.py Outdated Show resolved Hide resolved
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 beetbox#3606.
@sampsyo
Copy link
Member

sampsyo commented Jun 1, 2020

Perfect; thanks!!

@sampsyo sampsyo merged commit 0af2504 into beetbox:master Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

import: support extraction of bzip2 and gzip tarballs
2 participants