【问题标题】:Changing lyrics in an MP3 file via eyeD3通过 eyeD3 更改 MP3 文件中的歌词
【发布时间】:2018-07-21 01:28:36
【问题描述】:

我正在尝试用 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 大约一年了。我到处搜索并尝试了所有方法,但我想我现在需要一些帮助。

提前感谢您的帮助!

【问题讨论】:

  • 看起来歌词应该是"specific" formatted string.,并且在浏览源代码时看到这样的警告消息:'"Fixing invalid Lyrics language code...' 也许将您设置的歌词代码更改为:mp3 .tag.lyrics = 'eng:MyDescription:'+lyrics 可以解决问题。
  • 我收到此错误:- Traceback(最近一次通话最后一次):文件“/home/prateek/Desktop/Auto Lyrics Getter.py”,第 31 行,在 mp3.tag.lyrics = 'eng:MyDescription:'+lyrics AttributeError: 无法设置属性
  • @PrateekAlat 您对此有正确答案吗?我一直在寻找这个答案。

标签: python mp3 eyed3


【解决方案1】:

chcp 65001

eyeD3 --encoding utf8 --add-lyrics "001-001.txt" 001-001.mp3

【讨论】:

  • 我按照此说明进行操作,但歌词现在显示在 Android 音乐播放器中...
【解决方案2】:

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

from eyed3.id3 import Tag

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-25
    • 1970-01-01
    • 2012-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    相关资源
    最近更新 更多