Implement parallel download - #7
Open
LainX84 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Changes
This Pull Request introduces concurrent image downloading, resolves a critical startup
IndexErrorcrash, and significantly increases downloader robustness by improving the HTTP retry and rate-limiting logic.Key Changes
1. Bug Fix & URL Normalization
IndexError: list index out of rangeinCrawler._generate_album_pagesthat occurred when downloading single-page albums. The crawler now parses pagination parameters safely, finds the maximum page usingmax(), and dynamically builds the page list rather than relying on a fragile hardcoded index ([-2]).CrawlerandAlbumDownloaderto guarantee a trailing slash/and strip existing query parameters (such as?p=...). This prevents regex pattern matching mismatches against gallery HTML links.2. Parallelized Image Downloads
ThreadPoolExecutorinAlbumDownloaderto download the pictures of a gallery page concurrently.MAX_WORKERSsetting (defaulting to5) inconfig.pyto customize download speed while keeping requests polite.threading.Lock) insideProgressManagerandLiveManagerto prevent terminal UI glitches or exceptions during concurrent progress updates.requests.Sessionheader mutation by passing request-specific headers directly to each request, ensuring thread-safe operations.3. Improved HTTP Retry & Rate-Limiting Logic
fetch_with_retriesto specifically handle rate-limit status codes429(Too Many Requests) and509(Bandwidth Exceeded). The downloader now logs a rate-limit warning, sleeps forRATE_LIMIT_SLEEPING_TIME(60 seconds), and retries the download.404 Not Found) to prevent redundant retry attempts.Files Changed
src/config.py: Added theMAX_WORKERSconfiguration.src/crawler/crawler.py: Fixed the IndexError, normalized URLs, and added the thread-safeget_reloaded_page()helper.src/downloader/album_downloader.py: Redesigned downloading logic to run concurrently.src/downloader/download_utils.py: Added thread-safe headers support and improved retry logic (handling of 429/509/404).src/managers/progress_manager.py&src/managers/live_manager.py: Integrated thread-safety locks for UI rendering.