yea
This commit is contained in:
parent
34dde803ce
commit
d76bd67311
@ -42,7 +42,7 @@ class LyricsWindow(QDialog):
|
||||
"""Saves the current lyrics text to the USLT/lyrics ID3 tag"""
|
||||
success = set_tag(
|
||||
filepath=self.song_filepath,
|
||||
tag_name="lyrics",
|
||||
db_column="lyrics",
|
||||
value=self.input_field.toPlainText(),
|
||||
)
|
||||
if success:
|
||||
|
||||
@ -130,7 +130,9 @@ class MetadataWindow(QDialog):
|
||||
# Update the ID3 tag if the tag is not blank,
|
||||
# and has been edited
|
||||
success = set_tag(
|
||||
filepath=song[0], db_column=tag, value=field.text()
|
||||
filepath=song[0],
|
||||
db_column=self.headers.frame_id[tag].db,
|
||||
value=field.text(),
|
||||
)
|
||||
if success:
|
||||
update_song_in_database(
|
||||
|
||||
@ -5,20 +5,21 @@ from mutagen.id3 import ID3
|
||||
from mutagen.id3._util import ID3NoHeaderError
|
||||
from mutagen.id3._frames import USLT, Frame
|
||||
|
||||
def set_tag(filepath: str, tag_name: str, value: str):
|
||||
|
||||
def set_tag(filepath: str, db_column: str, value: str):
|
||||
"""
|
||||
Sets the ID3 tag for a file given a filepath, tag_name, and a value for the tag
|
||||
Sets the ID3 tag for a file given a filepath, db_column, and a value for the tag
|
||||
|
||||
Args:
|
||||
filepath: path to the mp3 file
|
||||
tag_name: db column name of the ID3 tag
|
||||
db_column: db column name of the ID3 tag
|
||||
value: value to set for the tag
|
||||
|
||||
Returns:
|
||||
True / False
|
||||
"""
|
||||
headers = HeaderTags2()
|
||||
debug(f"filepath: {filepath} | tag_name: {tag_name} | value: {value}")
|
||||
debug(f"filepath: {filepath} | db_column: {db_column} | value: {value}")
|
||||
|
||||
try:
|
||||
try: # Load existing tags
|
||||
@ -26,7 +27,7 @@ def set_tag(filepath: str, tag_name: str, value: str):
|
||||
except ID3NoHeaderError: # Create new tags if none exist
|
||||
audio_file = ID3()
|
||||
# Lyrics get handled differently
|
||||
if tag_name == "lyrics":
|
||||
if db_column == "lyrics":
|
||||
try:
|
||||
audio = ID3(filepath)
|
||||
except Exception as e:
|
||||
@ -38,14 +39,14 @@ def set_tag(filepath: str, tag_name: str, value: str):
|
||||
audio.save()
|
||||
return True
|
||||
# DB Tag into Mutagen Frame Class
|
||||
if tag_name in headers.db:
|
||||
frame_class = headers.db[tag_name].frame_class
|
||||
assert frame_class is not None # ooo scary
|
||||
if db_column in headers.db:
|
||||
frame_class = headers.db[db_column].frame_class
|
||||
assert frame_class is not None # ooo scary
|
||||
if issubclass(frame_class, Frame):
|
||||
frame = frame_class(encoding=3, text=[value])
|
||||
audio_file.add(frame)
|
||||
else:
|
||||
warning(f'Tag "{tag_name}" not found - ID3 tag update skipped')
|
||||
warning(f'Tag "{db_column}" not found - ID3 tag update skipped')
|
||||
audio_file.save(filepath)
|
||||
return True
|
||||
except Exception as e:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user