Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Cleanup / add comments
Jules-WinnfieldX11744431a0ae
diff --git a/cyberdrop_dl/scraper/crawlers/bunkr_crawler.py b/cyberdrop_dl/scraper/crawlers/bunkr_crawler.pyindex 0e4bb6c83..d1679036d 100644--- a/cyberdrop_dl/scraper/crawlers/bunkr_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/bunkr_crawler.py@@ -94,6 +94,7 @@ class BunkrCrawler(Crawler):"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""async def get_stream_link(self, url: URL) -> URL:+ """Gets the stream link for a given url"""cdn_possibilities = r"^(?:(?:(?:media-files|cdn|c|pizza|cdn-burger)[0-9]{0,2})|(?:(?:big-taco-|cdn-pizza|cdn-meatballs)[0-9]{0,2}(?:redir)?))\.bunkr?\.[a-z]{2,3}$"if not re.match(cdn_possibilities, url.host):@@ -113,5 +114,6 @@ class BunkrCrawler(Crawler):return urlasync def parse_datetime(self, date: str) -> int:+ """Parses a datetime string into a unix timestamp"""date = datetime.datetime.strptime(date, "%H:%M:%S %d/%m/%Y")return calendar.timegm(date.timetuple())diff --git a/cyberdrop_dl/scraper/crawlers/coomer_crawler.py b/cyberdrop_dl/scraper/crawlers/coomer_crawler.pyindex c03105145..ad6683a94 100644--- a/cyberdrop_dl/scraper/crawlers/coomer_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/coomer_crawler.py@@ -69,6 +69,7 @@ class CoomerCrawler(Crawler):@error_handling_wrapperasync def handle_post_content(self, post: Dict, scrape_item: ScrapeItem, user: str) -> None:+ """Handles the content of a post"""if "#ad" in post['content'] and self.manager.config_manager.settings_data['Ignore_Options']['ignore_coomer_ads']:return@@ -101,11 +102,13 @@ class CoomerCrawler(Crawler):return calendar.timegm(date.timetuple())async def get_service_and_user(self, scrape_item: ScrapeItem) -> Tuple[str, str]:+ """Gets the service and user from a scrape item"""user = scrape_item.url.parts[3]service = scrape_item.url.parts[1]return service, userasync def get_service_user_and_post(self, scrape_item: ScrapeItem) -> Tuple[str, str, str]:+ """Gets the service, user and post id from a scrape item"""user = scrape_item.url.parts[3]service = scrape_item.url.parts[1]post = scrape_item.url.parts[5]@@ -113,6 +116,7 @@ class CoomerCrawler(Crawler):async def create_new_scrape_item(self, link: URL, old_scrape_item: ScrapeItem, user: str, title: str, post_id: str,date: str) -> None:+ """Creates a new scrape item with the same parent as the old scrape item"""post_title = Noneif self.manager.config_manager.settings_data['Download_Options']['separate_posts']:post_title = f"{date} - {title}"diff --git a/cyberdrop_dl/scraper/crawlers/cyberfile_crawler.py b/cyberdrop_dl/scraper/crawlers/cyberfile_crawler.pyindex 143e93045..96cffe48a 100644--- a/cyberdrop_dl/scraper/crawlers/cyberfile_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/cyberfile_crawler.py@@ -133,6 +133,7 @@ class CyberfileCrawler(Crawler):@error_handling_wrapperasync def handle_content_id(self, scrape_item: ScrapeItem, contentId: int) -> None:+ """Scrapes a file using the content id"""data = {"u": contentId}async with self.request_limiter:ajax_dict = await self.client.post_data(self.domain, self.api_details, data=data)@@ -158,5 +159,6 @@ class CyberfileCrawler(Crawler):"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""async def parse_datetime(self, date: str) -> int:+ """Parses a datetime string into a unix timestamp"""date = datetime.datetime.strptime(date, "%d/%m/%Y %H:%M:%S")return calendar.timegm(date.timetuple())diff --git a/cyberdrop_dl/scraper/crawlers/ehentai_crawler.py b/cyberdrop_dl/scraper/crawlers/ehentai_crawler.pyindex 5632727b2..02eeab497 100644--- a/cyberdrop_dl/scraper/crawlers/ehentai_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/ehentai_crawler.py@@ -76,5 +76,6 @@ class EHentaiCrawler(Crawler):"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""async def parse_datetime(self, date: str) -> int:+ """Parses a datetime string into a unix timestamp"""date = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")return calendar.timegm(date.timetuple())diff --git a/cyberdrop_dl/scraper/crawlers/erome_crawler.py b/cyberdrop_dl/scraper/crawlers/erome_crawler.pyindex 92d7e7b18..867d28c1b 100644--- a/cyberdrop_dl/scraper/crawlers/erome_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/erome_crawler.py@@ -63,7 +63,6 @@ class EromeCrawler(Crawler):title = scrape_item.url.nameawait scrape_item.add_to_parent_title(title)- # Imagesimages = soup.select('img[class="img-front lasyload"]')vidoes = soup.select('div[class=media-group] div[class=video-lg] video source')diff --git a/cyberdrop_dl/scraper/crawlers/imgbox_crawler.py b/cyberdrop_dl/scraper/crawlers/imgbox_crawler.pyindex d23b843b0..d964f856c 100644--- a/cyberdrop_dl/scraper/crawlers/imgbox_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/imgbox_crawler.py@@ -69,5 +69,6 @@ class ImgBoxCrawler(Crawler):"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""async def parse_datetime(self, date: str) -> int:+ """Parses a datetime string into a unix timestamp"""date = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")return calendar.timegm(date.timetuple())diff --git a/cyberdrop_dl/scraper/crawlers/imgur_crawler.py b/cyberdrop_dl/scraper/crawlers/imgur_crawler.pyindex abb7b3ee0..78dc6d008 100644--- a/cyberdrop_dl/scraper/crawlers/imgur_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/imgur_crawler.py@@ -65,6 +65,7 @@ class ImgurCrawler(Crawler):@error_handling_wrapperasync def image(self, scrape_item: ScrapeItem) -> None:+ """Scrapes an image"""if self.imgur_client_id == "":await log("To scrape imgur content, you need to provide a client id")raise Exception("No Imgur Client ID provided")@@ -92,6 +93,7 @@ class ImgurCrawler(Crawler):"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""async def check_imgur_credits(self) -> None:+ """Checks the remaining credits"""credits_obj = await self.client.get_json(self.domain, self.imgur_api / "credits", headers_inc=self.headers)self.imgur_client_remaining = credits_obj["data"]["ClientRemaining"]if self.imgur_client_remaining < 100:diff --git a/cyberdrop_dl/scraper/crawlers/kemono_crawler.py b/cyberdrop_dl/scraper/crawlers/kemono_crawler.pyindex 821b5b91f..ebd824f5e 100644--- a/cyberdrop_dl/scraper/crawlers/kemono_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/kemono_crawler.py@@ -2,20 +2,16 @@ from __future__ import annotationsimport calendarimport datetime-from dataclasses import fieldfrom typing import TYPE_CHECKING, Tuple, Dictfrom aiolimiter import AsyncLimiterfrom yarl import URLfrom cyberdrop_dl.scraper.crawler import Crawler-from cyberdrop_dl.utils.dataclasses.url_objects import MediaItem, ScrapeItem-from cyberdrop_dl.utils.utilities import get_filename_and_ext, error_handling_wrapper, log, get_download_path+from cyberdrop_dl.utils.dataclasses.url_objects import ScrapeItem+from cyberdrop_dl.utils.utilities import get_filename_and_ext, error_handling_wrapperif TYPE_CHECKING:- from asyncio import Queue-- from cyberdrop_dl.clients.scraper_client import ScraperClientfrom cyberdrop_dl.managers.manager import Manager@@ -69,7 +65,7 @@ class KemonoCrawler(Crawler):async def discord(self, scrape_item: ScrapeItem) -> None:"""Scrapes a profile"""offset = 0- channel = await self.get_discord_channel(scrape_item)+ channel = scrape_item.url.raw_fragmentapi_call = self.api_url / "discord/channel" / channelwhile True:async with self.request_limiter:@@ -118,27 +114,26 @@ class KemonoCrawler(Crawler):"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""async def parse_datetime(self, date: str) -> int:- """Parses a datetime string"""+ """Parses a datetime string into a unix timestamp"""date = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")return calendar.timegm(date.timetuple())async def get_service_and_user(self, scrape_item: ScrapeItem) -> Tuple[str, str]:+ """Gets the service and user from a scrape item"""user = scrape_item.url.parts[3]service = scrape_item.url.parts[1]return service, userasync def get_service_user_and_post(self, scrape_item: ScrapeItem) -> Tuple[str, str, str]:+ """Gets the service, user and post id from a scrape item"""user = scrape_item.url.parts[3]service = scrape_item.url.parts[1]post = scrape_item.url.parts[5]return service, user, post- async def get_discord_channel(self, scrape_item: ScrapeItem) -> str:- channel = scrape_item.url.raw_fragment- return channel-async def create_new_scrape_item(self, link: URL, old_scrape_item: ScrapeItem, user: str, title: str, post_id: str,date: str) -> None:+ """Creates a new scrape item with the same parent as the old scrape item"""post_title = Noneif self.manager.config_manager.settings_data['Download_Options']['separate_posts']:post_title = f"{date} - {title}"diff --git a/cyberdrop_dl/scraper/crawlers/pimpandhost_crawler.py b/cyberdrop_dl/scraper/crawlers/pimpandhost_crawler.pyindex f8d104ad9..8c0d6f53a 100644--- a/cyberdrop_dl/scraper/crawlers/pimpandhost_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/pimpandhost_crawler.py@@ -78,6 +78,6 @@ class PimpAndHostCrawler(Crawler):"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""async def parse_datetime(self, date: str) -> int:- """Parses a datetime from a string"""+ """Parses a datetime string into a unix timestamp"""date = datetime.strptime(date, '%A, %B %d, %Y %I:%M:%S%p %Z')return calendar.timegm(date.timetuple())diff --git a/cyberdrop_dl/scraper/crawlers/pixeldrain_crawler.py b/cyberdrop_dl/scraper/crawlers/pixeldrain_crawler.pyindex 03689930e..c4ae0f86e 100644--- a/cyberdrop_dl/scraper/crawlers/pixeldrain_crawler.py+++ b/cyberdrop_dl/scraper/crawlers/pixeldrain_crawler.py@@ -64,9 +64,11 @@ class PixelDrainCrawler(Crawler):"""~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""async def parse_datetime(self, date: str) -> int:+ """Parses a datetime string into a unix timestamp"""date = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")return calendar.timegm(date.timetuple())async def create_download_link(self, file_id: str) -> URL:+ """Creates a download link for a file"""link = (self.api_address / "file" / file_id).with_query('download')return linkdiff --git a/cyberdrop_dl/scraper/crawlers/redgifs_crawler.py b/cyberdrop_dl/scraper/crawlers/redgifs_crawler.pynew file mode 100644index 000000000..a80211f49--- /dev/null+++ b/cyberdrop_dl/scraper/crawlers/redgifs_crawler.py@@ -0,0 +1,69 @@+from __future__ import annotations++import calendar+import datetime+from typing import TYPE_CHECKING++from aiolimiter import AsyncLimiter+from yarl import URL++from cyberdrop_dl.scraper.crawler import Crawler+from cyberdrop_dl.utils.dataclasses.url_objects import ScrapeItem+from cyberdrop_dl.utils.utilities import error_handling_wrapper, get_filename_and_ext++if TYPE_CHECKING:+ from cyberdrop_dl.managers.manager import Manager+++class RedGifsCrawler(Crawler):+ def __init__(self, manager: Manager):+ super().__init__(manager, "redgifs", "RedGifs")+ self.redgifs_api = URL("https://api.redgifs.com/")+ self.token = ""+ self.headers = {}+ self.request_limiter = AsyncLimiter(10, 1)++ """~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""++ async def fetch(self, scrape_item: ScrapeItem) -> None:+ """Determines where to send the scrape item based on the url"""+ task_id = await self.scraping_progress.add_task(scrape_item.url)++ if not self.token:+ await self.manage_token()++ if "users" in scrape_item.url.parts:+ await self.user(scrape_item)+ else:+ await self.post(scrape_item)++ await self.scraping_progress.remove_task(task_id)++ @error_handling_wrapper+ async def user(self, scrape_item: ScrapeItem) -> None:+ """Scrapes a users page"""+ print()++ @error_handling_wrapper+ async def post(self, scrape_item: ScrapeItem) -> None:+ """Scrapes a post"""+ print()++ @error_handling_wrapper+ async def media(self, scrape_item: ScrapeItem) -> None:+ """Scrapes a media item"""+ print()++ """~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"""++ async def parse_datetime(self, date: str) -> int:+ """Parses a datetime string into a unix timestamp"""+ date = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")+ return calendar.timegm(date.timetuple())++ async def manage_token(self) -> None:+ """Gets/Sets the redgifs token and header"""+ async with self.request_limiter:+ json_obj = await self.client.get_json(self.redgifs_api / "v2/auth/temporary")+ self.token = json_obj["token"]+ self.headers = {"Authorization": f"Bearer {self.token}"}