TIT2 id3 tag import fixes
This commit is contained in:
parent
aea3a6cdc3
commit
9be971f1b3
@ -1,6 +1,7 @@
|
|||||||
import DBA
|
import DBA
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from utils import get_id3_tags, id3_timestamp_to_datetime
|
from utils import get_id3_tags, id3_timestamp_to_datetime
|
||||||
|
import logging
|
||||||
|
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config.read("config.ini")
|
config.read("config.ini")
|
||||||
@ -11,6 +12,7 @@ def add_files_to_library(files):
|
|||||||
files = list() of fully qualified paths to audio file(s)
|
files = list() of fully qualified paths to audio file(s)
|
||||||
Returns a list of dictionaries of metadata
|
Returns a list of dictionaries of metadata
|
||||||
"""
|
"""
|
||||||
|
print("Running add_files_to_library.py")
|
||||||
if not files:
|
if not files:
|
||||||
return []
|
return []
|
||||||
extensions = config.get("settings", "extensions").split(",")
|
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):
|
if any(filepath.lower().endswith(ext) for ext in extensions):
|
||||||
filename = filepath.split("/")[-1]
|
filename = filepath.split("/")[-1]
|
||||||
audio = get_id3_tags(filepath)
|
audio = get_id3_tags(filepath)
|
||||||
# print("add_files_to_library audio:")
|
|
||||||
# print(audio)
|
|
||||||
|
|
||||||
# Skip if no title is found (but should never happen
|
try:
|
||||||
if "TIT2" not in audio:
|
title = audio["TIT2"].text[0]
|
||||||
continue
|
except KeyError as e:
|
||||||
title = audio["TIT2"].text[0]
|
title = filename
|
||||||
try:
|
try:
|
||||||
artist = audio["TPE1"].text[0]
|
artist = audio["TPE1"].text[0]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|||||||
@ -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)
|
# 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]
|
title = os.path.splitext(os.path.basename(file))[0]
|
||||||
for key in list(audio.keys()):
|
list_of_id3_tags = list(audio.keys())
|
||||||
if key == "TIT2":
|
if "TIT2" in list_of_id3_tags:
|
||||||
audio[key].text[0] = title
|
audio.save()
|
||||||
break
|
return audio
|
||||||
else:
|
else:
|
||||||
tit2_tag = TIT2(encoding=3, text=[title])
|
tit2_tag = TIT2(encoding=3, text=[title])
|
||||||
audio["TIT2"] = tit2_tag
|
audio["TIT2"] = tit2_tag
|
||||||
|
|
||||||
# Save the updated tags
|
# Save the updated tags
|
||||||
audio.save()
|
audio.save()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user