misc
This commit is contained in:
@@ -4,6 +4,7 @@ import random
|
||||
import os
|
||||
import tarfile
|
||||
import uuid
|
||||
import re
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse, unquote
|
||||
@@ -39,6 +40,23 @@ HEADERS = {
|
||||
sr = SRUtil()
|
||||
|
||||
|
||||
import re
|
||||
|
||||
def sanitize_filename(name: str) -> str:
|
||||
"""
|
||||
Remove or replace characters not allowed in filenames.
|
||||
Also trims whitespace and collapses consecutive spaces.
|
||||
"""
|
||||
# Replace slashes/backslashes with a dash
|
||||
name = name.replace("/", "-").replace("\\", "-")
|
||||
# Remove illegal characters for most OSes
|
||||
name = re.sub(r'[<>:"|?*\x00-\x1F]', "", name)
|
||||
# Strip leading/trailing spaces and dots
|
||||
name = name.strip().strip(".")
|
||||
# Collapse multiple spaces into one
|
||||
name = re.sub(r"\s+", " ", name)
|
||||
return name or "Unknown"
|
||||
|
||||
def bulk_download(track_list: list):
|
||||
"""
|
||||
Full RQ-compatible bulk download job with:
|
||||
@@ -103,9 +121,9 @@ def bulk_download(track_list: list):
|
||||
track_id,
|
||||
)
|
||||
continue
|
||||
artist = metadata.get("artist", "Unknown Artist")
|
||||
album = metadata.get("album", "Unknown Album")
|
||||
title = metadata.get("song", "Unknown Song")
|
||||
artist = sanitize_filename(metadata.get("artist", "Unknown Artist"))
|
||||
album = sanitize_filename(metadata.get("album", "Unknown Album"))
|
||||
title = sanitize_filename(metadata.get("song", "Unknown Song"))
|
||||
|
||||
logging.critical("Got metadata: %s/%s/%s", artist, album, title)
|
||||
|
||||
@@ -138,7 +156,7 @@ def bulk_download(track_list: list):
|
||||
per_track_meta.append(track_info)
|
||||
if job:
|
||||
job.meta["progress"] = int((i + 1) / total * 100)
|
||||
job.meta["tracks"] = per_track_meta
|
||||
job.meta["tracks"] = track_list
|
||||
job.save_meta()
|
||||
|
||||
# Throttle between downloads
|
||||
|
Reference in New Issue
Block a user