gpt4 book ai didi

python - 通过 eyeD3 更改 MP3 文件中的歌词

转载 作者:行者123 更新时间:2023-11-28 16:41:15 24 4
gpt4 key购买 nike

我正在尝试用 Python 创建一个程序,它可以自动检索特定 MP3 文件夹的歌词。 [我从azlyrics.com得到歌词]

到目前为止,除了将歌词实际嵌入“歌词”标签之外,我已经成功地完成了所有操作。

你回答了一个关于阅读歌词的问题 here .

我想知道您能否帮我设置歌词。这是我的代码。

import urllib2 # For downloading webpage
import time # For pausing
import eyed3 # For MP3s
import re # For replacing characters
import os # For reading folders


path = raw_input('Please enter folder of music') # TODO Must make GUI PATH SELECTION


files = os.listdir(path)
for x in files:
# Must make the program stop for a while to minimize server load
time.sleep(3)
# Opening MP3
mp3 = eyed3.load(path + '/' + x)
# Setting Values
artist = mp3.tag.artist.lower()
raw_song = str(mp3.tag.title).lower()
song = re.sub('[^0-9a-zA-Z]+', '', raw_song) #Stripping songs of anything other than alpha-numeric characters
# Generating A-Z Lyrics URL
url = "http://www.azlyrics.com/lyrics/" + artist + "/" + song + ".html"
# Getting Source and extracting lyrics
text = urllib2.urlopen(url).read()
where_start = text.find('<!-- start of lyrics -->')
start = where_start + 26
where_end = text.find('<!-- end of lyrics -->')
end = where_end - 2
lyrics = unicode(text[start:end].replace('<br />', ''), "UTF8")
# Setting Lyrics to the ID3 "lyrics" tag
mp3.tag.lyrics = lyrics ### RUNNING INTO PROBLEMS HERE
mp3.tag.save()

在执行倒数第二行后,我遇到了以下错误:-

Traceback (most recent call last):
File "<pyshell#62>", line 31, in <module>
mp3.tag.lyrics = lyrics
AttributeError: can't set attribute

我还想让您知道,我今年 15 岁,已经学习 Python 大约一年了。我到处搜索并尝试了所有方法,但我想我现在需要一些帮助。

在此先感谢您的帮助!

最佳答案

我不假装理解为什么会这样,但请查看 the handy example file 中的歌词是如何设置的:

from eyed3.id3 import Tag

t = Tag()
t.lyrics.set(u"""la la la""")

我认为这与将歌词放入框架有关,但其他人可能不得不对此进行更正。请注意,除非您将它传递给 unicode,否则这将失败。

关于python - 通过 eyeD3 更改 MP3 文件中的歌词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18916127/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com