mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-05 14:19:56 -05:00
Add per-domain and global daily download limits
Adds two optional DownloadManager settings: - download_daily_limit_per_domain: max non-recurring downloads per domain per day - download_daily_limit_global: max non-recurring downloads across all domains per day Recurring Channel/RSS catalog updates are never gated and never counted; only the videos/archives they spawn and one-off downloads count. Both successful and failed attempts consume a slot (counted once per download per day). Limits reset at local midnight (configured timezone). Over-limit downloads stay "new" and resume the next day. Implementation: - New Download.last_download_attempt column (+ index, migration) set at dispatch time so the count survives restarts and is correct across workers. - dispatch_downloads gates non-recurring downloads: per-domain skips that domain, global stops dispatching counted downloads for the cycle. daily_download_counts derives the day's totals from the DB. - Domain grouping uses normalized URLs via a new Downloader.normalize_domain method (base strips www/m/mobile + port); VideoDownloader/ChannelDownloader override it to collapse youtu.be, /shorts/, and tracking params to youtube.com. ArchiveDownloader is the seam for future archive URL normalization. - Settings wired through WROLPiConfig, the /settings API (GET/PATCH, non-negative validation, 0 = unlimited), and the React Settings page. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d6862ecd2d
commit
d95249218b
9 changed files with 478 additions and 11 deletions
|
|
@ -23,7 +23,7 @@ from yt_dlp.extractor import YoutubeTabIE # noqa
|
|||
|
||||
from wrolpi.cmd import YT_DLP_BIN
|
||||
from wrolpi.common import logger, get_media_directory, escape_file_name, resolve_generators, background_task, \
|
||||
trim_file_name, cached_multiprocessing_result, get_absolute_media_path, aiohttp_post
|
||||
trim_file_name, cached_multiprocessing_result, get_absolute_media_path, aiohttp_post, normalize_domain
|
||||
from wrolpi.dates import now
|
||||
from wrolpi.db import get_db_session
|
||||
from wrolpi.downloader import Downloader, Download, DownloadContext, DownloadResult, \
|
||||
|
|
@ -529,6 +529,10 @@ class ChannelDownloader(Downloader, ABC):
|
|||
def __repr__(self):
|
||||
return f'<ChannelDownloader>'
|
||||
|
||||
def normalize_domain(self, url: str) -> str:
|
||||
# Collapse youtu.be / youtube.com/shorts / tracking params to the canonical youtube.com domain.
|
||||
return normalize_domain(normalize_video_url(url))
|
||||
|
||||
@staticmethod
|
||||
def is_a_playlist(info: dict):
|
||||
# A playlist may have an id different from its channel.
|
||||
|
|
@ -793,6 +797,10 @@ class VideoDownloader(Downloader, ABC):
|
|||
def __repr__(self):
|
||||
return f'<VideoDownloader>'
|
||||
|
||||
def normalize_domain(self, url: str) -> str:
|
||||
# Collapse youtu.be / youtube.com/shorts / tracking params to the canonical youtube.com domain.
|
||||
return normalize_domain(normalize_video_url(url))
|
||||
|
||||
def already_downloaded(self, session: Session, *urls: str) -> List:
|
||||
# We only consider a video record with a video file as "downloaded".
|
||||
file_groups = list(session.query(FileGroup).filter(FileGroup.url.in_(urls), FileGroup.model == 'video'))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue