我正在尝试在 Python 中创建一个程序,该程序会自动检索特定 MP3 文件夹的歌词。[我从azlyrics.com 得到歌词]
到目前为止,除了将歌词实际嵌入“歌词”标签之外,我已经成功完成了所有工作。
你在这里回答了一个关于从它的标签中阅读歌词的问题。
我想知道你是否可以帮我设置歌词。这是我的代码。
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 大约一年了。我到处搜索并尝试了所有方法,但我想我现在需要一些帮助。
提前感谢您的所有帮助!