Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
feat: add yurivan support (#1913)
NTFSvolume70897b497dbd
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5fc64d500..8533e90b4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Soundgasm support- Clyp.it support- Livestreamfails support+- Yurivan support- Fatbox proxy support (Catbox)### Changeddiff --git a/cyberdrop_dl/crawlers/yurivan.py b/cyberdrop_dl/crawlers/yurivan.pynew file mode 100644index 000000000..d746a9b7c--- /dev/null+++ b/cyberdrop_dl/crawlers/yurivan.py@@ -0,0 +1,114 @@+from __future__ import annotations++from typing import TYPE_CHECKING, Any, ClassVar++from pydantic import dataclasses++from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths+from cyberdrop_dl.exceptions import ScrapeError+from cyberdrop_dl.url_objects import AbsoluteHttpURL+from cyberdrop_dl.utils import css, deserialize, error_handling_wrapper, next_js++if TYPE_CHECKING:+ from bs4 import BeautifulSoup++ from cyberdrop_dl.url_objects import ScrapeItem+++class YuriVanCrawler(Crawler):+ SUPPORTED_PATHS: ClassVar[SupportedPaths] = {+ "Chapter": "/story/<story_id>/read?chapter<chapter_id>",+ "Video": "/story/<story_id>/chapter/1",+ "Story": "/story/<story_id>",+ }+ DOMAIN: ClassVar[str] = "yurivan"+ PRIMARY_URL: ClassVar[AbsoluteHttpURL] = AbsoluteHttpURL("https://www.yurivan.com")++ async def __async_post_init__(self) -> None:+ self.update_cookies({"age_verified": "remember", "yh_sfs": "same-origin"})++ async def fetch(self, scrape_item: ScrapeItem) -> None:+ match scrape_item.url.parts[1:]:+ case ["story", story_id, "read"] if chapter := scrape_item.url.query.get("chapter"):+ return await self.chapter(scrape_item, story_id, int(chapter))+ case ["story", story_id, *_]:+ return await self.story(scrape_item, story_id)+ case _:+ raise ValueError++ @error_handling_wrapper+ async def story(self, scrape_item: ScrapeItem, story_id: str) -> None:+ soup = await self.request_soup(scrape_item.url)+ try:+ video_props = css.json_ld(soup, "VideoObject")+ except css.SelectorError:+ scrape_item.setup_as_album("")+ self._chapters(scrape_item, story_id, soup)+ else:+ await self._video(scrape_item, video_props)++ def _chapters(self, scrape_item: ScrapeItem, story_id: str, soup: BeautifulSoup):+ selector = f"a[href*='/story/{story_id}/read?chapter=']"+ for _, new_item in self.iter_children(scrape_item, soup, selector):+ self.create_task(self.run(new_item))+ scrape_item.add_children()++ async def _video(self, scrape_item: ScrapeItem, props: dict[str, Any]) -> None:+ scrape_item.uploaded_at = self.parse_iso_date(props["uploadDate"])+ thumb = self.parse_url(props["thumbnailUrl"])+ m3u8_url = thumb.with_name("playlist.m3u8")+ name: str = props["name"]+ m3u8, info = await self.request_m3u8_playlist(m3u8_url)+ filename = self.create_custom_filename(+ name,+ ext := ".mp4",+ resolution=info.resolution,+ video_codec=info.codecs.video,+ audio_codec=info.codecs.audio,+ )+ await self.handle_file(m3u8_url, scrape_item, name, ext, m3u8=m3u8, custom_filename=filename)++ @error_handling_wrapper+ async def chapter(self, scrape_item: ScrapeItem, story_id: str, chapter_id: int) -> None:+ chapter_idx = chapter_id - 1+ soup = await self.request_soup(scrape_item.url)+ story = _extract_story(soup, chapter_idx)+ title = self.create_title(story.storyTitle, story_id)+ scrape_item.setup_as_album(title, album_id=story_id)++ chapter = story.chapters[chapter_idx]+ scrape_item.add_to_parent_title(self.create_title(chapter.title))+ async with self.new_task_group(scrape_item) as tg:+ for page in chapter.pages:+ tg.create_task(self.direct_file(scrape_item, page.url))+ scrape_item.add_children()++[email protected](slots=True)+class Story:+ storyId: str # noqa: N815+ storyTitle: str # noqa: N815+ chapters: tuple[Chapter, ...]++[email protected](slots=True)+class Chapter:+ chapter_index: int+ title: str+ cover_url: str+ pages: tuple[Page, ...] = ()++[email protected](slots=True)+class Page:+ url: AbsoluteHttpURL+ bytes: int+++def _extract_story(soup: BeautifulSoup, chapter_index: int) -> Story:+ next_data = next_js.extract(soup)+ for s in next_js.ifind(next_data, "storyId", "storyTitle", "chapters"):+ story = deserialize(Story, s)+ if len(story.chapters) > chapter_index and story.chapters[chapter_index].pages:+ return story+ raise ScrapeError(422, "Unable to extract story info")diff --git a/tests/crawlers/test_cases/yurivan.py b/tests/crawlers/test_cases/yurivan.pynew file mode 100644index 000000000..7898a3786--- /dev/null+++ b/tests/crawlers/test_cases/yurivan.py@@ -0,0 +1,181 @@+DOMAIN = "yurivan"+TEST_CASES = [+ {+ "url": "https://www.yurivan.com/story/32cbf138-f76d-447f-86f2-352977b461e2/chapter/1",+ "results": [+ {+ "url": "re:/d616da37-4b88-4bdf-9106-697df8195393/playlist.m3u8",+ "filename": "Leatherman 4 — Episode 4 [hevc][mp4a][1080p].mp4",+ "debrid_link": None,+ "original_filename": "Leatherman 4 — Episode 4",+ "referer": "https://www.yurivan.com/story/32cbf138-f76d-447f-86f2-352977b461e2/chapter/1",+ "album_id": None,+ "uploaded_at": 1778058102,+ "download_folder": "re:Loose Files (Yurivan)",+ }+ ],+ "count": 1,+ },+ {+ "url": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=1",+ "results": [+ {+ "url": "https://img.yurivan.com/published/seed/cddf94f2-2c83-4ae4-8bfe-4622f1c4feb5/0.jpg",+ "filename": "0.jpg",+ "debrid_link": None,+ "original_filename": "0.jpg",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=1",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 1",+ },+ {+ "url": "https://img.yurivan.com/published/seed/cddf94f2-2c83-4ae4-8bfe-4622f1c4feb5/1.jpg",+ "filename": "1.jpg",+ "debrid_link": None,+ "original_filename": "1.jpg",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=1",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 1",+ },+ {+ "url": "https://img.yurivan.com/published/seed/cddf94f2-2c83-4ae4-8bfe-4622f1c4feb5/2.jpg",+ "filename": "2.jpg",+ "debrid_link": None,+ "original_filename": "2.jpg",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=1",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 1",+ },+ {+ "url": "https://img.yurivan.com/published/seed/cddf94f2-2c83-4ae4-8bfe-4622f1c4feb5/3.jpg",+ "filename": "3.jpg",+ "debrid_link": None,+ "original_filename": "3.jpg",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=1",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 1",+ },+ {+ "url": "https://img.yurivan.com/published/seed/cddf94f2-2c83-4ae4-8bfe-4622f1c4feb5/4.jpg",+ "filename": "4.jpg",+ "debrid_link": None,+ "original_filename": "4.jpg",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=1",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 1",+ },+ {+ "url": "https://img.yurivan.com/published/seed/cddf94f2-2c83-4ae4-8bfe-4622f1c4feb5/5.jpg",+ "filename": "5.jpg",+ "debrid_link": None,+ "original_filename": "5.jpg",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=1",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 1",+ },+ ],+ "count": 6,+ },+ {+ "url": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=3",+ "results": [+ {+ "url": "https://img.yurivan.com/published/seed/7ea3a059-2cdf-4866-9593-3357831ba644/0.webp",+ "filename": "0.webp",+ "debrid_link": None,+ "original_filename": "0.webp",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=3",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 3",+ },+ {+ "url": "https://img.yurivan.com/published/seed/7ea3a059-2cdf-4866-9593-3357831ba644/1.webp",+ "filename": "1.webp",+ "debrid_link": None,+ "original_filename": "1.webp",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=3",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 3",+ },+ {+ "url": "https://img.yurivan.com/published/seed/7ea3a059-2cdf-4866-9593-3357831ba644/2.jpg",+ "filename": "2.jpg",+ "debrid_link": None,+ "original_filename": "2.jpg",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=3",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 3",+ },+ {+ "url": "https://img.yurivan.com/published/seed/7ea3a059-2cdf-4866-9593-3357831ba644/3.jpg",+ "filename": "3.jpg",+ "debrid_link": None,+ "original_filename": "3.jpg",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=3",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 3",+ },+ {+ "url": "https://img.yurivan.com/published/seed/7ea3a059-2cdf-4866-9593-3357831ba644/4.jpg",+ "filename": "4.jpg",+ "debrid_link": None,+ "original_filename": "4.jpg",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=3",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 3",+ },+ {+ "url": "https://img.yurivan.com/published/seed/7ea3a059-2cdf-4866-9593-3357831ba644/5.webp",+ "filename": "5.webp",+ "debrid_link": None,+ "original_filename": "5.webp",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=3",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 3",+ },+ {+ "url": "https://img.yurivan.com/published/seed/7ea3a059-2cdf-4866-9593-3357831ba644/6.jpg",+ "filename": "6.jpg",+ "debrid_link": None,+ "original_filename": "6.jpg",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=3",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 3",+ },+ {+ "url": "https://img.yurivan.com/published/seed/7ea3a059-2cdf-4866-9593-3357831ba644/7.jpg",+ "filename": "7.jpg",+ "debrid_link": None,+ "original_filename": "7.jpg",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=3",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 3",+ },+ {+ "url": "https://img.yurivan.com/published/seed/7ea3a059-2cdf-4866-9593-3357831ba644/8.webp",+ "filename": "8.webp",+ "debrid_link": None,+ "original_filename": "8.webp",+ "referer": "https://www.yurivan.com/story/e5a3eecf-a920-44e9-80da-b09ace8aafb8/read?chapter=3",+ "album_id": "e5a3eecf-a920-44e9-80da-b09ace8aafb8",+ "uploaded_at": None,+ "download_folder": "re:Traditional Erotic Fairy Tale (Yurivan)/Chapter 3",+ },+ ],+ "count": 9,+ },+]