fix(dl): prevent attachment downloads during --skip-dl

Set DOWNLOAD_LICENCE_ONLY earlier in the download command so services build tracks in license-only mode.

Update Attachment URL handling to avoid eager downloads in license-only mode while keeping metadata, stable IDs, and safe cleanup behavior.
This commit is contained in:
Andy
2026-02-03 21:20:26 -07:00
parent c83b7a853e
commit a6494d9b54
2 changed files with 41 additions and 25 deletions

View File

@@ -897,6 +897,9 @@ class dl:
self.search_source = None self.search_source = None
start_time = time.time() start_time = time.time()
if skip_dl:
DOWNLOAD_LICENCE_ONLY.set()
if not acodec: if not acodec:
acodec = [] acodec = []
elif isinstance(acodec, Audio.Codec): elif isinstance(acodec, Audio.Codec):
@@ -1577,9 +1580,6 @@ class dl:
dl_start_time = time.time() dl_start_time = time.time()
if skip_dl:
DOWNLOAD_LICENCE_ONLY.set()
try: try:
with Live(Padding(download_table, (1, 5)), console=console, refresh_per_second=5): with Live(Padding(download_table, (1, 5)), console=console, refresh_per_second=5):
with ThreadPoolExecutor(downloads) as pool: with ThreadPoolExecutor(downloads) as pool:

View File

@@ -10,6 +10,7 @@ from zlib import crc32
import requests import requests
from unshackle.core.config import config from unshackle.core.config import config
from unshackle.core.constants import DOWNLOAD_LICENCE_ONLY
class Attachment: class Attachment:
@@ -43,6 +44,8 @@ class Attachment:
if path is None and url is None: if path is None and url is None:
raise ValueError("Either path or url must be provided.") raise ValueError("Either path or url must be provided.")
self.url = url
if url: if url:
if not isinstance(url, str): if not isinstance(url, str):
raise ValueError("The attachment URL must be a string.") raise ValueError("The attachment URL must be a string.")
@@ -57,7 +60,10 @@ class Attachment:
download_path = config.directories.temp / file_name download_path = config.directories.temp / file_name
# Download the file # Download the file unless we're in license-only mode
if DOWNLOAD_LICENCE_ONLY.is_set():
path = None
else:
try: try:
session = session or requests.Session() session = session or requests.Session()
response = session.get(url, stream=True) response = session.get(url, stream=True)
@@ -73,25 +79,30 @@ class Attachment:
except Exception as e: except Exception as e:
raise ValueError(f"Failed to download attachment from URL: {e}") raise ValueError(f"Failed to download attachment from URL: {e}")
if not isinstance(path, (str, Path)): if path is not None and not isinstance(path, (str, Path)):
raise ValueError("The attachment path must be provided.") raise ValueError("The attachment path must be provided.")
if path is not None:
path = Path(path) path = Path(path)
if not path.exists(): if not path.exists():
raise ValueError("The attachment file does not exist.") raise ValueError("The attachment file does not exist.")
if path is not None:
name = (name or path.stem).strip() name = (name or path.stem).strip()
else:
name = (name or Path(file_name).stem).strip()
mime_type = (mime_type or "").strip() or None mime_type = (mime_type or "").strip() or None
description = (description or "").strip() or None description = (description or "").strip() or None
if not mime_type: if not mime_type:
suffix = path.suffix.lower() if path is not None else Path(file_name).suffix.lower()
mime_type = { mime_type = {
".ttf": "application/x-truetype-font", ".ttf": "application/x-truetype-font",
".otf": "application/vnd.ms-opentype", ".otf": "application/vnd.ms-opentype",
".jpg": "image/jpeg", ".jpg": "image/jpeg",
".jpeg": "image/jpeg", ".jpeg": "image/jpeg",
".png": "image/png", ".png": "image/png",
}.get(path.suffix.lower(), mimetypes.guess_type(path)[0]) }.get(suffix, mimetypes.guess_type(file_name if path is None else path)[0])
if not mime_type: if not mime_type:
raise ValueError("The attachment mime-type could not be automatically detected.") raise ValueError("The attachment mime-type could not be automatically detected.")
@@ -111,11 +122,16 @@ class Attachment:
@property @property
def id(self) -> str: def id(self) -> str:
"""Compute an ID from the attachment data.""" """Compute an ID from the attachment data."""
if self.path and self.path.exists():
checksum = crc32(self.path.read_bytes()) checksum = crc32(self.path.read_bytes())
elif self.url:
checksum = crc32(self.url.encode("utf8"))
else:
checksum = crc32(self.name.encode("utf8"))
return hex(checksum) return hex(checksum)
def delete(self) -> None: def delete(self) -> None:
if self.path: if self.path and self.path.exists():
self.path.unlink() self.path.unlink()
self.path = None self.path = None