我正在创建一个标签编辑器,它在不同的 textLines 中以“之前”“之后”样式显示 mp3 文件的 ID3 标记。如果没有可用的标签,则不显示任何内容。您还可以编辑“之后”文本行,对它们所做的任何更改都应保存到文件中,但是当我按下 button2 时,我得到了底部回溯。如何将第 6-10 行保存为新的“audio["title"]、audio["artist"]" 等?这是图形用户界面
import sys
import easygui
import mutagen
from mutagen.easyid3 import EasyID3
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QDialog
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QLineEdit
lied = None
error = "No ID3-Tag available."
class TrackTag1(QDialog):
def __init__(self):
super(TrackTag1,self).__init__()
loadUi("TrackTag1.ui",self)
self.setWindowTitle("TrackTag")
@pyqtSlot()
def on_button1_clicked(self):
#root.fileName = filedialog.askopenfilename( filetypes = ( ("Musik Dateien", "*.mp3"), ("Alle Dateien", "*.*") ) )
#print(easygui.fileopenbox('MP3 Dateien','', '*.MP3'))
lied = easygui.fileopenbox('MP3 Dateien','', '*.MP3')
audio = EasyID3(lied)
self.line0.setText(lied) #printing filepath to line0
try:
self.line1.setText(str(audio["title"]).strip("[']")) #printing the ID3 tags after they've been stripped of "['']"
self.line6.setText(str(audio["title"]).strip("[']"))
except:
KeyError
self.line1.setText(error)
try:
self.line2.setText(str(audio["album"]).strip("[']"))
self.line7.setText(str(audio["album"]).strip("[']"))
except:
KeyError
self.line2.setText(error)
try:
self.line3.setText(str(audio["date"]).strip("[']"))
self.line8.setText(str(audio["date"]).strip("[']"))
except:
KeyError
self.line3.setText(error)
try:
self.line4.setText(str(audio["artist"]).strip("[']"))
self.line9.setText(str(audio["artist"]).strip("[']"))
except:
KeyError
self.line4.setText(error)
try:
self.line5.setText(str(audio["genre"]).strip("[']"))
self.line10.setText(str(audio["genre"]).strip("[']"))
except:
KeyError
self.line5.setText(error)
def on_button2_clicked(self):
audio = EasyID3(lied)
audio["title"] = self.line6.text()
audio.save()
app=QApplication(sys.argv)
widget=TrackTag1()
widget.show()
sys.exit(app.exec_())
app=QApplication(sys.argv)
widget=TrackTag1()
widget.show()
sys.exit(app.exec_())
当我按下保存更改按钮时,我得到了这个回溯:
Traceback (most recent call last):
File "<string>", line 69, in on_button2_clicked
File "h:\program files (x86)\python\lib\site-packages\mutagen\_util.py", line 139, in wrapper
writable, create) as h:
File "h:\program files (x86)\python\lib\contextlib.py", line 59, in __enter__
return next(self.gen)
File "h:\program files (x86)\python\lib\site-packages\mutagen\_util.py", line 270, in _openfile
raise TypeError("Missing filename or fileobj argument")
TypeError: Missing filename or fileobj argument
目前,您应该只能编辑标签,但我计划很快实现 MusicBrainz 查询。