Skip to content

Bulk asynchronous downloader for multiple file hosts

fix: fixed player info parsing (ashemaletube) (#128)

Barbarella666666685fe27be1a03
diff --git a/cyberdrop_dl/crawlers/ashemaletube.py b/cyberdrop_dl/crawlers/ashemaletube.py
index 0b29a8e51..037761f1e 100644
--- a/cyberdrop_dl/crawlers/ashemaletube.py
+++ b/cyberdrop_dl/crawlers/ashemaletube.py
@@ -2,17 +2,18 @@ from __future__ import annotations
import json
from enum import StrEnum
-from typing import TYPE_CHECKING, ClassVar, NamedTuple
+from typing import TYPE_CHECKING, ClassVar
from cyberdrop_dl.crawlers.crawler import Crawler, SupportedPaths
from cyberdrop_dl.data_structures.url_objects import AbsoluteHttpURL
from cyberdrop_dl.exceptions import ScrapeError
-from cyberdrop_dl.utils import css
+from cyberdrop_dl.utils import css, m3u8
from cyberdrop_dl.utils.utilities import error_handling_wrapper, get_text_between
if TYPE_CHECKING:
from bs4 import BeautifulSoup, Tag
+ from cyberdrop_dl.data_structures.mediaprops import Resolution
from cyberdrop_dl.data_structures.url_objects import ScrapeItem
@@ -34,12 +35,6 @@ class Selectors:
_SELECTORS = Selectors()
-class Format(NamedTuple):
- resolution: str
- url: AbsoluteHttpURL
- hls: bool
-
-
class CollectionType(StrEnum):
ALBUM = "album"
MODEL = "model"
@@ -175,12 +170,7 @@ class AShemaleTubeCrawler(Crawler):
if soup.select_one(_SELECTORS.LOGIN_REQUIRED):
raise ScrapeError(401)
js_text = css.select_text(soup, _SELECTORS.JS_PLAYER)
- best_format = parse_player_info(js_text)
- m3u8 = debrid_link = None
- if best_format.hls:
- m3u8 = await self.get_m3u8_from_index_url(best_format.url)
- else:
- debrid_link = best_format.url
+ resolution, url, m3u8 = await self.parse_player_info(js_text)
if video_object := soup.select_one(_SELECTORS.VIDEO_PROPS_JS):
json_data = json.loads(css.text(video_object))
@@ -188,8 +178,8 @@ class AShemaleTubeCrawler(Crawler):
title = css.select_text(soup, "title").split("- aShemaletube.com")[0].strip()
scrape_item.url = canonical_url
- filename, ext = self.get_filename_and_ext(best_format.url.name, assume_ext=".mp4")
- custom_filename = self.create_custom_filename(title, ext, file_id=video_id, resolution=best_format.resolution)
+ filename, ext = self.get_filename_and_ext(url.name, assume_ext=".mp4")
+ custom_filename = self.create_custom_filename(title, ext, file_id=video_id, resolution=resolution)
return await self.handle_file(
canonical_url,
@@ -198,14 +188,13 @@ class AShemaleTubeCrawler(Crawler):
ext,
custom_filename=custom_filename,
m3u8=m3u8,
- debrid_link=debrid_link,
)
+ async def parse_player_info(self, script_text: str) -> tuple[Resolution, AbsoluteHttpURL, m3u8.Rendition]:
+ sources = get_text_between(script_text, "sources: ", "aspectRatio").strip().strip(",")
+ sources_data = json.loads(sources)
+ url = self.parse_url(sources_data["hlsAuto"])
-def parse_player_info(script_text: str) -> Format:
- def get_resolution(video) -> int:
- return int(video["desc"].rstrip("p"))
+ rendition, playlist_info = await self.get_m3u8_from_playlist_url(url)
- sources = get_text_between(script_text, "var sources = ", "var multiSource =").strip().strip(";")
- video_data = max(json.loads(sources), key=get_resolution)
- return Format(video_data["desc"], AbsoluteHttpURL(video_data["src"]), video_data["hls"])
+ return playlist_info.resolution, url, rendition
diff --git a/tests/crawlers/test_cases/ashemaletube.py b/tests/crawlers/test_cases/ashemaletube.py
index 7d8c8f453..b948b75dd 100644
--- a/tests/crawlers/test_cases/ashemaletube.py
+++ b/tests/crawlers/test_cases/ashemaletube.py
@@ -17,7 +17,7 @@ TEST_CASES = [
[
{
"url": "https://cc.ashemaletube.com/images/2025-09/b8/68b658b8f35c3/68b658b8f35c3-full-0.jpg",
- "filename": "68b658b8f35c3-full-0.jpg [11374066].jpg",
+ "filename": "68b658b8f35c3-full-0 [11374066].jpg",
"referer": "https://www.ashemaletube.com/pics/265074/jjk-black-uniform/1",
"album_id": None,
}
diff --git a/tests/crawlers/test_crawlers.py b/tests/crawlers/test_crawlers.py
index 09f72c42e..d3789c5d4 100644
--- a/tests/crawlers/test_crawlers.py
+++ b/tests/crawlers/test_crawlers.py
@@ -101,11 +101,12 @@ async def test_crawler(running_manager: Manager, crawler_test_case: CrawlerTestC
with _crawler_mock() as func:
async with ScrapeMapper(running_manager)() as scrape_mapper:
await scrape_mapper.run()
- crawler = next(
- (crawler for crawler in scrape_mapper._factory if crawler.DOMAIN == test_case.domain),
+ cls = next(
+ (crawler for crawler in scrape_mapper.crawlers.values() if crawler.DOMAIN == test_case.domain),
None,
)
- assert crawler, f"{test_case.domain} is not a valid crawler domain. Test case is invalid"
+ assert cls, f"{test_case.domain} is not a valid crawler domain. Test case is invalid"
+ crawler = cls(running_manager)
await crawler.__async_init__()
item = ScrapeItem(url=crawler.parse_url(test_case.input_url))
await crawler.run(item)