fix id3 tags editable by table cell edit
This commit is contained in:
parent
c6aed88838
commit
7ce1404ce2
@ -406,13 +406,18 @@ class MusicTable(QTableView):
|
|||||||
# update the ID3 information
|
# update the ID3 information
|
||||||
user_input_data: str = topLeft.data()
|
user_input_data: str = topLeft.data()
|
||||||
edited_column_name: str = self.headers.user_fields[topLeft.column()]
|
edited_column_name: str = self.headers.user_fields[topLeft.column()]
|
||||||
debug(
|
debug(f"on_cell_data_changed | edited column name: {edited_column_name}")
|
||||||
f"on_cell_data_changed | edited column name: {edited_column_name}")
|
response = set_tag(
|
||||||
response = set_tag(filepath, edited_column_name, user_input_data)
|
filepath=filepath,
|
||||||
|
tag_name=edited_column_name,
|
||||||
|
value=user_input_data
|
||||||
|
)
|
||||||
if response:
|
if response:
|
||||||
# Update the library with new metadata
|
# Update the library with new metadata
|
||||||
_ = update_song_in_database(
|
_ = update_song_in_database(
|
||||||
song_id, edited_column_name, user_input_data)
|
song_id, edited_column_name, user_input_data)
|
||||||
|
else:
|
||||||
|
error('ERROR: response failed')
|
||||||
return
|
return
|
||||||
|
|
||||||
def handle_progress(self, data: object):
|
def handle_progress(self, data: object):
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
from logging import debug, error
|
from logging import debug, error, warning
|
||||||
from components import ErrorDialog
|
from components import ErrorDialog
|
||||||
from components.HeaderTags import HeaderTags
|
from components.HeaderTags import HeaderTags
|
||||||
|
|
||||||
@ -82,7 +82,8 @@ mutagen_id3_tag_mapping = {
|
|||||||
|
|
||||||
|
|
||||||
def set_tag(filepath: str, tag_name: str, value: str):
|
def set_tag(filepath: str, tag_name: 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, tag_name, and a value for the tag
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
filepath: path to the mp3 file
|
filepath: path to the mp3 file
|
||||||
@ -90,9 +91,10 @@ def set_tag(filepath: str, tag_name: str, value: str):
|
|||||||
value: value to set for the tag
|
value: value to set for the tag
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True / False"""
|
True / False
|
||||||
|
"""
|
||||||
headers = HeaderTags()
|
headers = HeaderTags()
|
||||||
# debug(f"filepath: {filepath} | tag_name: {tag_name} | value: {value}")
|
debug(f"filepath: {filepath} | tag_name: {tag_name} | value: {value}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try: # Load existing tags
|
try: # Load existing tags
|
||||||
@ -109,7 +111,8 @@ def set_tag(filepath: str, tag_name: str, value: str):
|
|||||||
# audio_file.add(tdat_tag)
|
# audio_file.add(tdat_tag)
|
||||||
|
|
||||||
# Lyrics
|
# Lyrics
|
||||||
if tag_name == "lyrics" or tag_name == "USLT":
|
# if tag_name == "lyrics" or tag_name == "USLT":
|
||||||
|
if tag_name == "lyrics":
|
||||||
try:
|
try:
|
||||||
audio = ID3(filepath)
|
audio = ID3(filepath)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -120,20 +123,16 @@ def set_tag(filepath: str, tag_name: str, value: str):
|
|||||||
audio.add(frame)
|
audio.add(frame)
|
||||||
audio.save()
|
audio.save()
|
||||||
return True
|
return True
|
||||||
# Convert any ID3 tag or nice name (that i chose) into into the Mutagen Frame object
|
# Convert ID3 tag nice name (that i chose) into into the Mutagen Frame object
|
||||||
if tag_name in list(headers.id3_keys.values()):
|
if tag_name in mutagen_id3_tag_mapping: # Tag accounted for
|
||||||
tag_nice_name = headers.id3[tag_name]
|
tag_class = mutagen_id3_tag_mapping[tag_name]
|
||||||
else:
|
|
||||||
tag_nice_name = tag_name
|
|
||||||
# Other
|
|
||||||
if tag_nice_name in mutagen_id3_tag_mapping: # Tag accounted for
|
|
||||||
tag_class = mutagen_id3_tag_mapping[tag_nice_name]
|
|
||||||
if issubclass(tag_class, Frame):
|
if issubclass(tag_class, Frame):
|
||||||
frame = tag_class(encoding=3, text=[value])
|
frame = tag_class(encoding=3, text=[value])
|
||||||
audio_file.add(frame) # Add the tag
|
audio_file.add(frame) # Add the tag
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
warning('nice name tag not found - skipping updating id3 tag')
|
||||||
pass
|
pass
|
||||||
audio_file.save(filepath)
|
audio_file.save(filepath)
|
||||||
return True
|
return True
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user