-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
import: support extraction of bzip2 and gzip tarballs #3606
Comments
Have you tried importing a Lines 1037 to 1038 in 19ab28e
|
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.
Note that
The method that we want is
I'll send a patch. Please double check the tests, this is the first time I write anything in Python and I've given up trying to get the necessary packages :( |
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.
Use case
I'm trying to use beets to import albums from a set of bzip2/gzip tarballs, i.e. .tar.bz2 and .tar.gz files. Would be nice if we could just import them instead of having to extract them first.
Solution
I see that the
tarfile
module can process tar archives with gzip or bzip2 compression, so hopefully this is not too hard to do. Unfortunately I don't know Python so I cannot provide a patch.Alternatives
As a workaround I am extracting the tarballs first. Not the end of the world but it would be nice to be able to just point beets to the files, just like we do with rar and zip files.
Thanks for maintaining this great piece of software!
The text was updated successfully, but these errors were encountered: