akd*_*dom 113 python mp3 metadata
在python中检索mp3元数据的最佳方法是什么?我已经看到了几个框架,但我不确定哪个框架最好用......哪有想法?
Owe*_*wen 101
我前几天使用eyeD3取得了很大的成功.我发现它可以在ID3标签上添加艺术品,而我看到的其他模块则不能.您必须python setup.py install从源文件夹下载tar并执行.
该网站的相关示例如下.
读取包含v1或v2标签信息的mp3文件的内容:
import eyeD3
tag = eyeD3.Tag()
tag.link("/some/file.mp3")
print tag.getArtist()
print tag.getAlbum()
print tag.getTitle()
Run Code Online (Sandbox Code Playgroud)
读取mp3文件(曲目长度,比特率等)并访问它的标签:
if eyeD3.isMp3File(f):
audioFile = eyeD3.Mp3AudioFile(f)
tag = audioFile.getTag()
Run Code Online (Sandbox Code Playgroud)
可以选择特定的标签版本:
tag.link("/some/file.mp3", eyeD3.ID3_V2)
tag.link("/some/file.mp3", eyeD3.ID3_V1)
tag.link("/some/file.mp3", eyeD3.ID3_ANY_VERSION) # The default.
Run Code Online (Sandbox Code Playgroud)
或者你可以迭代原始帧:
tag = eyeD3.Tag()
tag.link("/some/file.mp3")
for frame in tag.frames:
print frame
Run Code Online (Sandbox Code Playgroud)
将标记链接到文件后,可以对其进行修改和保存:
tag.setArtist(u"Cro-Mags")
tag.setAlbum(u"Age of Quarrel")
tag.update()
Run Code Online (Sandbox Code Playgroud)
如果链接的标记是v2,并且您想将其保存为v1:
tag.update(eyeD3.ID3_V1_1)
Run Code Online (Sandbox Code Playgroud)
读入标记并将其从文件中删除:
tag.link("/some/file.mp3")
tag.remove()
tag.update()
Run Code Online (Sandbox Code Playgroud)
添加新标签:
tag = eyeD3.Tag()
tag.link('/some/file.mp3') # no tag in this file, link returned False
tag.header.setVersion(eyeD3.ID3_V2_3)
tag.setArtist('Fugazi')
tag.update()
Run Code Online (Sandbox Code Playgroud)
Chr*_*ord 18
一个问题eyed3是它会抛出NotImplementedError("Unable to write ID3 v2.2")常见的MP3文件.
根据我的经验,mutagen课程的EasyID3工作更加可靠.例:
from mutagen.easyid3 import EasyID3
audio = EasyID3("example.mp3")
audio['title'] = u"Example Title"
audio['artist'] = u"Me"
audio['album'] = u"My album"
audio['composer'] = u"" # clear
audio.save()
Run Code Online (Sandbox Code Playgroud)
所有其他标签都可以通过这种方式访问并保存,这将用于大多数目的.更多信息可以在Mutagen教程中找到.
Har*_*mbe 13
您所追求的是ID3模块.它非常简单,可以满足您的需求.只需将ID3.py文件复制到您的site-packages目录中,您就可以执行以下操作:
from ID3 import *
try:
id3info = ID3('file.mp3')
print id3info
# Change the tags
id3info['TITLE'] = "Green Eggs and Ham"
id3info['ARTIST'] = "Dr. Seuss"
for k, v in id3info.items():
print k, ":", v
except InvalidTagError, message:
print "Invalid ID3 tag:", message
Run Code Online (Sandbox Code Playgroud)
检查一下:
https://github.com/Ciantic/songdetails
用法示例:
>>> import songdetails
>>> song = songdetails.scan("data/song.mp3")
>>> print song.duration
0:03:12
Run Code Online (Sandbox Code Playgroud)
保存更改:
>>> import songdetails
>>> song = songdetails.scan("data/commit.mp3")
>>> song.artist = "Great artist"
>>> song.save()
Run Code Online (Sandbox Code Playgroud)
我使用tinytag 1.3.1因为
1.3.0 (2020-03-09):
added option to ignore encoding errors ignore_errors #73
Improved text decoding for many malformed files
Run Code Online (Sandbox Code Playgroud)
MP3 (ID3 v1, v1.1, v2.2, v2.3+)
Wave/RIFF
OGG
OPUS
FLAC
WMA
MP4/M4A/M4B
Run Code Online (Sandbox Code Playgroud)
1.3.0 (2020-03-09):
added option to ignore encoding errors ignore_errors #73
Improved text decoding for many malformed files
Run Code Online (Sandbox Code Playgroud)
JoeTagPj>python joeTagTest.py
"artist": "Conan O’Brien Needs A Friend",
"album": "Conan O’Brien Needs A Friend",
"title": "17. Thomas Middleditch and Ben Schwartz",
"duration(secs)": "3565.1829583532785",
"artist": "Conan O’Brien Needs A Friend",
"album": "Conan O’Brien Needs A Friend",
"title": "Are you ready to make friends?",
"duration(secs)": "417.71840447045264",
"artist": "Conan O’Brien Needs A Friend",
"album": "Conan O’Brien Needs A Friend",
"title": "Introducing Conan’s new podcast",
"duration(secs)": "327.22187551899646",
"artist": "Conan O’Brien Needs A Friend",
"album": "Conan O’Brien Needs A Friend",
"title": "19. Ray Romano",
"duration(secs)": "3484.1986772305863",
C:\1d\PodcastPjs\JoeTagPj>
Run Code Online (Sandbox Code Playgroud)
最简单的方法是歌曲详细信息..
用于读取数据
import songdetails
song = songdetails.scan("blah.mp3")
if song is not None:
print song.artist
Run Code Online (Sandbox Code Playgroud)
同样用于编辑
import songdetails
song = songdetails.scan("blah.mp3")
if song is not None:
song.artist = u"The Great Blah"
song.save()
Run Code Online (Sandbox Code Playgroud)
不要忘记添加û名前直到你知道中国的语言。
您可以使用 python glob 模块批量读取和编辑
前任。
import glob
songs = glob.glob('*') # script should be in directory of songs.
for song in songs:
# do the above work.
Run Code Online (Sandbox Code Playgroud)
在尝试了pip install这里推荐的 eyeD3、pytaglib 和 ID3 模块的简单路线后,我发现第四个选项是唯一可行的。其余的有导入错误,缺少 C++ 中的依赖项或一些魔法或其他一些pip丢失的库。所以用这个来基本阅读 ID3 标签(所有版本):
https://pypi.python.org/pypi/tinytag/0.18.0
from tinytag import TinyTag
tag = TinyTag.get('/some/music.mp3')
Run Code Online (Sandbox Code Playgroud)
您可以使用 TinyTag 获得的可能属性列表:
tag.album # album as string
tag.albumartist # album artist as string
tag.artist # artist name as string
tag.audio_offset # number of bytes before audio data begins
tag.bitrate # bitrate in kBits/s
tag.disc # disc number
tag.disc_total # the total number of discs
tag.duration # duration of the song in seconds
tag.filesize # file size in bytes
tag.genre # genre as string
tag.samplerate # samples per second
tag.title # title of the song
tag.track # track number as string
tag.track_total # total number of tracks as string
tag.year # year or data as string
Run Code Online (Sandbox Code Playgroud)
正如宣传的那样,它小巧而独立。
| 归档时间: |
|
| 查看次数: |
97814 次 |
| 最近记录: |