Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: make create children a scrape_item method

NTFSvolumef28437e82198
diff --git a/cyberdrop_dl/crawlers/crawler.py b/cyberdrop_dl/crawlers/crawler.py
index 9b3569ac7..2779066f7 100644
--- a/cyberdrop_dl/crawlers/crawler.py
+++ b/cyberdrop_dl/crawlers/crawler.py
@@ -758,16 +758,14 @@ class Crawler(HTTPMixin, HLSMixin, ABC):
/,
attribute: str = "href",
*,
- results: Mapping[str, bool] | None = None,
- ) -> Generator[tuple[AbsoluteHttpURL | None, ScrapeItem]]:
+ results: Mapping[str, bool] | None = None, # noqa: ARG002
+ ) -> Generator[tuple[None, ScrapeItem]]:
"""Generates tuples with an URL from the `src` value of the first image tag (AKA the thumbnail) and a new scrape item from the value of `attribute`
:param results: must be the output of `self.get_album_results`.
If provided, it will be used as a filter, to only yield items that has not been downloaded before"""
- for thumb, link in self.iter_thumbnails(soup, selector, attribute, results=results):
- new_scrape_item = scrape_item.create_child(link)
- yield thumb, new_scrape_item
- scrape_item.add_children()
+ for new_scrape_item in scrape_item.create_children(self.iter_urls(soup, selector, attribute)):
+ yield None, new_scrape_item
async def web_pager(
self,
diff --git a/cyberdrop_dl/url_objects.py b/cyberdrop_dl/url_objects.py
index e306eee31..68136e625 100644
--- a/cyberdrop_dl/url_objects.py
+++ b/cyberdrop_dl/url_objects.py
@@ -15,7 +15,7 @@ import yarl
from cyberdrop_dl.utils.filepath import sanitize_folder
if TYPE_CHECKING:
- from collections.abc import Generator, Sequence
+ from collections.abc import Generator, Iterable, Sequence
from cyberdrop_dl import signature
from cyberdrop_dl.manager import Manager
@@ -341,6 +341,11 @@ class ScrapeItem:
def setup_as_post(self: ScrapeItem, title: str, *, album_id: str | None = None) -> None:
return self.setup_as(title, FORUM_POST, album_id=album_id)
+ def create_children(self, urls: Iterable[AbsoluteHttpURL]) -> Generator[Self]:
+ for url in urls:
+ yield self.create_child(url)
+ self.add_children()
+
@property
def origin(self) -> AbsoluteHttpURL | None:
if self.parents: