I am attempting to edit certain MP3 files ID3 tags through Python. I have done some research, and found the mutagen, and eyeD3 libraries. However, I have run into similar issues with both of these libraries. Both implementations complain that the file I’m providing either does not exist, or is not an .mp3 file.
I have downloaded Mp3tag (http://www.mp3tag.de/en/download.html) and confirmed that the file I am providing is Tagged as ID3v2.3(ID3v1 ID3v2.3) and that is an .mp3 file.
Below is the mutagen code, followed by the error I receive:
from mutagen.mp3 import MP3
audio = MP3("C:\Users\557319\Music\Trance\Paul van Dyk - We Come Together (Arty Remix)")
print audio.info.length, audio.info.bitrate
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
audio = MP3("C:\Users\557319\Music\Trance\Paul van Dyk - We Come Together (Arty Remix) www.freshnewtracks.com.mp3")
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 75, in __init__
self.load(filename, *args, **kwargs)
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 1995, in load
try: self.tags = ID3(filename, **kwargs)
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 74, in __init__
super(ID3, self).__init__(*args, **kwargs)
File "C:\Python27\lib\site-packages\mutagen\_util.py", line 105, in __init__
super(DictProxy, self).__init__(*args, **kwargs)
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 39, in __init__
self.load(*args, **kwargs)
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 109, in load
self.__fileobj = file(filename, 'rb')
IOError: [Errno 2] No such file or directory: 'C:\\Userso319\\Music\\Trance\\Paul van Dyk - We Come Together (Arty Remix) www.freshnewtracks.com.mp3'
Now when I try to view the ID3 data using eyeD3, I experience the following:
import eyeD3
trackInfo = eyeD3.Mp3AudioFile("C:\Users\557319\Music\Trance\Paul van Dyk - We Come Together (Arty Remix) www.freshnewtracks.com")
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
trackInfo = eyeD3.Mp3AudioFile("C:\Users\557319\Music\Trance\Paul van Dyk - We Come Together (Arty Remix) www.freshnewtracks.com")
File "C:\Python27\lib\site-packages\eyeD3\tag.py", line 1618, in __init__
raise InvalidAudioFormatException("File is not mp3");
InvalidAudioFormatException: File is not mp3
My guess is that I am not viewing the file properly? Do I need to use some type of os library to properly view these files ID3 data for Windows 7? Any help is greatly appreciated.
Thanks.
When you deal with Windows paths in Python, you have three options:
"C:\\mydir\\myfile.mp3")r'C:\mydir\myfile.mp3'— note the initial “r”)Whenever you manipulate paths, you should always use the functions in the
os.pathmodule, e.g.os.path.join(r'C:\mydir','myfile.mp3')(as an aside, note that ID3 libs like mutagen are known for being buggy and temperamental, so expect breakages or weird behaviour; this is unfortunately due to ID3 being a poorly-specified non-standard full of corner cases and strange implementations.)