leosongwei / mutagen

Automatically exported from code.google.com/p/mutagen
GNU General Public License v2.0
0 stars 0 forks source link

Fails to recognize MP3 files without tags and .mp3 extension #87

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
class MP3(ID3FileType):
    """An MPEG audio (usually MPEG-1 Layer 3) file."""

    _Info = MPEGInfo
    _mimes = ["audio/mp3", "audio/x-mp3", "audio/mpeg", "audio/mpg",
              "audio/x-mpeg"]

    def score(filename, fileobj, header):
        filename = filename.lower()
        return (header.startswith("ID3") * 2 + filename.endswith(".mp3") +
                filename.endswith(".mp2") + filename.endswith(".mpg") +
                filename.endswith(".mpeg"))
    score = staticmethod(score)

I have nearly pulled my hair out trying to figure out why 

mutagen.File(filename, easy=True)

was returning a NoneType.  I was running it on an MP3 file that had no ID3 tags 
yet and was not named with a ".mp3" extension.  I expected an exception to be 
raised, but instead I just got a NoneType, and my script failed on trying to 
add_tags(), save(), etc.

An easy way to fix this would be to use python-magic to identify files.  
libmagic and file do an excellent job.

Original issue reported on code.google.com by alphadel...@gmail.com on 8 Apr 2011 at 5:10

GoogleCodeExporter commented 9 years ago
I don't want Mutagen to depend on libmagic, and I also don't want the scoring 
algorithms to have different results depending on what third-party libraries 
are installed - that would be hell for application authors to debug user issues.

Original comment by joe.wreschnig@gmail.com on 8 Apr 2011 at 7:59

GoogleCodeExporter commented 9 years ago
I understand those issues--though libmagic is standard on Linux systems.  But 
is there some other way you could fix it?  Maybe you could check the first few 
bytes of the file to see if it's an MP3, even if it doesn't have ID3 tags.

At least, could there be a way to override the score and force mutagen.File() 
to open a file as an MP3 so tags can be added to the file?

Original comment by alphadel...@gmail.com on 11 Apr 2011 at 5:44

GoogleCodeExporter commented 9 years ago
libmagic is standard on Linux but python-magic is not; I don't even think it's 
installed by default on most distributions. Figuring out whether something is 
an MP3 file in the general case is surprisingly difficult.

If you just want to add tags, use mutagen.id3.ID3, which writes raw ID3 tags to 
a file. File is the auto-detecting variant; all constructors can still be used 
manually.

Original comment by joe.wreschnig@gmail.com on 11 Apr 2011 at 9:07

GoogleCodeExporter commented 9 years ago
Ok, thanks.

Original comment by alphadel...@gmail.com on 12 Apr 2011 at 12:37