mirror of
https://github.com/oskvr37/tiddl.git
synced 2026-06-13 04:05:08 +03:00
🐛 Album/artist download errors related to templates are now handled (#257)
* refactor variable name in _clean_segment function for clarity * Add error handling documentation for format_template function * Add error handling for album template formatting in download_callback
This commit is contained in:
@@ -299,15 +299,26 @@ def download_callback(
|
||||
)
|
||||
|
||||
for album_item in album_items.items:
|
||||
try:
|
||||
template = TEMPLATE or CONFIG.templates.album
|
||||
file_path = format_template(
|
||||
template=template,
|
||||
item=album_item.item,
|
||||
album=album,
|
||||
quality=get_item_quality(album_item.item),
|
||||
)
|
||||
|
||||
except AttributeError as exc:
|
||||
log.error(f"{exc=}")
|
||||
ctx.obj.console.print(
|
||||
f"[red]Wrong Album Template:[/] {exc} ({template=}, {album.id=}, {album_item.item.id=})"
|
||||
)
|
||||
continue
|
||||
|
||||
futures.append(
|
||||
handle_item(
|
||||
item=album_item.item,
|
||||
file_path=format_template(
|
||||
template=TEMPLATE or CONFIG.templates.album,
|
||||
item=album_item.item,
|
||||
album=album,
|
||||
quality=get_item_quality(album_item.item),
|
||||
),
|
||||
file_path=file_path,
|
||||
track_metadata=Metadata(
|
||||
cover=cover,
|
||||
date=str(album.releaseDate),
|
||||
@@ -563,9 +574,9 @@ def download_callback(
|
||||
try:
|
||||
await handle_resource(r)
|
||||
except ApiError as e:
|
||||
ctx.obj.console.print(f"[red]API Error:[/] {e} at {r}")
|
||||
ctx.obj.console.print(f"[red]API Error:[/] {e} ({r})")
|
||||
except Exception as e:
|
||||
ctx.obj.console.print(f"[red]Error:[/] {e} at {r}")
|
||||
ctx.obj.console.print(f"[red]Error:[/] {e} ({r})")
|
||||
|
||||
await asyncio.gather(*(wrapper(r) for r in ctx.obj.resources))
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@ def _clean_segment(text: str) -> str:
|
||||
- Ensures the segment is never empty (uses "_" as fallback).
|
||||
"""
|
||||
|
||||
s = sanitize_string(text)
|
||||
s = re.sub(r"\.{2,}", ".", s)
|
||||
s = s.rstrip(" .")
|
||||
s = re.sub(r"\s{2,}", " ", s)
|
||||
s = s.strip()
|
||||
text = sanitize_string(text)
|
||||
text = re.sub(r"\.{2,}", ".", text)
|
||||
text = text.rstrip(" .")
|
||||
text = re.sub(r"\s{2,}", " ", text)
|
||||
text = text.strip()
|
||||
|
||||
return s or "_"
|
||||
return text or "_"
|
||||
|
||||
|
||||
class Explicit:
|
||||
@@ -202,6 +202,10 @@ def format_template(
|
||||
with_asterisk_ext: bool = True,
|
||||
**extra,
|
||||
) -> str:
|
||||
"""
|
||||
Raises `AttributeError` on invalid template.
|
||||
"""
|
||||
|
||||
custom_fields = {"now": datetime.now()}
|
||||
|
||||
data = (
|
||||
|
||||
Reference in New Issue
Block a user