Batch Download Performance#
Two v5.8 changes compound to significantly increase wall-clock time during bulk scraping and downloading: a redesigned wait() delay injected after every API response, and an original_quality probe request fired for each Douyin video item. Understanding both is essential for diagnosing slowdowns or tuning throughput.
1. wait() โ Per-Request Rate-Limiting Delay#
get_wait_time() draws a random delay from a log-normal distribution:
- Default mean (
avg_delay): 6 seconds,sigma= 0.5 - Hard bounds: 1.5 s minimum, 33.3 s maximum
wait() is an async wrapper that calls await sleep(get_wait_time(...)). Its docstring explicitly states it applies only to data fetching, not file downloads .
wait() is called unconditionally after every successful API response. Because batch mode paginates by calling the single-item fetcher in a loop, every page of results in an account or collection incurs this delay. For accounts with many pages, cumulative delay is substantial.
To disable: In src/custom/function.py, comment out the await sleep(...) block and uncomment # pass. The maintainer warns this increases the probability of rate-limiting and platform risk controls .
2. original_quality โ Per-Video Probe Request#
When original_quality = true, the extractor fires an additional HTTP request for every Douyin video item to check whether a higher-quality source URL is available.
Default: false โ set via check_bool_false in parameter.py, which maps to the global application setting.
How it works in __extract_video_download():
- After selecting the best bitrate URL from the
bit_ratelist, the method checksuse_original_quality and self.download and self.original_quality. - If true, it constructs an "original quality" CDN URL from the video's
uriand calls__request_video_size(). __request_video_size()issues aGETwithRange: bytes=0-0to the CDN endpoint and parses theContent-Rangeresponse header to obtain total file size โ one real network round-trip per video .- The original URL is used only if its reported size โฅ the bitrate-selected URL's size ; otherwise the probe result is discarded, meaning the request is purely exploratory overhead.
__request_video_size()is decorated with@Retry.retry, so a network failure can trigger multiple additional retries .
Platform scope: original_quality is implemented only for Douyin. The TikTok video extraction path (__extract_video_download_tiktok()) does not include this logic.
Configuration scope: original_quality is a global-only setting. The accounts_urls entries support only mark, url, tab, earliest, latest, and enable fields โ there is no per-account original_quality override .
3. suspend() โ Optional Batch Cooldown#
A third, opt-in mechanism is suspend() in src/custom/function.py. When enabled it pauses for a configurable rest_time (default 5 minutes) every batches accounts/collections processed . It is disabled by default (the body is commented out in favor of # pass) and applies only to batch account/collection modes, not per-item fetching.
Tuning Reference#
| Goal | Action |
|---|---|
| Reduce per-video scraping overhead | Set original_quality: false (default) |
| Reduce inter-request delay | Comment out await sleep(...) in wait() and uncomment pass โ increases rate-limiting risk |
| Throttle large batch jobs | Enable suspend() with appropriate batches/rest_time values |
Key Files#
| File | Purpose |
|---|---|
src/custom/function.py | wait(), get_wait_time(), suspend() implementations |
src/extract/extractor.py | __extract_video_download() and __request_video_size() โ original quality probe logic |
src/config/parameter.py | Global original_quality parameter wiring; check_urls_params() defining the accounts_urls schema |