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

extraction failed: local variable 'archive' referenced before assignment #3041

Closed
rain0r opened this issue Sep 21, 2018 · 4 comments
Closed
Labels
bug bugs that are confirmed and actionable

Comments

@rain0r
Copy link
Contributor

rain0r commented Sep 21, 2018

Problem

When trying to import a mp3-file as a singleton, I get the following error:
extraction failed: local variable 'archive' referenced before assignment

The file is is a mp3-version of this song (youtube-dl -x ...).

After digging in the code, I found this line: importer.py

ipdb> handler_class(util.py3_path(self.toppath), mode='r')
*** OSError: [Errno 22] Invalid argument

If handler_class() throws an error, archive.close() is not assigned when called in the finally block.

By the way, why does beets try to extract a mp3-file?

Here's a link to the music files that trigger the bug (if relevant):

https://www.youtube.com/watch?v=JibljZBesgM

Setup

  • OS: Gentoo Linux
  • beets version 1.4.7
  • Python version 3.6.6
  • plugins: chroma, embedart, fetchart, info, lastgenre, mpdstats, play, replaygain
@sampsyo sampsyo added the bug bugs that are confirmed and actionable label Sep 21, 2018
@sampsyo
Copy link
Member

sampsyo commented Sep 21, 2018

Thanks!! I've fixed the immediate problem. Can you please give that a try?

As for why beets is trying to extract an ordinary MP3, I don't have an answer for you… maybe that deserves closer investigation?

@sampsyo
Copy link
Member

sampsyo commented Sep 21, 2018

Actually, now that I think of it:

for path_test, handler_class in self.handlers():
    if path_test(util.py3_path(self.toppath)):
        break

This stanza doesn't seem to bail out if there are no matching handlers. It seems to just continue on with the last handler, even if it didn't claim to be able to extract the file. I think we need to add:

else:
    return

to abort when there is no match. Would that make sense?

@rain0r
Copy link
Contributor Author

rain0r commented Sep 22, 2018

Getting this result now:

$ beet -vv import -s Ill_Breed_-_Act_Up-JibljZBesgM.mp3 
user configuration: /home/rain0r/.config/beets/config.yaml
data directory: /home/rain0r/.config/beets
plugin paths: 
Sending event: pluginload
artresizer: method is (2, (7, 0, 8))
library database: /home/rain0r/.local/share/beets/musiclibrary.blb
library directory: /mnt/archivefs/music
Sending event: library_opened
Sending event: import_begin
state file could not be read: 'ascii' codec can't decode byte 0xcc in position 75: ordinal not in range(128)
Extracting archive: /home/rain0r/to-tag/hiphop/Ill_Breed_-_Act_Up-JibljZBesgM.mp3
extraction failed: [Errno 22] Invalid argument
No files imported from /home/rain0r/to-tag/hiphop/Ill_Breed_-_Act_Up-JibljZBesgM.mp3
Sending event: import
Sending event: cli_exit
$ beet --version
beets version 1.4.8
Python version 3.6.6
plugins: chroma, embedart, fetchart, info, lastgenre, mpdstats, play, replaygain

@sampsyo
Copy link
Member

sampsyo commented Sep 22, 2018

Weird! For what it's wort, I'm able to reproduce this if I use the --audio-format mp3 flag to youtube-dl to create the MP3 file. In this case, Python's built-in zipfile module returns true for is_zipfile() on that file. The file command on my system, however, disagrees:

$ file Ill\ Breed\ -\ Act\ Up-JibljZBesgM.mp3
Ill Breed - Act Up-JibljZBesgM.mp3: Audio file with ID3 version 2.4.0, contains:MPEG ADTS, layer III, v1,  64 kbps, 48 kHz, Stereo

I'm not exactly sure what to suggest. We could whitelist filename extensions, for example, or fall back to an ordinary import procedure if extraction fails?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs that are confirmed and actionable
Projects
None yet
Development

No branches or pull requests

2 participants