Skip to content

Bulk asynchronous downloader for multiple file hosts

feat: add flugel-anime support (#1075)

NTFSvolume9a43e500883e
diff --git a/cyberdrop_dl/crawlers/__init__.py b/cyberdrop_dl/crawlers/__init__.py
index 8a95d86a6..48024e41d 100644
--- a/cyberdrop_dl/crawlers/__init__.py
+++ b/cyberdrop_dl/crawlers/__init__.py
@@ -30,6 +30,7 @@ from .fapello import FapelloCrawler
from .fikfap import FikFapCrawler
from .fileditch import FileditchCrawler
from .files_vc import FilesVcCrawler
+from .flugel_anime import FlugelAnimeCrawler
from .fourchan import FourChanCrawler
from .generic import GenericCrawler
from .gofile import GoFileCrawler
diff --git a/cyberdrop_dl/crawlers/_one_manager.py b/cyberdrop_dl/crawlers/_one_manager.py
new file mode 100644
index 000000000..6b53c757e
--- /dev/null
+++ b/cyberdrop_dl/crawlers/_one_manager.py
@@ -0,0 +1,95 @@
+"""An index and manager of Onedrive based on serverless.
+
+Gitlab: https://git.hit.edu.cn/ysun/OneManager-php
+Github: https://github.com/qkqpttgf/OneManager-php
+Gitee: https://gitee.com/qkqpttgf/OneManager-php
+"""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, ClassVar
+
+from cyberdrop_dl.crawlers.crawler import Crawler
+from cyberdrop_dl.exceptions import InvalidContentTypeError
+from cyberdrop_dl.utils import css
+from cyberdrop_dl.utils.utilities import error_handling_wrapper
+
+if TYPE_CHECKING:
+ from bs4 import Tag
+
+ from cyberdrop_dl.crawlers.crawler import SupportedPaths
+ from cyberdrop_dl.data_structures.url_objects import AbsoluteHttpURL, ScrapeItem
+
+
+class Selectors:
+ TABLE = "table#list-table"
+ FILE_LINK = "a.download"
+ FOLDER_LINK = "a[name='folderlist']"
+ FILE = f"tr:has({FILE_LINK})"
+ FOLDER = f"tr:has({FOLDER_LINK})"
+ DATE = "td.updated_at"
+ README = "div#head.markdown-body"
+
+
+_SELECTORS = Selectors()
+
+
+class OneManagerCrawler(Crawler, is_abc=True):
+ SUPPORTED_PATHS: ClassVar[SupportedPaths] = {"Any path": "/..."}
+ SKIP_PRE_CHECK = True
+
+ async def fetch(self, scrape_item: ScrapeItem) -> None:
+ scrape_item.url = scrape_item.url.with_query(None)
+ if self.PRIMARY_URL not in scrape_item.parent_threads:
+ self.init_item(scrape_item)
+ await self.process_path(scrape_item)
+
+ async def async_startup(self) -> None:
+ self.manager.download_manager.download_limits.update({self.DOMAIN: 2})
+
+ @error_handling_wrapper
+ async def process_path(self, scrape_item: ScrapeItem) -> None:
+ try:
+ async with self.request_limiter:
+ soup = await self.client.get_soup(self.DOMAIN, scrape_item.url)
+ except InvalidContentTypeError: # This is a file, not html
+ scrape_item.parent_title = scrape_item.parent_title.rsplit("/", 1)[0]
+ link = scrape_item.url
+ scrape_item.url = link.parent
+ return await self._process_file(scrape_item, link)
+
+ # TODO: save readme as a sidecard
+ if soup.select_one(_SELECTORS.README):
+ pass
+
+ # href are not actual links, they only have the name of the new part
+ table = css.select_one(soup, _SELECTORS.TABLE)
+ for file in css.iselect(table, _SELECTORS.FILE):
+ await self.process_file(scrape_item, file)
+ scrape_item.add_children()
+
+ for folder in css.iselect(table, _SELECTORS.FOLDER):
+ link = scrape_item.url / css.select_one_get_attr(folder, _SELECTORS.FOLDER_LINK, "href")
+ new_scrape_item = scrape_item.create_child(link, new_title_part=link.name)
+ self.manager.task_group.create_task(self.run(new_scrape_item))
+ scrape_item.add_children()
+
+ @error_handling_wrapper
+ async def process_file(self, scrape_item: ScrapeItem, file: Tag) -> None:
+ datetime = self.parse_date(css.select_one_get_text(file, _SELECTORS.DATE))
+ link = scrape_item.url / css.select_one_get_attr(file, _SELECTORS.FILE_LINK, "href")
+ await self._process_file(scrape_item, link, datetime)
+
+ async def _process_file(self, scrape_item: ScrapeItem, link: AbsoluteHttpURL, datetime: int | None = None) -> None:
+ preview_url = link.with_query("preview") # The query param needs to be `?preview` exactly, with no value or `=`
+ new_scrape_item = scrape_item.create_child(preview_url, possible_datetime=datetime)
+ filename, ext = self.get_filename_and_ext(link.name)
+ await self.handle_file(link, new_scrape_item, filename, ext)
+
+ def init_item(self, scrape_item: ScrapeItem) -> None:
+ scrape_item.setup_as_album(self.FOLDER_DOMAIN, album_id=self.DOMAIN)
+ for part in scrape_item.url.parts[1:]:
+ scrape_item.add_to_parent_title(part)
+
+ # smugle url as as sentinel
+ scrape_item.parent_threads.add(self.PRIMARY_URL)
diff --git a/cyberdrop_dl/crawlers/flugel_anime.py b/cyberdrop_dl/crawlers/flugel_anime.py
new file mode 100644
index 000000000..1186ab92a
--- /dev/null
+++ b/cyberdrop_dl/crawlers/flugel_anime.py
@@ -0,0 +1,12 @@
+from __future__ import annotations
+
+from typing import ClassVar
+
+from cyberdrop_dl.crawlers._one_manager import OneManagerCrawler
+from cyberdrop_dl.data_structures.url_objects import AbsoluteHttpURL
+
+
+class FlugelAnimeCrawler(OneManagerCrawler):
+ DOMAIN: ClassVar[str] = "flugel-anime"
+ PRIMARY_URL: ClassVar = AbsoluteHttpURL("https://flugelanime.com")
+ FOLDER_DOMAIN: ClassVar = "Flugel-Anime"
diff --git a/cyberdrop_dl/data_structures/url_objects.py b/cyberdrop_dl/data_structures/url_objects.py
index 866b06c95..0035d8845 100644
--- a/cyberdrop_dl/data_structures/url_objects.py
+++ b/cyberdrop_dl/data_structures/url_objects.py
@@ -6,7 +6,7 @@ from dataclasses import InitVar, dataclass, field
from enum import IntEnum
from functools import partialmethod
from pathlib import Path
-from typing import TYPE_CHECKING, Literal, NamedTuple, ParamSpec, TypeVar, overload
+from typing import TYPE_CHECKING, Literal, NamedTuple, ParamSpec, Self, TypeVar, overload
import yarl
@@ -308,6 +308,6 @@ class ScrapeItem:
if self.parents:
return self.parents[-1]
- def copy(self) -> ScrapeItem:
+ def copy(self) -> Self:
"""Returns a deep copy of this scrape_item"""
return copy.deepcopy(self)