Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Implement --separate-posts flag.
Jules-WinnfieldXd842ba503044
diff --git a/CHANGELOG.txt b/CHANGELOG.txtindex caa9a121e..0756fdd46 100644--- a/CHANGELOG.txt+++ b/CHANGELOG.txt@@ -19,4 +19,7 @@ Created scraper_helper.pyRemoved title tags from thotsbay folder names.2.16.6-Added --ignore-history flag and separated SQL into its own helper class.\ No newline at end of file+Added --ignore-history flag and separated SQL into its own helper class.++2.16.8+added --separate-posts to separate each thotsbay post into it's own folder (request).\ No newline at end of filediff --git a/cyberdrop_dl/__init__.py b/cyberdrop_dl/__init__.pyindex b15cdcbbd..c72fa46f6 100644--- a/cyberdrop_dl/__init__.py+++ b/cyberdrop_dl/__init__.py@@ -1 +1 @@-__version__ = "2.16.7"+__version__ = "2.16.8"diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex 7545f322e..18b32912c 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -29,6 +29,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("--separate-posts", help="separates thotsbay scraping into folders by post", action="store_true")parser.add_argument("--thotsbay-username", type=str, help="username to login to thotsbay", default=None)parser.add_argument("--thotsbay-password", type=str, help="password to login to thotsbay", default=None)parser.add_argument("links", metavar="link", nargs="*", help="link to content to download (passing multiple links is supported)", default=[])@@ -54,7 +55,7 @@ async def download_all(args: argparse.Namespace):with open(input_file, "r") as f:links += await regex_links(f.read())- content_object = await scrape(links, args.include_id, args.thotsbay_username, args.thotsbay_password)+ content_object = await scrape(links, args.include_id, args.thotsbay_username, args.thotsbay_password, args.separate_posts)if await content_object.is_empty():logging.error(f'ValueError No links')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)diff --git a/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py b/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.pyindex ab61b403d..be3e56606 100644--- a/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py+++ b/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py@@ -9,8 +9,9 @@ from ..data_classes import CascadeItemclass ThotsbayCrawler():- def __init__(self, *, include_id=False, username=None, password=None, scraping_mapper, session):+ def __init__(self, *, include_id=False, username=None, password=None, scraping_mapper, session, separate_posts=False):self.include_id = include_id+ self.separate_posts = separate_postsself.username = usernameself.password = passwordself.scraping_mapper = scraping_mapper@@ -61,7 +62,7 @@ class ThotsbayCrawler():except Exception:await log("Error handling " + str(url))return- await Cascade.append_title(title)+ # await Cascade.append_title(title)await log("Finished scrape of " + str(url), Fore.WHITE)return Cascade@@ -95,11 +96,14 @@ class ThotsbayCrawler():posts = soup.select("div[class='message-main uix_messageContent js-quickEditTarget']")for post in posts:+ post_num_str = post.select_one("li[class=u-concealed] a").get('href').split('/')[-1]+ post_num_int = int(post_num_str.split('post-')[-1])if post_number:- post_num_int = post.select_one("li[class=u-concealed] a")- post_num_int = int(post_num_int.get('href').split('post-')[-1])if post_number > post_num_int:continue++ temp_title = title+"/"+post_num_str if self.separate_posts else title+for elem in post.find_all('blockquote'):elem.decompose()post_content = post.select_one("div[class=bbWrapper]")@@ -114,7 +118,7 @@ class ThotsbayCrawler():link = "https:" + linkelif link.startswith('/'):link = domain / link[1:]- content_links.append(URL(link))+ content_links.append([URL(link), temp_title])links = post.select("div[class='bbImageWrapper js-lbImage']")for link in links:@@ -123,7 +127,7 @@ class ThotsbayCrawler():link = link[:-1]if link.startswith('/'):link = domain / link[1:]- content_links.append(URL(link))+ content_links.append([URL(link), temp_title])links = post.select("div[class='bbImageWrapper lazyload js-lbImage']")for link in links:@@ -134,7 +138,7 @@ class ThotsbayCrawler():link = "https:" + linkelif link.startswith('/'):link = domain / link[1:]- content_links.append(URL(link))+ content_links.append([URL(link), temp_title])links = post.select("video source")for link in links:@@ -145,7 +149,7 @@ class ThotsbayCrawler():link = "https:" + linkelif link.startswith('/'):link = domain / link[1:]- content_links.append(URL(link))+ content_links.append([URL(link), temp_title])attachments_block = post.select_one("section[class=message-attachments]")links = attachments_block.select("a[class='file-preview js-lbImage']") if attachments_block else []@@ -155,21 +159,27 @@ class ThotsbayCrawler():link = link[:-1]if link.startswith('/'):link = domain / link[1:]- await Cascade.add_to_album(url.host, "Attachments", URL(link), url)+ in_prog_title = temp_title + "/Attachments" if self.separate_posts else "Attachments"+ await Cascade.add_to_album(url.host, in_prog_title, URL(link), url)- forum_direct_urls = [x for x in content_links if url.host in x.host]+ forum_direct_urls = [x for x in content_links if url.host in x[0].host]content_links = [x for x in content_links if x not in forum_direct_urls]- for link in forum_direct_urls:+ for link_title_bundle in forum_direct_urls:+ link = link_title_bundle[0]+ temp_title = link_title_bundle[1]+ in_prog_title = temp_title + "/Attachments" if self.separate_posts else "Attachments"if str(link).endswith("/"):link = URL(str(link)[:-1])if 'attachments' in link.parts:- await Cascade.add_to_album(url.host, "Attachments", link, url)+ await Cascade.add_to_album(url.host, in_prog_title, link, url)elif 'data' in link.parts:- await Cascade.add_to_album(url.host, "Attachments", link, url)+ await Cascade.add_to_album(url.host, in_prog_title, link, url)tasks = []- for link in content_links:- tasks.append(self.scraping_mapper.map_url(link, title))+ for link_title_bundle in content_links:+ link = link_title_bundle[0]+ temp_title = link_title_bundle[1]+ tasks.append(self.scraping_mapper.map_url(link, temp_title))await asyncio.gather(*tasks)next_page = soup.select_one('a[class="pageNav-jump pageNav-jump--next"]')diff --git a/cyberdrop_dl/utils/scraper.py b/cyberdrop_dl/utils/scraper.pyindex 3fb3d1c06..7d14b7815 100644--- a/cyberdrop_dl/utils/scraper.py+++ b/cyberdrop_dl/utils/scraper.py@@ -7,13 +7,13 @@ from .base_functions import log, user_agentfrom .scraper_helper import ScrapeMapper-async def scrape(urls, include_id: bool, thotsbay_username: str, thotsbay_password: str):+async def scrape(urls, include_id: bool, thotsbay_username: str, thotsbay_password: str, separate_posts: bool):await log("Starting Scrape", Fore.WHITE)headers = {"user-agent": user_agent}jar = aiohttp.CookieJar(quote_cookie=False)async with aiohttp.ClientSession(headers=headers, raise_for_status=True, cookie_jar=jar) as session:- scraper = ScrapeMapper(session=session, include_id=include_id, username=thotsbay_username, password=thotsbay_password)+ scraper = ScrapeMapper(session=session, include_id=include_id, username=thotsbay_username, password=thotsbay_password, separate_posts=separate_posts)tasks = []for link in urls:tasks.append(scraper.map_url(link))diff --git a/cyberdrop_dl/utils/scraper_helper.py b/cyberdrop_dl/utils/scraper_helper.pyindex eb08cb352..3123ca34d 100644--- a/cyberdrop_dl/utils/scraper_helper.py+++ b/cyberdrop_dl/utils/scraper_helper.py@@ -11,8 +11,9 @@ from .data_classes import CascadeItemclass ScrapeMapper():- def __init__(self, *, session, include_id=False, username=None, password=None):+ def __init__(self, *, session, include_id=False, username=None, password=None, separate_posts=False):self.include_id = include_id+ self.separate_posts = separate_postsself.username = usernameself.password = passwordself.session = session@@ -78,7 +79,7 @@ class ScrapeMapper():async def ThotsBay(self, url: URL, title=None):if not self.thotsbay_crawler:- self.thotsbay_crawler = ThotsbayCrawler(include_id=self.include_id, username=self.username, password=self.password, scraping_mapper=self, session=self.session)+ self.thotsbay_crawler = ThotsbayCrawler(include_id=self.include_id, username=self.username, password=self.password, scraping_mapper=self, session=self.session, separate_posts=self.separate_posts)await self.Cascade.extend(await self.thotsbay_crawler.fetch(self.session, url))async def map_url(self, url_to_map: URL, title=None):