Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Resolved upstream merge
cowliquid8fa8e92c236b
diff --cc cyberdrop_dl/main.pyindex 83b20681b,18b32912c..e63d42973--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@@ -100,12 -84,8 +85,9 @@@ async def download_all(args: argparse.Nawait log('There are still partial downloads in your folders, please re-run the program.')-def main():- args = parse_args()+def main(args=None):+ if not args:- print("parsing args")+ args = parse_args()- else:- print(args)logging.basicConfig(filename=args.log_file,level=logging.DEBUG,diff --cc cyberdrop_dl/utils/base_functions.pyindex 194ec931b,fe202767f..48eec70a5--- a/cyberdrop_dl/utils/base_functions.py+++ b/cyberdrop_dl/utils/base_functions.py@@@ -117,8 -76,7 +76,8 @@@ async def purge_dir(dir, in_place=True)async def regex_links(urls) -> list:- all_links = [x.group().replace(".md.", ".") for x in re.finditer(r"(?:http.*?)(?=('|$|\n|\r\n|\r|\s|\"|\[/URL]|]\[|\[/img]))", urls)]+ all_links = [x.group().replace(".md.", ".") for x in re.finditer(- r"(?:http.*?)(?=('|$|\n|\r\n|\r|\s|\"|\[/URL]))", urls)]++ r"(?:http.*?)(?=('|$|\n|\r\n|\r|\s|\"|\[/URL]|]\[|\[/img]))", urls)]yarl_links = []for link in all_links:yarl_links.append(URL(link))diff --cc cyberdrop_dl/utils/crawlers/Thotsbay_Spider.pyindex fbbc1ebf9,be3e56606..e588ae6cd--- a/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py+++ b/cyberdrop_dl/utils/crawlers/Thotsbay_Spider.py@@@ -62,9 -62,9 +63,9 @@@ 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)+ # await log("Finished scrape of " + str(url), Fore.WHITE)return Cascadeasync def parse_thread(self, session, url, Cascade, title):@@@ -120,20 -118,18 +125,20 @@@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']")+ links = post.select(+ "div[class='bbImageWrapper js-lbImage']")for link in links:link = link.get('data-src')if link.endswith("/"):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']")+ links = post.select(+ "div[class='bbImageWrapper lazyload js-lbImage']")for link in links:link = link.get('data-src')if link.endswith("/"):@@@ -153,56 -149,40 +158,59 @@@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 []+ attachments_block = post.select_one(+ "section[class=message-attachments]")+ links = attachments_block.select(+ "a[class='file-preview js-lbImage']") if attachments_block else []for link in links:link = link.get('href')if link.endswith("/"):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[0].host]- content_links = [x for x in content_links if x not 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"+ # Gyfcat+ links = post_content.select(+ "span[data-s9e-mediaembed-iframe]")+ for link in links:+ embed_data = link.get("data-s9e-mediaembed-iframe")+ # Replace gyfcat embed url escape chars+ embed_data = embed_data.replace("\/\/", "https://www.")+ embed_data = embed_data.replace("\\", "")++ # extract gyfcat url from embed data+ embed_url = re.search(+ "https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)", embed_data)+ if embed_url:+ embed_url = URL(embed_url.group(+ 0).replace("www.", ""))+ content_links.append(embed_url)++ forum_direct_urls = [+ x for x in content_links if url.host in x.host]+ content_links = [+ x for x in content_links if x not in forum_direct_urls]+ for link in forum_direct_urls: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"]')+ next_page = soup.select_one(+ 'a[class="pageNav-jump pageNav-jump--next"]')if next_page is not None:next_page = next_page.get('href')if next_page is not None:diff --cc cyberdrop_dl/utils/downloaders.pyindex 9add35718,c5a5071cb..dbf37c9e6--- a/cyberdrop_dl/utils/downloaders.py+++ b/cyberdrop_dl/utils/downloaders.py@@@ -154,13 -150,11 +152,13 @@@ class Downloaderasync with session.get(url, headers=headers, ssl=ssl_context, raise_for_status=True) as resp:content_type = resp.headers.get('Content-Type')if 'text' in content_type.lower() or 'html' in content_type.lower():- logger.debug(f"Server for %s is either down or the file no longer exists" % str(url))+ logger.debug(+ f"Server for %s is either down or the file no longer exists" % str(url))return- total = int(resp.headers.get('Content-Length', str(0))) + resume_point+ total = int(resp.headers.get(+ 'Content-Length', str(0))) + resume_point- if await sql_check_existing(self.cursor, filename, total):+ if await self.SQL_helper.sql_check_existing(filename, total):logger.debug("%s Already Downloaded" % filename)return@@@ -247,14 -241,14 +247,13 @@@async def download_content(self, show_progress: bool = True) -> None:"""Download the content of all links and save them as files."""- (self.folder / self.title).mkdir(parents=True, exist_ok=True)async with aiohttp.ClientSession(cookie_jar=self.cookie_jar) as session:await self.download_all(self.album_obj, session, show_progress=show_progress)- self.connection.commit()-+ self.SQL_helper.conn.commit()- def get_downloaders(Cascade: CascadeItem, folder: Path, attempts: int, disable_attempt_limit: bool, threads: int, exclude_videos: bool,- exclude_images: bool, exclude_audio: bool, exclude_other: bool, connection: sqlite3.Connection, cursor: sqlite3.Cursor) -> List[Downloader]:-+ def get_downloaders(Cascade: CascadeItem, folder: Path, attempts: int, disable_attempt_limit: bool, threads: int,+ exclude_videos: bool, exclude_images: bool, exclude_audio: bool, exclude_other: bool,+ SQL_helper: SQLHelper) -> List[Downloader]:"""Get a list of downloaders for each supported type of URLs.We shouldn't just assume that each URL will have the same netloc asthe first one, so we need to classify them one by one, sort them to