TIT2 id3 tag import fixes

This commit is contained in:
billypom on debian 2024-08-18 16:07:21 -04:00
parent aea3a6cdc3
commit 9be971f1b3
2 changed files with 10 additions and 11 deletions

View File

@ -1,6 +1,7 @@
import DBA
from configparser import ConfigParser
from utils import get_id3_tags, id3_timestamp_to_datetime
import logging
config = ConfigParser()
config.read("config.ini")
@ -11,6 +12,7 @@ def add_files_to_library(files):
files = list() of fully qualified paths to audio file(s)
Returns a list of dictionaries of metadata
"""
print("Running add_files_to_library.py")
if not files:
return []
extensions = config.get("settings", "extensions").split(",")
@ -19,13 +21,11 @@ def add_files_to_library(files):
if any(filepath.lower().endswith(ext) for ext in extensions):
filename = filepath.split("/")[-1]
audio = get_id3_tags(filepath)
# print("add_files_to_library audio:")
# print(audio)
# Skip if no title is found (but should never happen
if "TIT2" not in audio:
continue
title = audio["TIT2"].text[0]
try:
title = audio["TIT2"].text[0]
except KeyError as e:
title = filename
try:
artist = audio["TPE1"].text[0]
except KeyError:

View File

@ -44,14 +44,13 @@ def get_id3_tags(file):
# If 'TIT2' tag is not set, add it with a default value (title will be the filename without extension)
title = os.path.splitext(os.path.basename(file))[0]
for key in list(audio.keys()):
if key == "TIT2":
audio[key].text[0] = title
break
list_of_id3_tags = list(audio.keys())
if "TIT2" in list_of_id3_tags:
audio.save()
return audio
else:
tit2_tag = TIT2(encoding=3, text=[title])
audio["TIT2"] = tit2_tag
# Save the updated tags
audio.save()