MP3 の特定のフォルダーの歌詞を自動的に取得するプログラムを Python で作成しようとしています。[ azlyrics.com から歌詞を取得します]
これまでのところ、実際に歌詞を「lyrics」タグに埋め込む以外はすべて成功しています。
ここのタグから歌詞を読むことに関する質問に回答しました。
歌詞の設定を手伝ってもらえないかと思っていました。これが私のコードです。
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()
最後の 2 行目が実行された後、次のエラーが発生します。
Traceback (most recent call last):
File "<pyshell#62>", line 31, in <module>
mp3.tag.lyrics = lyrics
AttributeError: can't set attribute
また、私は 15 歳で、Python を学習して約 1 年になります。私はあらゆる場所を検索し、すべてを試しましたが、今すぐ助けが必要だと思います.
ご協力いただきありがとうございます。