update yt-dlp and fix some bugs with TPE2. Fixes #3

This commit is contained in:
2026-01-31 11:10:33 +00:00
parent 4aa0c5b6d9
commit 879a318e54
6 changed files with 174 additions and 91 deletions

View File

@@ -91,7 +91,9 @@ def search_google_images_and_save(x: str, audio):
if x.endswith(".flac"):
songpath = join(".",str(audio["artist"]),str(audio["album"]))
else:
songpath = join(".",str(audio["TPE2"]),str(audio["TALB"]))
# Use TPE2 if available, otherwise fallback to TPE1
artist_folder = str(audio.get("TPE2", audio.get("TPE1", "Unknown Artist")))
songpath = join(".", artist_folder, str(audio["TALB"]))
if "\x00" in songpath:
# having null bytes in os.replace will throw an error
songpath = songpath.replace("\x00",", ")
@@ -189,7 +191,7 @@ def create_ID3_tag(audio, tagname: str, textvalue: str):
def check_tag(audio, filename: str, ID3_tag: str, normal_tag) -> bool:
res = False
# check if the ID3 artist tag exists
# check if the ID3 tag exists
if (ID3_tag in audio.keys() and len(str(audio[ID3_tag])) != 0):
logging.info(ID3_tag + " ID3 tag found! " + str(audio[ID3_tag]))
@@ -201,7 +203,7 @@ def check_tag(audio, filename: str, ID3_tag: str, normal_tag) -> bool:
logging.info("Set " + normal_tag + " to " + str(audio[normal_tag]))
res = True
# check if general album tag exists
# check if general tag exists
elif (normal_tag in audio.keys() and len(str(audio[normal_tag])) != 0):
logging.info(normal_tag + " normal tag found! " + str(audio[normal_tag]))
if audio[normal_tag] is not str:
@@ -228,6 +230,11 @@ def check_title_songname(x: str, audio):
if (" - " in x):
items = x.split(" - ")
# If the format is 'artist - Topic - title', remove 'Topic'
if len(items) > 2 and items[1].strip().lower() == "topic":
logging.info("Detected ' - Topic - ' in name, removing 'Topic'.")
# Rebuild items without 'Topic'
items = [items[0]] + items[2:]
if (len(items) > 2):
logging.info("song title has more than 1 part after the -: " + str(items))
if (items[1].count(".mp3") >= 1):
@@ -266,7 +273,7 @@ def check_for_multiple_artists(audio, filename: str, name: str):
artists = name.split(",")
elif ("/" in name):
artists = name.split("/")
elif ("\x00" in name):
elif ("\x00" in name):
artists = name.split("\x00")
if (len(artists) > 0):
@@ -276,7 +283,11 @@ def check_for_multiple_artists(audio, filename: str, name: str):
else:
audio["TPE1"] = TPE2(encoding=3,text=["\0".join(artists)])
else:
logging.info("no multiple artists found in name " + name)
logging.info("no multiple artists found in name " + name + ", setting artist to " + name)
if filename.endswith(".flac"):
audio["artist"] = TPE2(encoding=3,text=name)
else:
audio["TPE1"] = TPE2(encoding=3,text=name)
# checks for any artist from the song name. If it exists it sets the properties of the file
@@ -297,6 +308,9 @@ def check_artist(audio, filename: str) -> bool:
res = False
# check if the ID3 artist tag exists
check_tag(audio, filename, "TPE1","artist")
check_tag(audio, filename, "TPE2","artist")
if ("TPE1" in audio.keys()):
if (len(str(audio["TPE1"])) != 0):
logging.info("TPE1 tag was found! " + str(audio["TPE1"]))
@@ -445,9 +459,9 @@ def check_spotify_album_and_save(spotify, audio,x: str) -> bool:
comment ="Spotify ID: {0}. Release date precision: {1}, total tracks in album: {2}. This album has {3} version(s)".format(album["id"],album["release_date_precision"], album["total_tracks"],len(results["albums"]["items"]))
logging.info("Comment: " + comment)
if x.endswith(".flac"):
audio["comment"] = comment
audio["comment"] = audio["comment"] + comment
else:
audio["COMM"] = COMM(encoding=3,text=comment)
audio["COMM"] = COMM(encoding=3,text=comment + audio["COMM"])
if x.endswith(".flac"):
remove_flac_ID3_tags(audio,x)
@@ -748,10 +762,12 @@ def main():
logging.info("valid artist found. making folder for artist " + str(audio["artist"][0]))
make_folder(join(".",str(audio["artist"][0])))
else:
logging.info("valid artist found. making folder for artist " + str(audio["TPE1"]))
if "/" in audio["TPE2"]:
audio["TPE2"] = audio["TPE2"].replace("/","")
make_folder(join(".",str(audio["TPE2"])))
# Use TPE2 if available, otherwise fallback to TPE1
artist_folder = str(audio.get("TPE2", audio.get("TPE1", "Unknown Artist")))
logging.info("valid artist found. making folder for artist " + artist_folder)
if "/" in artist_folder:
artist_folder = artist_folder.replace("/","")
make_folder(join(".", artist_folder))
if (has_valid_album):
if (x.endswith(".flac")):