Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: remove generic crawler (#16)
NTFSvolume805d96edf8c3
diff --git a/README.md b/README.mdindex a5c09eef8..67cf0935e 100644--- a/README.md+++ b/README.md@@ -4,13 +4,13 @@Bulk asynchronous downloader for multiple file hosts-[](https://github.com/NTFSvolume/cdl/blob/master/LICENSE)+[](https://github.com/NTFSvolume/cdl/blob/main/LICENSE)[](https://github.com/NTFSvolume/cdl/actions/workflows/ruff.yaml)[](https://github.com/NTFSvolume/cdl/actions/workflows/ci.yaml)Brand new and improved! Cyberdrop-DL now has an updated paint job, fantastic new look. It's now easier to use than ever before!-+</div>diff --git a/cyberdrop_dl/config/global_model.py b/cyberdrop_dl/config/global_model.pyindex 2a5aaac87..4fc30a619 100755--- a/cyberdrop_dl/config/global_model.py+++ b/cyberdrop_dl/config/global_model.py@@ -26,7 +26,6 @@ class General(BaseModel):# TODO: Move `ssl_context` to an advance config sectionssl_context: Literal["truststore", "certifi", "truststore+certifi"] | None = "truststore+certifi"disable_crawlers: ListNonEmptyStr = []- enable_generic_crawler: bool = Falseflaresolverr: HttpURL | None = Nonemax_file_name_length: PositiveInt = 95max_folder_name_length: PositiveInt = 60diff --git a/cyberdrop_dl/crawlers/__init__.py b/cyberdrop_dl/crawlers/__init__.pyindex a75828b4e..3839a0139 100644--- a/cyberdrop_dl/crawlers/__init__.py+++ b/cyberdrop_dl/crawlers/__init__.py@@ -43,7 +43,6 @@ from .fourchan import FourChanCrawlerfrom .fsiblog import FSIBlogCrawlerfrom .fucking_fast import FuckingFastCrawlerfrom .fuxxx import FuXXXCrawler-from .generic import GenericCrawlerfrom .girlsreleased import GirlsReleasedCrawlerfrom .gofile import GoFileCrawlerfrom .google_drive import GoogleDriveCrawler@@ -164,5 +163,5 @@ ALL_CRAWLERS: set[type[Crawler]] = {ALL_CRAWLERS.update(WP_CRAWLERS, GENERIC_CRAWLERS, FORUM_CRAWLERS)DEBUG_CRAWLERS = {SimpCityCrawler, TwitterCrawler}CRAWLERS = ALL_CRAWLERS-WEBSITE_CRAWLERS = CRAWLERS - FORUM_CRAWLERS - {GenericCrawler}+WEBSITE_CRAWLERS = CRAWLERS - FORUM_CRAWLERS__all__ = ["ALL_CRAWLERS", "CRAWLERS", "DEBUG_CRAWLERS", "FORUM_CRAWLERS", "Crawler"]diff --git a/cyberdrop_dl/crawlers/crawler.py b/cyberdrop_dl/crawlers/crawler.pyindex 122262e34..9a62316c0 100644--- a/cyberdrop_dl/crawlers/crawler.py+++ b/cyberdrop_dl/crawlers/crawler.py@@ -227,7 +227,6 @@ class Crawler(ABC):assert cls.__init__ is Crawler.__init__, msgcls.NAME = cls.__name__.removesuffix("Crawler")cls.IS_GENERIC = is_generic- cls.IS_FALLBACK_GENERIC = cls.NAME == "Generic"cls.IS_REAL_DEBRID = cls.NAME == "RealDebrid"cls.SUPPORTED_PATHS = _sort_supported_paths(cls.SUPPORTED_PATHS)cls.IS_ABC = is_abc@@ -241,7 +240,7 @@ class Crawler(ABC):if is_abc:return- if not (cls.IS_FALLBACK_GENERIC or cls.IS_REAL_DEBRID):+ if not cls.IS_REAL_DEBRID:Crawler._assert_fields_overrides(cls, "PRIMARY_URL", "DOMAIN", "SUPPORTED_PATHS")if cls.OLD_DOMAINS:@@ -367,12 +366,7 @@ class Crawler(ABC):@contextlib.contextmanagerdef new_task_id(self, url: AbsoluteHttpURL) -> Generator[TaskID]:"""Creates a new task_id (shows the URL in the UI and logs)"""- scrape_prefix = "Scraping"- if self.IS_FALLBACK_GENERIC:- scrape_prefix += " (unsupported domain)"- else:- scrape_prefix += f" [{self.FOLDER_DOMAIN}]"- log(f"{scrape_prefix}: {url}", 20)+ log(f"Scraping [{self.FOLDER_DOMAIN}]: {url}", 20)task_id = self.manager.progress_manager.scraping_progress.add_task(url)try:yield task_iddiff --git a/cyberdrop_dl/crawlers/generic.py b/cyberdrop_dl/crawlers/generic.pydeleted file mode 100644index 6f6d76e78..000000000--- a/cyberdrop_dl/crawlers/generic.py+++ /dev/null@@ -1,133 +0,0 @@-from __future__ import annotations--import mimetypes-from dataclasses import dataclass-from functools import wraps-from pathlib import Path-from typing import TYPE_CHECKING, ClassVar, ParamSpec, TypeVar--from cyberdrop_dl.crawlers.crawler import Crawler-from cyberdrop_dl.exceptions import InvalidContentTypeError, NoExtensionError, ScrapeError-from cyberdrop_dl.utils import css-from cyberdrop_dl.utils.logger import log-from cyberdrop_dl.utils.utilities import error_handling_wrapper, get_filename_and_ext--if TYPE_CHECKING:- from collections.abc import Callable, Coroutine-- from bs4 import BeautifulSoup-- from cyberdrop_dl.data_structures.url_objects import AbsoluteHttpURL, ScrapeItem---P = ParamSpec("P")-R = TypeVar("R")--VIDEO_SELECTOR = "video > source"---def log_unsupported_wrapper(- func: Callable[P, Coroutine[None, None, R]],-) -> Callable[P, Coroutine[None, None, R | None]]:- @wraps(func)- async def wrapper(*args, **kwargs) -> R | None:- self: GenericCrawler = args[0]- item: ScrapeItem = args[1]- try:- return await func(*args, **kwargs)- except (InvalidContentTypeError, ScrapeError) as e:- await self.log_unsupported(item, f"({e})")- except Exception:- raise-- return wrapper---@dataclass(frozen=True, slots=True)-class FakeURL:- host: str- scheme: str = "https"- path: str = "/"- query: str = ""- fragment: str = ""---class GenericCrawler(Crawler):- DOMAIN: ClassVar[str] = "generic"- PRIMARY_URL: ClassVar[AbsoluteHttpURL] = FakeURL(host=".") # type: ignore-- async def fetch(self, scrape_item: ScrapeItem) -> None:- await self.file(scrape_item)-- @error_handling_wrapper- @log_unsupported_wrapper- async def file(self, scrape_item: ScrapeItem) -> None:- async with self.request(scrape_item.url) as resp:- content_type = resp.content_type- if "html" in content_type:- return await self.try_video_from_soup(scrape_item, await resp.soup())-- filename, ext = guess_filename_and_ext(scrape_item.url, content_type)- if not ext:- msg = f"Received '{content_type}', was expecting other"- raise InvalidContentTypeError(message=msg)-- fullname = Path(filename).with_suffix(ext)- filename, _ = self.get_filename_and_ext(fullname.name)- await self.handle_file(scrape_item.url, scrape_item, filename, ext)-- async def try_video_from_soup(self, scrape_item: ScrapeItem, soup: BeautifulSoup) -> None:- try:- title = css.select_text(soup, "title").rsplit(" - ", 1)[0].rsplit("|", 1)[0]- link_str: str = css.select(soup, VIDEO_SELECTOR, "src")- except (AssertionError, AttributeError, KeyError):- raise ScrapeError(422) from None-- link = self.parse_url(link_str, scrape_item.url.with_path("/"))- try:- filename, ext = self.get_filename_and_ext(link.name)- except NoExtensionError:- filename, ext = self.get_filename_and_ext(link.name + ".mp4")- custom_filename = self.create_custom_filename(title, ext)- await self.handle_file(link, scrape_item, filename, ext, custom_filename=custom_filename)-- async def log_unsupported(self, scrape_item: ScrapeItem, msg: str = "") -> None:- log(f"Unsupported URL: {scrape_item.url} {msg}", 30)- self.manager.log_manager.write_unsupported_urls_log(scrape_item.url, scrape_item.origin)- self.manager.progress_manager.scrape_stats_progress.add_unsupported()---def guess_filename_and_ext(url: AbsoluteHttpURL, content_type: str) -> tuple[str, str | None]:- filename, ext = get_name_and_ext_from_url(url)- if filename and ext:- return filename, ext- return url.name, get_ext_from_content_type(content_type)---def get_ext_from_content_type(content_type: str) -> str | None:- return mimetypes.guess_extension(content_type) or CONTENT_TYPE_TO_EXTENSION.get(content_type)---def get_name_and_ext_from_url(url: AbsoluteHttpURL) -> tuple[str, str | None]:- try:- return get_filename_and_ext(url.name)- except NoExtensionError:- return url.name, None---CONTENT_TYPE_TO_EXTENSION = {- "image/jpeg": ".jpg",- "image/jpg": ".jpg",- "image/png": ".png",- "image/gif": ".gif",- "image/webp": ".webp",- "application/pdf": ".pdf",- "audio/mpeg": ".mp3",- "audio/wav": ".wav",- "video/mp4": ".mp4",- "video/webm": ".webm",- "application/zip": ".zip",- "application/gzip": ".gz",- "application/x-tar": ".tar",- "image/svg+xml": ".svg",-}diff --git a/cyberdrop_dl/scraper/scrape_mapper.py b/cyberdrop_dl/scraper/scrape_mapper.pyindex 04da00b1e..594817cb7 100644--- a/cyberdrop_dl/scraper/scrape_mapper.py+++ b/cyberdrop_dl/scraper/scrape_mapper.py@@ -14,7 +14,6 @@ from cyberdrop_dl.constants import REGEX_LINKS, BlockedDomainsfrom cyberdrop_dl.crawlers._chevereto import CheveretoCrawlerfrom cyberdrop_dl.crawlers.crawler import Crawler, create_crawlersfrom cyberdrop_dl.crawlers.discourse import DiscourseCrawler-from cyberdrop_dl.crawlers.generic import GenericCrawlerfrom cyberdrop_dl.crawlers.http_direct import DirectHttpFilefrom cyberdrop_dl.crawlers.realdebrid import RealDebridCrawlerfrom cyberdrop_dl.crawlers.wordpress import WordPressHTMLCrawler, WordPressMediaCrawler@@ -51,7 +50,6 @@ class ScrapeMapper:self.using_input_file = Falseself.groups = set()self.count = 0- self.fallback_generic: GenericCrawlerself.real_debrid: RealDebridCrawler"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""@@ -73,7 +71,6 @@ class ScrapeMapper:from cyberdrop_dl import pluginsself.existing_crawlers = get_crawlers_mapping(self.manager)- self.fallback_generic = GenericCrawler(self.manager)generic_crawlers = create_generic_crawlers_by_config(self.global_settings.generic_crawlers_instances)for crawler in generic_crawlers:register_crawler(self.existing_crawlers, crawler(self.manager), from_user=True)@@ -257,12 +254,6 @@ class ScrapeMapper:self.manager.progress_manager.scrape_stats_progress.add_unsupported(sent_to_jdownloader=success)return- if self.enable_generic_crawler:- if not self.fallback_generic.ready:- await self.fallback_generic.startup()- self.manager.task_group.create_task(self.fallback_generic.run(scrape_item))- return-log(f"Unsupported URL: {scrape_item.url}", 30)self.manager.log_manager.write_unsupported_urls_log(scrape_item.url,@@ -382,8 +373,6 @@ def register_crawler(include_generics: bool = False,from_user: bool | Literal["raise"] = False,) -> None:- if crawler.IS_FALLBACK_GENERIC:- returnif crawler.IS_GENERIC and include_generics:keys = (crawler.GENERIC_NAME,)else:diff --git a/cyberdrop_dl/utils/markdown.py b/cyberdrop_dl/utils/markdown.pyindex 7bc04f435..7abb69603 100644--- a/cyberdrop_dl/utils/markdown.py+++ b/cyberdrop_dl/utils/markdown.py@@ -58,7 +58,7 @@ def _get_crawlers_info_cols_and_rows() -> tuple[list[str], Generator[tuple[str,def _gen_crawlers_info_rows(crawlers: Sequence[Crawler]) -> Generator[tuple[str, ...]]:- info_gen = (crawler.INFO for crawler in crawlers if not crawler.IS_FALLBACK_GENERIC)+ info_gen = (crawler.INFO for crawler in crawlers)for info in sorted(info_gen, key=lambda x: x.site.casefold()):yield _get_row_values(info)diff --git a/pyproject.toml b/pyproject.tomlindex 8154b06e3..fa2fbac93 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -49,9 +49,8 @@ cyberdrop-dl = "cyberdrop_dl.main:main"cyberdrop-dl-patched = "cyberdrop_dl.main:main"[project.urls]-Changelog = "https://github.com/jbsparrow/CyberDropDownloader/blob/master/CHANGELOG.md"-Documentation = "https://script-ware.gitbook.io/cyberdrop-dl/"-Repository = "https://github.com/jbsparrow/CyberDropDownloader"+Changelog = "https://github.com/NTFSvolume/cdl/blob/main/CHANGELOG.md"+Repository = "https://github.com/NTFSvolume/cdl"[build-system]build-backend = "uv_build"