Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: use group for max-children
NTFSvolumed3f6fd091f7c
diff --git a/cyberdrop_dl/config/__init__.py b/cyberdrop_dl/config/__init__.pyindex d1e35f8ff..161076a4f 100644--- a/cyberdrop_dl/config/__init__.py+++ b/cyberdrop_dl/config/__init__.py@@ -12,14 +12,14 @@ from pydantic import AfterValidator, BaseModel, Field, NonNegativeInt, PositiveIfrom cyberdrop_dl.config.appdata import AppDatafrom cyberdrop_dl.exceptions import CDLConfigRuntimeErrorsGroup, InvalidYamlErrorfrom cyberdrop_dl.models import ConfigModel-from cyberdrop_dl.models.types import ByteSizeSerilized, FalsyAsTuple # noqa: TC001+from cyberdrop_dl.models.types import ByteSizeSerilized # noqa: TC001from cyberdrop_dl.models.validators import to_bytesizefrom cyberdrop_dl.utils import cleanupfrom .auth import Authentication, Notificationsfrom .crawlers import Crawlersfrom .filters import Filters-from .settings import Downloads, Hashing, Jdownloader, Logs, Network, Sort, SubFolders, UIOptions+from .settings import Downloads, Hashing, Jdownloader, Logs, MaxChildren, Network, Sort, SubFolders, UIOptionsif TYPE_CHECKING:from collections.abc import Iterable@@ -76,7 +76,7 @@ class Config(ConfigModel, title="cyberdrop-dl config"):jdownloader: Jdownloader = Field(default_factory=Jdownloader)logs: Logs = Field(default_factory=Logs)- max_children: FalsyAsTuple[NonNegativeInt] = ()+ max_children: MaxChildren = Field(default_factory=MaxChildren)"Limit the number of items to scrape per category"max_file_name_length: PositiveInt = 95diff --git a/cyberdrop_dl/config/default.yaml b/cyberdrop_dl/config/default.yamlindex 189a534d2..976d3596b 100644--- a/cyberdrop_dl/config/default.yaml+++ b/cyberdrop_dl/config/default.yaml@@ -104,7 +104,11 @@ logs:folder: nulllevel: DEBUGrotate: false-max_children: []+max_children:+ album: 0+ forum: 0+ forum_post: 0+ profile: 0max_file_name_length: 95max_folder_name_length: 60max_thread_depth: 0diff --git a/cyberdrop_dl/config/schema.json b/cyberdrop_dl/config/schema.jsonindex 3703710ca..3234575c5 100644--- a/cyberdrop_dl/config/schema.json+++ b/cyberdrop_dl/config/schema.json@@ -339,13 +339,6 @@}]},- "FalsyAsTuple_Annotated_int__Ge__": {- "items": {- "minimum": 0,- "type": "integer"- },- "type": "array"- },"FalsyAsTuple_HttpURL_": {"items": {"$ref": "#/$defs/HttpURL"@@ -623,6 +616,37 @@"title": "Logs","type": "object"},+ "MaxChildren": {+ "additionalProperties": false,+ "properties": {+ "forum": {+ "default": 0,+ "minimum": 0,+ "title": "Forum",+ "type": "integer"+ },+ "forum_post": {+ "default": 0,+ "minimum": 0,+ "title": "Forum Post",+ "type": "integer"+ },+ "profile": {+ "default": 0,+ "minimum": 0,+ "title": "Profile",+ "type": "integer"+ },+ "album": {+ "default": 0,+ "minimum": 0,+ "title": "Album",+ "type": "integer"+ }+ },+ "title": "MaxChildren",+ "type": "object"+ },"Network": {"additionalProperties": false,"properties": {@@ -1002,8 +1026,7 @@"$ref": "#/$defs/Logs"},"max_children": {- "$ref": "#/$defs/FalsyAsTuple_Annotated_int__Ge__",- "default": []+ "$ref": "#/$defs/MaxChildren"},"max_file_name_length": {"default": 95,diff --git a/cyberdrop_dl/config/settings.py b/cyberdrop_dl/config/settings.pyindex 88706651b..76c2fcf38 100644--- a/cyberdrop_dl/config/settings.py+++ b/cyberdrop_dl/config/settings.py@@ -6,7 +6,7 @@ from pathlib import Pathfrom typing import Annotated, ClassVar, Literal, overridefrom cyclopts import Parameter-from pydantic import BaseModel, Field, PrivateAttr+from pydantic import BaseModel, Field, NonNegativeInt, PrivateAttrfrom pydantic.types import ByteSize, NonNegativeFloat, PositiveFloat, PositiveIntfrom cyberdrop_dl.constants import LOGS_DATE_FORMAT, LOGS_DATETIME_FORMAT, CIStrEnum, HashMode@@ -349,3 +349,14 @@ class UIOptions(ConfigGroup):portrait: bool = False"force CDL to run with a vertical layout"refresh_rate: PositiveFloat = 10.0+++class MaxChildren(ConfigGroup, name=None):+ forum: NonNegativeInt = 0+ "Do not scrape more that this number of URLs inside a forum thread"+ forum_post: NonNegativeInt = 0+ "Do not scrape more that this number of URLs inside an individual a forum post"+ profile: NonNegativeInt = 0+ "Do not scrape more that this number of URLs in a profile"+ album: NonNegativeInt = 0+ "Do not scrape more that this number of URLs in a album"diff --git a/cyberdrop_dl/crawlers/gofile.py b/cyberdrop_dl/crawlers/gofile.pyindex 8c9a8f464..649777e92 100644--- a/cyberdrop_dl/crawlers/gofile.py+++ b/cyberdrop_dl/crawlers/gofile.py@@ -260,9 +260,7 @@ def _check_node_is_accessible(node: Node) -> TypeGuard[File | Folder]:def _has_single_not_nested_file(scrape_item: ScrapeItem, folder: Folder) -> bool:return (- folder["childrenCount"] == 1- and folder["name"] == folder["code"]- and scrape_item.type != ScrapeItemType.FILE_HOST_ALBUM+ folder["childrenCount"] == 1 and folder["name"] == folder["code"] and scrape_item.type != ScrapeItemType.ALBUM)diff --git a/cyberdrop_dl/crawlers/toonily.py b/cyberdrop_dl/crawlers/toonily.pyindex 75d08fdde..4bf32f28f 100644--- a/cyberdrop_dl/crawlers/toonily.py+++ b/cyberdrop_dl/crawlers/toonily.py@@ -50,7 +50,7 @@ class ToonilyCrawler(Crawler):*_, series_name, chapter_title = (css.text(bc) for bc in soup.select(Selector.NAV_BREADCUMBS))- if scrape_item.type != ScrapeItemType.FILE_HOST_PROFILE:+ if scrape_item.type != ScrapeItemType.PROFILE:series_title = self.create_title(series_name)scrape_item.append_folders(series_title)diff --git a/cyberdrop_dl/scrape_mapper.py b/cyberdrop_dl/scrape_mapper.pyindex 11a49747d..88825895c 100644--- a/cyberdrop_dl/scrape_mapper.py+++ b/cyberdrop_dl/scrape_mapper.py@@ -16,7 +16,7 @@ from cyberdrop_dl.crawlers import ALLOW_NO_EXT, create_crawlersfrom cyberdrop_dl.exceptions import JDownloaderError, NoExtensionErrorfrom cyberdrop_dl.logs import log_spacerfrom cyberdrop_dl.progress.scraping import ScrapingUI-from cyberdrop_dl.url_objects import AbsoluteHttpURL, ScrapeItem+from cyberdrop_dl.url_objects import AbsoluteHttpURL, ScrapeItem, ScrapeItemTypefrom cyberdrop_dl.utils import remove_trailing_slashif TYPE_CHECKING:@@ -24,6 +24,7 @@ if TYPE_CHECKING:from pathlib import Pathfrom cyberdrop_dl.clients.jdownloader import JDownloader+ from cyberdrop_dl.config import Configfrom cyberdrop_dl.config.crawlers import GenericCrawlersfrom cyberdrop_dl.crawlers.crawler import Crawlerfrom cyberdrop_dl.crawlers.http_direct import DirectHttpFileCrawler@@ -224,9 +225,9 @@ class ScrapeMapper:self.create_download_task(wait_until_scrape_is_done())- children_limits = tuple(self.manager.config.max_children)+ max_children = _build_max_children_map(self.manager.config)async for item in items:- item.children_limits = children_limits+ item.max_children = max_childrenitem.download_folder = self.manager.config.download_folderif self._should_scrape(item):stats.update(item)@@ -516,3 +517,13 @@ def _best_match[T](current_map: dict[str, T], domain: str) -> T | None:else:current_map[domain] = found = current_map[best_match]return found+++def _build_max_children_map(config: Config) -> dict[ScrapeItemType, int]:+ max_children = config.max_children+ return {+ ScrapeItemType.FORUM: max_children.forum,+ ScrapeItemType.FORUM_POST: max_children.forum_post,+ ScrapeItemType.PROFILE: max_children.profile,+ ScrapeItemType.ALBUM: max_children.album,+ }diff --git a/cyberdrop_dl/url_objects.py b/cyberdrop_dl/url_objects.pyindex 5f47db049..f77dd6709 100644--- a/cyberdrop_dl/url_objects.py+++ b/cyberdrop_dl/url_objects.py@@ -18,7 +18,7 @@ from cyberdrop_dl.exceptions import MaxChildrenErrorfrom cyberdrop_dl.filepath import sanitize_folderif TYPE_CHECKING:- from collections.abc import Generator, Iterable, Sequence+ from collections.abc import Generator, Iterable, Mapping, Sequence@finalclass AbsoluteHttpURL(yarl.URL):@@ -113,8 +113,8 @@ def is_absolute_http_url(url: yarl.URL) -> TypeIs[AbsoluteHttpURL]:class ScrapeItemType(IntEnum):FORUM = 0FORUM_POST = 1- FILE_HOST_PROFILE = 2- FILE_HOST_ALBUM = 3+ PROFILE = 2+ ALBUM = 3logger = logging.getLogger(__name__)@@ -199,7 +199,7 @@ class ScrapeItem:folders: list[str] = dataclasses.field(default_factory=list)parents: list[AbsoluteHttpURL] = dataclasses.field(default_factory=list)parent_threads: set[AbsoluteHttpURL] = dataclasses.field(default_factory=set)- children_limits: tuple[int, ...] = dataclasses.field(default_factory=tuple)+ max_children: Mapping[ScrapeItemType, int] | None = Nonepassword: str | None = None_children_count: int = 0@@ -241,11 +241,12 @@ class ScrapeItem:def type(self, item_type: ScrapeItemType | None) -> None:self._type = item_typeself._children_count = self._children_limit = 0- if item_type is None:+ if item_type is None or not self.max_children:return+try:- self._children_limit = self.children_limits[item_type]- except (IndexError, TypeError):+ self._children_limit = self.max_children[item_type]+ except LookupError:pass@property@@ -326,10 +327,10 @@ class ScrapeItem:return self.create_new(url, part_of_album=True, add_parent=True)def setup_as_album(self: ScrapeItem, title: str, *, album_id: str | None = None) -> None:- return self.setup_as(title, ScrapeItemType.FILE_HOST_ALBUM, album_id=album_id)+ return self.setup_as(title, ScrapeItemType.ALBUM, album_id=album_id)def setup_as_profile(self: ScrapeItem, title: str, *, album_id: str | None = None) -> None:- return self.setup_as(title, ScrapeItemType.FILE_HOST_PROFILE, album_id=album_id)+ return self.setup_as(title, ScrapeItemType.PROFILE, album_id=album_id)def setup_as_forum(self: ScrapeItem, title: str, *, album_id: str | None = None) -> None:return self.setup_as(title, ScrapeItemType.FORUM, album_id=album_id)