Python: How can I access an mp3 file's metadata using Python?
There's a module called Python-ID3 that does exactly this. If you're on a Debian/Ubuntu box, its package name is python-id3
and there is example code on its website:
from ID3 import *
try:
id3info = ID3('/some/file/moxy.mp3')
print id3info
id3info['TITLE'] = "Green Eggs and Ham"
id3info['ARTIST'] = "Moxy Früvous"
for k, v in id3info.items():
print k, ":", v
except InvalidTagError, message:
print "Invalid ID3 tag:", message
How to read ID3 Tag in an MP3 using Python?
Dive into Python uses MP3 ID3 tags as an example.
How to get a custom MP3 tag via Python?
Yes, you can use either one. These custom tags are stored as user text frames, with the frame ID "TXXX".
Here's some example code with eyeD3:
import eyed3
file = eyed3.load("test.mp3")
for frame in file.tag.frameiter(["TXXX"]):
print(f"{frame.description}: {frame.text}")
# get a specific tag
artist_id = file.tag.user_text_frames.get("MusicBrainz Artist Id").text
And with mutagen (it supports multiple values in each frame, but this seems to violates the ID3 spec; see this picard PR for the gory details):
from mutagen.id3 import ID3
audio = ID3("test.mp3")
for frame in audio.getall("TXXX"):
print(f"{frame.desc}: {frame.text}")
# get a specific tag
artist_id = audio["TXXX:MusicBrainz Artist Id"].text[0]
You can see how Picard uses mutagen to read these tags here: https://github.com/metabrainz/picard/blob/ee06ed20f3b6ec17d16292045724921773dde597/picard/formats/id3.py#L314-L336
How to extract Encoded by from mp3 metadata using Python?
It turns out the "Encoded by" field is buried in a list returned by the frame_set
object: audiofile.tag.frame_set['TENC'][0].text
Trying to access id3 tags of mp3 songs from a folder using a loop
Now that you typed the full error message the error is clear:
No such file or directory: '01 California Dreaming (copy).mp3'
That means that the call is correct but the file name you are using does not exist. You are thinking: "but it came from os.walk()
so it must exist!". Well yes, but os.walk()
returns a list of tuples, each of three values: root, dirs, files
. The files
list of names are the filenames in the root
directory.
Solution: you have to concatenate the root
and file
names:
for root, dir, files in os.walk("home/undead/ShareWindowsTest")":
for file in files:
path = os.path.join(root, file)
audiofile = eyeD3.Mp3AudioFile(path)
PS: Are you missing a leading /
in your os.walk("/home...)
?
Extract ID3 tags of a MP3 URL using python
You can do a partial download: Download file using partial download (HTTP) (if the server supports it)
on rereading, and seeing joelhardi's comment, this is even easier:
jcomeau@intrepid:/tmp$ python
Python 2.6.6 (r266:84292, Apr 20 2011, 11:58:30)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> urllib.urlopen('http://latest/temp.csv')
<addinfourl at 160617676 whose fp = <socket._fileobject object at 0x9872aec>>
>>> input=_
>>> input.read(128)
'gene,species,C_frame,start_exon1,end_exon1,start_exon2,end_exon2,start_exon3,end_exon3,start_exon4,end_exon4,intron1,intron2,int'
>>> input.close()
>>>
Related Topics
Validate Ssl Certificates with Python
How to Apply Piecewise Linear Fit in Python
Python - Is a Dictionary Slow to Find Frequency of Each Character
Pandas Groupby and Select Rows with the Minimum Value in a Specific Column
How to Save an Image Locally Using Python Whose Url Address I Already Know
How to Sum Values in a Column That Match a Given Condition Using Pandas
How to Plot a Gradient Color Line in Matplotlib
Python: Can Executable Zip Files Include Data Files
How to Escape Strings for SQLite Table/Column Names in Python
How to Find Numeric Columns in Pandas
Could Not Find a Version That Satisfies the Requirement Tensorflow
How to Make a Selenium Script Undetectable Using Geckodriver and Firefox Through Python
How to Compare Multiple Variables to the Same Value