feat: enhance duplicate prevention to support FLAC, M4A, WAV, OPUS, OGG, and strip track numbers
Build and Push Docker Images / build (api) (push) Successful in 2m10s Details
Build and Push Docker Images / build (musicseerr) (push) Successful in 9m45s Details
Build and Push Docker Images / build (web) (push) Successful in 4m1s Details
Build and Push Docker Images / build (nextgen) (push) Successful in 16m1s Details
Build and Push Docker Images / build (worker) (push) Successful in 13m6s Details
Build and Push Docker Images / deploy (push) Successful in 51s Details

This commit is contained in:
fchinembiri 2026-07-10 01:05:19 +02:00
parent 4e42ad4705
commit 00c7498859
1 changed files with 30 additions and 6 deletions

View File

@ -229,8 +229,8 @@ def send_telegram_notification(chat_id: int, text: str):
def symlink_existing_tracks(temp_dir: str):
"""
Finds all MP3 files recursively in /remote-music/music and creates symlinks to them
in the temp_dir so spotDL and yt-dlp skip downloading duplicates.
Finds all audio files recursively in /remote-music/music, extracts artist and title,
and creates symlinks named "Artist - Title.mp3" in temp_dir so spotDL skips them.
"""
remote_base = "/remote-music/music"
if not os.path.isdir(remote_base):
@ -240,15 +240,39 @@ def symlink_existing_tracks(temp_dir: str):
count = 0
for root, dirs, files in os.walk(remote_base):
for file in files:
if file.endswith(".mp3"):
src_path = os.path.join(root, file)
dest_path = os.path.join(temp_dir, file)
if file.lower().endswith((".mp3", ".flac", ".m4a", ".ogg", ".wav", ".opus")):
# Try to clean/extract artist and title
base_name = os.path.splitext(file)[0]
# Strip leading numbers like "01. ", "01 - ", etc.
cleaned = re.sub(r'^\d+[\s.-]+', '', base_name).strip()
# We expect the file to have a " - " separator
if " - " in cleaned:
parts = cleaned.split(" - ", 1)
artist = parts[0].strip()
title = parts[1].strip()
# Target filename that spotDL expects
target_name = f"{artist} - {title}.mp3"
else:
# Fallback to direct name with .mp3 extension
target_name = f"{cleaned}.mp3"
# Replaces invalid chars
target_name = "".join([c for c in target_name if c.isalnum() or c in " .-_()"]).strip()
if not target_name.endswith(".mp3"):
target_name += ".mp3"
dest_path = os.path.join(temp_dir, target_name)
if not os.path.exists(dest_path):
try:
src_path = os.path.join(root, file)
os.symlink(src_path, dest_path)
count += 1
except Exception as e:
logger.warning(f"Failed to create symlink for {file}: {e}")
logger.warning(f"Failed to create symlink for {file} -> {target_name}: {e}")
logger.info(f"Created {count} symlinks for existing tracks.")