Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Fix Event Loop Closed & Implement Output Last Post
Jules-WinnfieldX9a195ef264c5
diff --git a/cyberdrop_dl/base_functions/base_functions.py b/cyberdrop_dl/base_functions/base_functions.pyindex 07d821597..31d1e1481 100644--- a/cyberdrop_dl/base_functions/base_functions.py+++ b/cyberdrop_dl/base_functions/base_functions.py@@ -1,6 +1,8 @@+import aiofilesimport loggingimport osimport re+from pathlib import Pathfrom colorama import Fore, Stylefrom yarl import URL@@ -84,6 +86,12 @@ async def cyberdrop_parse(url: URL) -> URL:return URL(url)+async def write_last_post_file(file: Path, url: str):+ async with aiofiles.open(file, mode='a') as f:+ await f.write(url + '\n')+ return++async def check_direct(url: URL):mapping_direct = ['i.pixl.is', r's..putmega.com', r's..putme.ga', r'img-...cyberdrop...', r'f.cyberdrop...',r'fs-...cyberdrop...', r'cdn.bunkr...', r'cdn..bunkr...', r'media-files.bunkr...', r'jpg.church/images/...',diff --git a/cyberdrop_dl/crawlers/SimpCity_Spider.py b/cyberdrop_dl/crawlers/SimpCity_Spider.pyindex 5faa79ff5..e7038bdab 100644--- a/cyberdrop_dl/crawlers/SimpCity_Spider.py+++ b/cyberdrop_dl/crawlers/SimpCity_Spider.py@@ -4,15 +4,16 @@ import refrom bs4 import BeautifulSoupfrom yarl import URL-from ..base_functions.base_functions import log, logger, make_title_safe+from ..base_functions.base_functions import log, logger, make_title_safe, write_last_post_filefrom ..base_functions.data_classes import AuthData, CascadeItemfrom ..client.client import Sessionclass SimpCityCrawler:- def __init__(self, *, include_id=False, auth: AuthData = None, scraping_mapper, separate_posts=False):+ def __init__(self, *, include_id=False, auth: AuthData = None, scraping_mapper, separate_posts=False, output_last=[False, None]):self.include_id = include_idself.separate_posts = separate_posts+ self.output_last = output_lastself.username, self.password = (auth.username, auth.password) if auth else (None, None)self.scraping_mapper = scraping_mapperself.lock = 0@@ -203,6 +204,14 @@ class SimpCityCrawler:next_page = domain / next_page[1:]next_page = URL(next_page)title = await self.parse_thread(session, next_page, cascade, title)++ if self.output_last[0]:+ if 'post-' in url.raw_name:+ last_post_url = url.parent / post_num_str+ else:+ last_post_url = url / post_num_str+ await write_last_post_file(self.output_last[1], str(last_post_url))+returnexcept Exception as e:diff --git a/cyberdrop_dl/crawlers/SocialMediaGirls_Spider.py b/cyberdrop_dl/crawlers/SocialMediaGirls_Spider.pyindex 16fd6a08c..3668ecfdb 100644--- a/cyberdrop_dl/crawlers/SocialMediaGirls_Spider.py+++ b/cyberdrop_dl/crawlers/SocialMediaGirls_Spider.py@@ -4,15 +4,16 @@ import refrom bs4 import BeautifulSoupfrom yarl import URL-from ..base_functions.base_functions import log, logger, make_title_safe+from ..base_functions.base_functions import log, logger, make_title_safe, write_last_post_filefrom ..base_functions.data_classes import AuthData, CascadeItemfrom ..client.client import Sessionclass SocialMediaGirlsCrawler:- def __init__(self, *, include_id=False, auth: AuthData = None, scraping_mapper, separate_posts=False):+ def __init__(self, *, include_id=False, auth: AuthData = None, scraping_mapper, separate_posts=False, output_last=[False, None]):self.include_id = include_idself.separate_posts = separate_posts+ self.output_last = output_lastself.username, self.password = (auth.username, auth.password) if auth else (None, None)self.scraping_mapper = scraping_mapperself.lock = 0@@ -203,6 +204,14 @@ class SocialMediaGirlsCrawler:next_page = domain / next_page[1:]next_page = URL(next_page)title = await self.parse_thread(session, next_page, cascade, title)++ if self.output_last[0]:+ if 'post-' in url.raw_name:+ last_post_url = url.parent / post_num_str+ else:+ last_post_url = url / post_num_str+ await write_last_post_file(self.output_last[1], str(last_post_url))+returnexcept Exception as e:diff --git a/cyberdrop_dl/crawlers/XBunker_Spider.py b/cyberdrop_dl/crawlers/XBunker_Spider.pyindex 47766544d..a998023a9 100644--- a/cyberdrop_dl/crawlers/XBunker_Spider.py+++ b/cyberdrop_dl/crawlers/XBunker_Spider.py@@ -4,15 +4,16 @@ import refrom bs4 import BeautifulSoupfrom yarl import URL-from ..base_functions.base_functions import log, logger, make_title_safe+from ..base_functions.base_functions import log, logger, make_title_safe, write_last_post_filefrom ..base_functions.data_classes import AuthData, CascadeItemfrom ..client.client import Sessionclass XBunkerCrawler:- def __init__(self, *, include_id=False, auth: AuthData = None, scraping_mapper, separate_posts=False):+ def __init__(self, *, include_id=False, auth: AuthData = None, scraping_mapper, separate_posts=False, output_last=[False, None]):self.include_id = include_idself.separate_posts = separate_posts+ self.output_last = output_lastself.username, self.password = (auth.username, auth.password) if auth else (None, None)self.scraping_mapper = scraping_mapperself.lock = 0@@ -199,6 +200,14 @@ class XBunkerCrawler:next_page = domain / next_page[1:]next_page = URL(next_page)title = await self.parse_thread(session, next_page, cascade, title)++ if self.output_last[0]:+ if 'post-' in url.raw_name:+ last_post_url = url.parent / post_num_str+ else:+ last_post_url = url / post_num_str+ await write_last_post_file(self.output_last[1], str(last_post_url))+returnexcept Exception as e:diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex 7a0fef53c..56d9072e9 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -1,10 +1,12 @@import argparseimport multiprocessing+import platformfrom argparse import Namespaceimport asyncioimport logging+from asyncio.proactor_events import _ProactorBasePipeTransportfrom pathlib import Path-import sys+from functools import wrapsfrom colorama import Forefrom yarl import URL@@ -35,6 +37,7 @@ def parse_args():parser.add_argument("--exclude-audio", help="skip downloading of audio files", action="store_true")parser.add_argument("--exclude-other", help="skip downloading of images", action="store_true")parser.add_argument("--ignore-history", help="This ignores previous download history", action="store_true")+ parser.add_argument("--output-last-forum-post", help="Separates forum scraping into folders by post number", action="store_true")parser.add_argument("--separate-posts", help="Separates forum scraping into folders by post number", action="store_true")parser.add_argument("--xbunker-username", type=str, help="username to login to xbunker", default=None)parser.add_argument("--xbunker-password", type=str, help="password to login to xbunker", default=None)@@ -82,6 +85,14 @@ async def download_all(args: argparse.Namespace):await log("No links found, check the URL.txt\nIf the link works in your web browser, ""please open an issue ticket with me.", Fore.RED)+ output_url_file = None++ if args.output_last_forum_post:+ output_url_file: Path = input_file.parent / "URLs_last_post.txt"+ if output_url_file.exists():+ output_url_file.unlink()+ output_url_file.touch()+xbunker_auth = AuthData(args.xbunker_username, args.xbunker_password)socialmediagirls_auth = AuthData(args.socialmediagirls_username, args.socialmediagirls_password)simpcity_auth = AuthData(args.simpcity_username, args.simpcity_password)@@ -89,7 +100,7 @@ async def download_all(args: argparse.Namespace):excludes = {'videos': args.exclude_videos, 'images': args.exclude_images, 'audio': args.exclude_audio,'other': args.exclude_other}content_object = await scrape(links, client, args.include_id, xbunker_auth, socialmediagirls_auth,- simpcity_auth, args.separate_posts, skip_data)+ simpcity_auth, args.separate_posts, skip_data, [args.output_last_forum_post, output_url_file])if await content_object.is_empty():logging.error('ValueError No links')@@ -116,6 +127,17 @@ async def download_all(args: argparse.Namespace):await log('There are still partial downloads in your folders, please re-run the program.')+def silence_event_loop_closed(func):+ @wraps(func)+ def wrapper(self, *args, **kwargs):+ try:+ return func(self, *args, **kwargs)+ except RuntimeError as e:+ if str(e) != 'Event loop is closed':+ raise+ return wrapper++def main(args=None):if not args:args = parse_args()@@ -126,6 +148,10 @@ def main(args=None):filemode="w")+ if platform.system() == 'Windows':+ # Silence the "Event loop is closed" exception here.+ _ProactorBasePipeTransport.__del__ = silence_event_loop_closed(_ProactorBasePipeTransport.__del__)+loop = asyncio.get_event_loop()loop.run_until_complete(download_all(args))loop.run_until_complete(asyncio.sleep(1))diff --git a/cyberdrop_dl/scraper/scraper.py b/cyberdrop_dl/scraper/scraper.pyindex daad78048..3d301cf55 100644--- a/cyberdrop_dl/scraper/scraper.py+++ b/cyberdrop_dl/scraper/scraper.py@@ -7,12 +7,12 @@ from ..client.client import Clientasync def scrape(urls, client: Client, include_id: bool, xbunker_auth: AuthData, socialmediagirls_auth: AuthData,- simpcity_auth: AuthData, separate_posts: bool, skip_data: SkipData):+ simpcity_auth: AuthData, separate_posts: bool, skip_data: SkipData, output_last: list):await log("Starting Scrape")scraper = ScrapeMapper(client=client, include_id=include_id, xbunker_auth=xbunker_auth,socialmediagirls_auth=socialmediagirls_auth, simpcity_auth=simpcity_auth,- separate_posts=separate_posts, skip_data=skip_data)+ separate_posts=separate_posts, skip_data=skip_data, output_last=output_last)tasks = []for link in urls:tasks.append(scraper.map_url(link))diff --git a/cyberdrop_dl/scraper/scraper_helper.py b/cyberdrop_dl/scraper/scraper_helper.pyindex 423d6af21..ad3e51d1e 100644--- a/cyberdrop_dl/scraper/scraper_helper.py+++ b/cyberdrop_dl/scraper/scraper_helper.py@@ -29,9 +29,10 @@ from ..client.rate_limiting import AsyncRateLimiterclass ScrapeMapper():def __init__(self, *, include_id=False, xbunker_auth=None, socialmediagirls_auth=None, simpcity_auth=None,- separate_posts=False, skip_data: SkipData, client: Client):+ separate_posts=False, skip_data: SkipData, client: Client, output_last: list):self.include_id = include_idself.separate_posts = separate_posts+ self.output_last = output_lastself.xbunker_auth = xbunker_authself.socialmediagirls_auth = socialmediagirls_authself.simpcity_auth = simpcity_auth@@ -64,9 +65,9 @@ class ScrapeMapper():self.semaphore = asyncio.Semaphore(1)self.mapping = {"anonfiles.com": self.Anonfiles, "bayfiles": self.Anonfiles, "bunkr": self.Bunkr,"coomer.party": self.coomer, "cyberdrop": self.Cyberdrop, "cyberfile.is": self.cyberfile,- "erome.com": self.Erome, "gfycat.com": self.gfycat, "gofile.io": self.GoFile, "img.kiwi": self.ShareX,- "jpg.church": self.ShareX, "jpg.homes": self.ShareX, "kemono.party": self.Kemono,- "pixeldrain.com": self.Pixeldrain, "pixl.is": self.ShareX,+ "erome.com": self.Erome, "gfycat.com": self.gfycat, "gofile.io": self.GoFile,+ "img.kiwi": self.ShareX, "jpg.church": self.ShareX, "jpg.homes": self.ShareX,+ "kemono.party": self.Kemono, "pixeldrain.com": self.Pixeldrain, "pixl.is": self.ShareX,"postimg": self.Postimg, "putme.ga": self.ShareX, "putmega.com": self.ShareX,"redgifs.com": self.redgifs, "saint.to": self.Saint, "socialmediagirls": self.SocialMediaGirls,"simpcity": self.SimpCity, "xbunker": self.XBunker}@@ -232,7 +233,8 @@ class ScrapeMapper():self.socialmediagirls_crawler = SocialMediaGirlsCrawler(include_id=self.include_id,auth=self.socialmediagirls_auth,scraping_mapper=self,- separate_posts=self.separate_posts)+ separate_posts=self.separate_posts,+ output_last=self.output_last)async with self.forum_limiter:await self.Cascade.extend(await self.socialmediagirls_crawler.fetch(socialmediagirls_session, url))await socialmediagirls_session.exit_handler()@@ -241,7 +243,8 @@ class ScrapeMapper():simpcity_session = Session(self.client)if not self.simpcity_crawler:self.simpcity_crawler = SimpCityCrawler(include_id=self.include_id, auth=self.simpcity_auth,- scraping_mapper=self, separate_posts=self.separate_posts)+ scraping_mapper=self, separate_posts=self.separate_posts,+ output_last=self.output_last)async with self.forum_limiter:await self.Cascade.extend(await self.simpcity_crawler.fetch(simpcity_session, url))await simpcity_session.exit_handler()@@ -250,7 +253,8 @@ class ScrapeMapper():xbunker_session = Session(self.client)if not self.xbunker_crawler:self.xbunker_crawler = XBunkerCrawler(include_id=self.include_id, auth=self.xbunker_auth,- scraping_mapper=self, separate_posts=self.separate_posts)+ scraping_mapper=self, separate_posts=self.separate_posts,+ output_last=self.output_last)async with self.forum_limiter:await self.Cascade.extend(await self.xbunker_crawler.fetch(xbunker_session, url))await xbunker_session.exit_handler()