Skip to content

Commit 761fcec

Browse files
committed
chore(grut): minor fixes
chore(grut): minor fixes
1 parent 984c156 commit 761fcec

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

gui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import customtkinter as ctk
1212
from downloader import main as downloader_main
1313

14-
GUI_VERSION = "2025.09.14"
14+
GUI_VERSION = "2025.11.22"
1515

1616
def resource_path(relative_path):
1717
""" Get absolute path to resource, works for dev and for PyInstaller """

helpers/crawlers/crawler_utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging
66
import re
7+
import uuid
78
from pathlib import Path
89
from typing import TYPE_CHECKING
910

@@ -70,9 +71,12 @@ async def extract_all_album_item_pages(
7071
async def get_item_download_link(
7172
item_url: str,
7273
soup: BeautifulSoup | None = None,
73-
) -> str:
74+
) -> str | None:
7475
"""Retrieve the download link for a specific item from its HTML content."""
7576
api_response = get_api_response(item_url, soup=soup)
77+
if api_response is None:
78+
logging.warning(f"Failed to get API response for {item_url}")
79+
return None
7680
return decrypt_url(api_response)
7781

7882

@@ -82,6 +86,10 @@ def get_item_filename(item_soup: BeautifulSoup) -> str:
8286
"h1",
8387
{"class": "text-subs font-semibold text-base sm:text-lg truncate"},
8488
)
89+
if item_filename_container is None:
90+
random_filename = f"file_{uuid.uuid4().hex[:12]}"
91+
logging.warning(f"Failed to extract filename from HTML, using: {random_filename}")
92+
return random_filename
8593
item_filename = item_filename_container.get_text()
8694
return item_filename.encode("latin1").decode("utf-8")
8795

@@ -111,6 +119,11 @@ def format_item_filename(original_filename: str, url_based_filename: str) -> str
111119
async def get_download_info(item_url: str, item_soup: BeautifulSoup) -> tuple:
112120
"""Gather download information (link and filename) for the item."""
113121
item_download_link = await get_item_download_link(item_url, soup=item_soup)
122+
123+
# If we couldn't get the download link, return None for both values
124+
if item_download_link is None:
125+
return None, None
126+
114127
item_filename = get_item_filename(item_soup)
115128

116129
url_based_filename = (

helpers/downloaders/album_downloader.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ async def execute_item_download(
6161
failed_download = await asyncio.to_thread(media_downloader.download)
6262
if failed_download:
6363
self.failed_downloads.append(failed_download)
64+
else:
65+
# Skip this item if no download link could be obtained
66+
self.live_manager.update_log(
67+
"Download skipped",
68+
f"Failed to get download link for: {item_page}",
69+
)
70+
self.live_manager.update_task(task, completed=100, visible=False)
6471

6572
async def download_album(self, max_workers: int = MAX_WORKERS) -> None:
6673
"""Handle the album download."""

helpers/url_utils.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import logging
1212
import re
1313
import sys
14+
import uuid
1415
from typing import TYPE_CHECKING
1516
from urllib.parse import unquote, urlparse, urlunparse
1617

@@ -125,9 +126,17 @@ def get_album_name(soup: BeautifulSoup) -> str | None:
125126
)
126127

127128
if not name_container:
128-
return None
129-
130-
raw_album_name = name_container.find("h1").get_text(strip=True)
129+
random_name = f"album_{uuid.uuid4().hex[:12]}"
130+
logging.warning(f"Failed to extract album name from HTML, using: {random_name}")
131+
return random_name
132+
133+
h1_tag = name_container.find("h1")
134+
if h1_tag is None:
135+
random_name = f"album_{uuid.uuid4().hex[:12]}"
136+
logging.warning(f"Failed to extract album name from h1 tag, using: {random_name}")
137+
return random_name
138+
139+
raw_album_name = h1_tag.get_text(strip=True)
131140
unescaped_album_name = html.unescape(raw_album_name)
132141

133142
# Attempt to fix mojibake (UTF-8 bytes mis-decoded as Latin-1). If encoding/decoding

0 commit comments

Comments
 (0)