Skip to content

Bulk asynchronous downloader for multiple file hosts

Minor bug fixes and basic commenting, removing unused imports

Jules-WinnfieldXbffc05f51a08
diff --git a/Timelog b/Timelog
index 620dc3206..5d214d8e4 100644
--- a/Timelog
+++ b/Timelog
@@ -9,4 +9,5 @@
2023-02-09: 10:05AM:12:35PM:
2023-02-09: 1:05PM:3:46PM:
2023-02-09: 6:12PM:9:01PM: 2941 Minutes Total
-2023-02-09: 9:01PM:
\ No newline at end of file
+2023-02-09: 9:01PM:11:00PM: 3060 Minutes Total
+2023-02-10: 9:35AM:
\ No newline at end of file
diff --git a/cyberdrop_dl/base_functions/base_functions.py b/cyberdrop_dl/base_functions/base_functions.py
index 7efa6c58b..00270c31f 100644
--- a/cyberdrop_dl/base_functions/base_functions.py
+++ b/cyberdrop_dl/base_functions/base_functions.py
@@ -74,6 +74,7 @@ async def check_free_space(required_space: int, download_directory: Path) -> boo
async def allowed_filetype(media: MediaItem, block_images: bool, block_video: bool, block_audio: bool, block_other: bool):
+ """Checks whether the enclosed file is allowed to be downloaded"""
ext = media.ext
if block_images:
if ext in FILE_FORMATS["Images"]:
@@ -111,6 +112,7 @@ async def write_last_post_file(file: Path, url: str):
async def get_db_path(url: URL, referer=None):
+ """Gets the URL path to be put into the DB and checked from the DB"""
url_path = url.path
if 'anonfiles' in url.host or 'bayfiles' in url.host:
url_path = url.path
@@ -140,6 +142,7 @@ async def make_title_safe(title: str) -> str:
async def check_direct(url: URL):
+ """Checks whether the given url is a direct link to a content item"""
mapping_direct = [r'i.pixl.li', r'i..pixl.li', r'img-...cyberdrop...', r'f.cyberdrop...',
r'fs-...cyberdrop...', r'jpg.church/images/...', r'simp..jpg.church', r's..putmega.com',
r's..putme.ga', r'images..imgbox.com', 's..lovefap...']
@@ -147,6 +150,7 @@ async def check_direct(url: URL):
async def get_filename_and_ext(filename):
+ """Returns the filename and extension of a given file, throws NoExtensionFailure if there is no extension"""
filename_parts = filename.rsplit('.', 1)
if len(filename_parts) == 1:
raise NoExtensionFailure()
diff --git a/cyberdrop_dl/base_functions/config_manager.py b/cyberdrop_dl/base_functions/config_manager.py
index e552460df..cb6f60b54 100644
--- a/cyberdrop_dl/base_functions/config_manager.py
+++ b/cyberdrop_dl/base_functions/config_manager.py
@@ -1,4 +1,5 @@
from __future__ import annotations
+
import copy
from pathlib import Path
diff --git a/cyberdrop_dl/base_functions/data_classes.py b/cyberdrop_dl/base_functions/data_classes.py
index 6abc052a5..19dfeee20 100644
--- a/cyberdrop_dl/base_functions/data_classes.py
+++ b/cyberdrop_dl/base_functions/data_classes.py
@@ -1,7 +1,8 @@
+from __future__ import annotations
+
import asyncio
from dataclasses import dataclass
-from pathlib import Path
-from typing import ClassVar, Dict, List, Optional, Tuple
+from typing import ClassVar, List, Tuple
from yarl import URL
@@ -50,7 +51,7 @@ class AlbumItem:
class DomainItem:
"""Class for keeping track of albums for each scraper type"""
domain: str
- albums: Dict[str, AlbumItem]
+ albums: dict
async def add_to_album(self, title: str, media: MediaItem):
if title in self.albums.keys():
@@ -96,7 +97,7 @@ class DomainItem:
@dataclass
class CascadeItem:
"""Class for keeping track of domains for each scraper type"""
- domains: Dict[str, DomainItem]
+ domains: dict
async def add_albums(self, domain_item: DomainItem):
domain = domain_item.domain
@@ -156,7 +157,8 @@ class CascadeItem:
@dataclass
class ForumItem:
- threads: Dict[str, CascadeItem]
+ """Class for keeping track of forum threads"""
+ threads: dict
async def add_album_to_thread(self, title: str, domain: str, album: AlbumItem):
if title not in self.threads.keys():
diff --git a/cyberdrop_dl/base_functions/error_classes.py b/cyberdrop_dl/base_functions/error_classes.py
index fb997255d..e4ade0625 100644
--- a/cyberdrop_dl/base_functions/error_classes.py
+++ b/cyberdrop_dl/base_functions/error_classes.py
@@ -13,12 +13,14 @@ class NoExtensionFailure(Exception):
class FailedLoginFailure(Exception):
+ """This error will be thrown when the login fails for a site"""
def __init__(self, *, message="Failed login."):
self.message = message
super().__init__(self.message)
class DownloadFailure(Exception):
+ """This error will be thrown when a download fails"""
def __init__(self, code, message="Something went wrong"):
self.code = code
self.message = message
diff --git a/cyberdrop_dl/base_functions/sql_helper.py b/cyberdrop_dl/base_functions/sql_helper.py
index c8d8f15ab..9017746dd 100644
--- a/cyberdrop_dl/base_functions/sql_helper.py
+++ b/cyberdrop_dl/base_functions/sql_helper.py
@@ -4,7 +4,7 @@ import sqlite3
from pathlib import Path
from cyberdrop_dl.base_functions.base_functions import get_db_path
-from cyberdrop_dl.base_functions.data_classes import AlbumItem, CascadeItem, MediaItem, DomainItem
+from cyberdrop_dl.base_functions.data_classes import AlbumItem, CascadeItem, DomainItem
class SQLHelper:
@@ -32,6 +32,7 @@ class SQLHelper:
await self.create_coomeno_history()
async def check_old_history(self):
+ """Checks whether V3 history exists"""
self.curs.execute("""SELECT name FROM sqlite_schema WHERE type='table' AND name='downloads'""")
sql_file_check = self.curs.fetchone()
if sql_file_check:
@@ -63,6 +64,7 @@ class SQLHelper:
self.conn.commit()
async def create_coomeno_history(self):
+ """Creates the cache table for coomeno"""
create_table_query = """CREATE TABLE IF NOT EXISTS coomeno (
url_path TEXT,
post_data BLOB,
@@ -91,22 +93,26 @@ class SQLHelper:
"""Temp Table Operations"""
async def get_temp_names(self):
+ """Gets the list of temp filenames"""
self.curs.execute("SELECT downloaded_filename FROM downloads_temp;")
filenames = self.curs.fetchall()
filenames = list(sum(filenames, ()))
return filenames
async def sql_insert_temp(self, downloaded_filename):
+ """Inserts a temp filename into the downloads_temp table"""
self.curs.execute("""INSERT OR IGNORE INTO downloads_temp VALUES (?)""", (downloaded_filename,))
self.conn.commit()
"""Coomeno Table Operations"""
async def insert_blob(self, blob: str, url_path: str):
+ """Inserts the post content into coomeno"""
self.curs.execute("""INSERT OR IGNORE INTO coomeno VALUES (?, ?)""", (url_path, blob,))
self.conn.commit()
async def get_blob(self, url_path: str):
+ """returns the post content for a given coomeno post url"""
if self.ignore_cache:
return None
self.curs.execute("""SELECT post_data FROM coomeno WHERE url_path = ?""", (url_path,))
@@ -119,11 +125,13 @@ class SQLHelper:
async def insert_media(self, domain: str, url_path: str, album_path: str, referer: str, download_path: str,
download_filename: str, original_filename: str, completed: int):
+ """Inserts a media entry into the media table"""
self.curs.execute("""INSERT OR IGNORE INTO media VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
(domain, url_path, album_path, referer, download_path, download_filename, original_filename, completed,))
self.conn.commit()
async def insert_album(self, domain: str, album_path: str, album: AlbumItem):
+ """Inserts an albums media into the media table"""
if album.media:
for media in album.media:
url_path = await get_db_path(media.url, domain)
@@ -132,6 +140,7 @@ class SQLHelper:
self.conn.commit()
async def insert_domain(self, domain_name: str, album_path: str, domain: DomainItem):
+ """Inserts a domains media into the media table"""
if domain.albums:
for title, album in domain.albums.items():
for media in album.media:
@@ -142,6 +151,7 @@ class SQLHelper:
self.conn.commit()
async def insert_cascade(self, cascade: CascadeItem):
+ """Inserts a cascades media into the media table"""
if not await cascade.is_empty():
for domain, domain_obj in cascade.domains.items():
for title, album_obj in domain_obj.albums.items():
@@ -153,6 +163,7 @@ class SQLHelper:
self.conn.commit()
async def get_downloaded_filename(self, url_path, filename):
+ """Gets downloaded filename given the url path and original filename"""
self.curs.execute("""SELECT download_filename FROM media WHERE url_path = ? and original_filename = ?""",
(url_path, filename,))
sql_file_check = self.curs.fetchone()
@@ -161,6 +172,7 @@ class SQLHelper:
return None
async def sql_check_old_existing(self, url_path):
+ """Checks the V3 history table for completed if it exists"""
if not self.old_history:
return False
if self.ignore_history:
@@ -170,6 +182,7 @@ class SQLHelper:
return sql_file_check and sql_file_check[0] == 1
async def check_complete_singular(self, domain, url_path):
+ """Checks whether an individual file has completed given its domain and url path"""
if self.ignore_history:
return False
self.curs.execute("""SELECT completed FROM media WHERE domain = ? and url_path = ?""", (domain, url_path,))
@@ -184,15 +197,19 @@ class SQLHelper:
"""Downloader Operations"""
async def check_filename(self, filename):
+ """Checks whether an individual exists in the DB given its filename"""
self.curs.execute("""SELECT EXISTS(SELECT 1 FROM media WHERE download_filename = ?)""", (filename, ))
sql_check = self.curs.fetchone()[0]
return sql_check == 1
async def update_pre_download(self, path: Path, filename: str, url_path: str, original_filename: str):
- self.curs.execute("""UPDATE media SET download_path = ?, download_filename = ? WHERE url_path = ? AND original_filename = ?""", (str(path), filename, url_path, original_filename,))
+ """Update the media entry pre-download"""
+ self.curs.execute("""UPDATE media SET download_path = ?, download_filename = ? WHERE url_path = ?
+ AND original_filename = ?""", (str(path), filename, url_path, original_filename,))
self.conn.commit()
async def mark_complete(self, url_path: str, original_filename: str):
+ """Update the media entry post-download"""
self.curs.execute("""UPDATE media SET completed = 1 WHERE url_path = ? AND original_filename = ?""", (url_path, original_filename,))
self.conn.commit()
diff --git a/cyberdrop_dl/client/client.py b/cyberdrop_dl/client/client.py
index 8fc530121..8b9acb91e 100644
--- a/cyberdrop_dl/client/client.py
+++ b/cyberdrop_dl/client/client.py
@@ -1,4 +1,5 @@
from __future__ import annotations
+
import asyncio
import json
import logging
diff --git a/cyberdrop_dl/client/rate_limiting.py b/cyberdrop_dl/client/rate_limiting.py
index acdc5a90d..75c37d606 100644
--- a/cyberdrop_dl/client/rate_limiting.py
+++ b/cyberdrop_dl/client/rate_limiting.py
@@ -6,8 +6,6 @@ from datetime import datetime
from types import TracebackType
from typing import Optional, Callable, Awaitable, Any, Type
-from ..base_functions.base_functions import logger
-
class AsyncRateLimiter:
"""Provides rate limiting for an operation with a configurable number of requests for a time period."""
diff --git a/cyberdrop_dl/crawlers/Anonfiles_Spider.py b/cyberdrop_dl/crawlers/Anonfiles_Spider.py
index 79a42261b..2424d8f55 100644
--- a/cyberdrop_dl/crawlers/Anonfiles_Spider.py
+++ b/cyberdrop_dl/crawlers/Anonfiles_Spider.py
@@ -13,6 +13,7 @@ class AnonfilesCrawler:
self.api_link = URL("https://api.anonfiles.com/v2/file")
async def fetch(self, session: ScrapeSession, url: URL):
+ """Scraper for Anonfiles"""
if 'cdn' in url.host:
url = URL("https://anonfiles.com") / url.parts[1]
diff --git a/cyberdrop_dl/crawlers/Bunkr_Spider.py b/cyberdrop_dl/crawlers/Bunkr_Spider.py
index 854d32b33..8431a322e 100644
--- a/cyberdrop_dl/crawlers/Bunkr_Spider.py
+++ b/cyberdrop_dl/crawlers/Bunkr_Spider.py
@@ -1,5 +1,4 @@
import re
-from pathlib import Path
from yarl import URL
@@ -18,6 +17,7 @@ class BunkrCrawler:
self.remove_bunkr_id = remove_bunkr_id
async def fetch(self, session: ScrapeSession, url: URL):
+ """Scraper for Bunkr"""
album_obj = AlbumItem("Loose Bunkr Items", [])
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
@@ -66,6 +66,7 @@ class BunkrCrawler:
return album_obj
async def remove_id(self, filename: str, ext: str):
+ """Removes the additional string bunkr adds to the end of every filename"""
filename = filename.rsplit(ext, 1)[0]
filename = filename.rsplit("-")[0]
if not ext in filename:
@@ -73,6 +74,7 @@ class BunkrCrawler:
return filename
async def get_file(self, session: ScrapeSession, url: URL):
+ """Gets the media item from the supplied url"""
try:
soup = await session.get_BS4(url)
head = soup.select_one("head")
@@ -105,6 +107,7 @@ class BunkrCrawler:
return MediaItem(url, url, False, "", "")
async def get_album(self, session: ScrapeSession, url: URL):
+ """Iterates through an album and creates the media items"""
album = AlbumItem(url.name, [])
try:
soup = await session.get_BS4(url)
diff --git a/cyberdrop_dl/crawlers/Coomeno_Spider.py b/cyberdrop_dl/crawlers/Coomeno_Spider.py
index 83de9c715..a1b4623a2 100644
--- a/cyberdrop_dl/crawlers/Coomeno_Spider.py
+++ b/cyberdrop_dl/crawlers/Coomeno_Spider.py
@@ -18,6 +18,7 @@ class CoomenoCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Director for Coomer/Kemono scraping"""
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
cascade = CascadeItem({})
title = None
@@ -36,6 +37,7 @@ class CoomenoCrawler:
return cascade, title
async def handle_coomer(self, session: ScrapeSession, url: URL, cascade: CascadeItem):
+ """Coomer director function"""
post_selectors = ['h2[class=post-card__heading] a']
next_page_selector = 'a[title="Next page"]'
images_selector = 'a[class="fileThumb"]'
@@ -71,6 +73,7 @@ class CoomenoCrawler:
return title
async def handle_kemono(self, session: ScrapeSession, url: URL, cascade: CascadeItem):
+ """Kemono director function"""
post_selectors = ['article[class="post-card post-card--preview"] a', 'article[class="post-card"] a']
next_page_selector = 'a[class=next]'
images_selector = 'a[class="fileThumb"]'
@@ -106,6 +109,7 @@ class CoomenoCrawler:
return title
async def map_links(self, text_content: list, title: str, referer: URL):
+ """Maps external links to other scrapers"""
tasks = []
for content in text_content:
link = URL(content.get('href'))
@@ -115,6 +119,7 @@ class CoomenoCrawler:
async def parse_profile(self, session: ScrapeSession, url: URL, domain: str, cascade: CascadeItem,
posts_selectors: list, next_page_selector: str, images_selector: str,
downloads_selector: str, text_selector: str):
+ """Parses profiles with supplied selectors"""
title = None
try:
soup = await session.get_BS4(url)
@@ -148,6 +153,7 @@ class CoomenoCrawler:
async def parse_post(self, session: ScrapeSession, url: URL, domain: str, cascade: CascadeItem,
images_selector: str, downloads_selector: str, text_selector: str, title=None):
+ """Parses posts with supplied selectors"""
try:
url_path = await get_db_path(url)
text = await self.SQL_Helper.get_blob(url_path)
diff --git a/cyberdrop_dl/crawlers/CyberFile_Spider.py b/cyberdrop_dl/crawlers/CyberFile_Spider.py
index 7efac8e83..10bb6df07 100644
--- a/cyberdrop_dl/crawlers/CyberFile_Spider.py
+++ b/cyberdrop_dl/crawlers/CyberFile_Spider.py
@@ -16,6 +16,7 @@ class CyberFileCrawler:
self.file_details = URL('https://cyberfile.me/account/ajax/file_details')
async def fetch(self, session: ScrapeSession, url: URL):
+ """Director for cyberfile scraping"""
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
domain_obj = DomainItem("cyberfile", {})
download_links = []
@@ -44,6 +45,7 @@ class CyberFileCrawler:
return domain_obj
async def get_folder_id(self, session: ScrapeSession, url: URL):
+ """Gets the internal ID for a folder"""
try:
soup = await session.get_BS4(url)
script_func = soup.select_one('div[class="page-container horizontal-menu with-sidebar fit-logo-with-sidebar logged-out clear-adblock"] script').text
@@ -59,6 +61,7 @@ class CyberFileCrawler:
return 0
async def get_folder_content(self, session, url: URL, nodeId, page, title=None):
+ """Gets the content id's encased in a folder"""
data = {"pageType": "folder", "nodeId": nodeId, "pageStart": page, "perPage": 0, "filterOrderBy": ""}
nodes = []
contents = []
@@ -98,6 +101,7 @@ class CyberFileCrawler:
return []
async def get_single_contentId(self, session: ScrapeSession, url: URL):
+ """Gets an individual content id"""
try:
soup = await session.get_BS4(url)
script_funcs = soup.select('script')
@@ -119,6 +123,7 @@ class CyberFileCrawler:
return 0
async def get_shared_ids_and_content(self, session: ScrapeSession, url: URL, page):
+ """Gets folder id's and content id's from shared links"""
try:
# Initial page load to tell server, this is what we want.
await session.get_no_resp(url, {'referer': str(url), "user-agent": session.client.user_agent})
@@ -158,6 +163,7 @@ class CyberFileCrawler:
return []
async def get_shared_content(self, session, url: URL, nodeId, page, title=None):
+ """Gets content from shared folders"""
try:
nodes = []
contents = []
@@ -196,6 +202,7 @@ class CyberFileCrawler:
return []
async def get_download_links(self, session, url, contentIds):
+ """Obtains download links from content ids"""
download_links = []
try:
for title, contentId in contentIds:
diff --git a/cyberdrop_dl/crawlers/Cyberdrop_Spider.py b/cyberdrop_dl/crawlers/Cyberdrop_Spider.py
index b64fa60d9..283182b0d 100644
--- a/cyberdrop_dl/crawlers/Cyberdrop_Spider.py
+++ b/cyberdrop_dl/crawlers/Cyberdrop_Spider.py
@@ -1,5 +1,3 @@
-from pathlib import Path
-
from yarl import URL
from ..base_functions.base_functions import log, logger, make_title_safe, check_direct, get_filename_and_ext, \
@@ -17,6 +15,7 @@ class CyberdropCrawler:
self.quiet = quiet
async def fetch(self, session: ScrapeSession, url: URL):
+ """Cyberdrop scraper"""
album_obj = AlbumItem("Loose Cyberdrop Files", [])
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
diff --git a/cyberdrop_dl/crawlers/EHentai_Spider.py b/cyberdrop_dl/crawlers/EHentai_Spider.py
index af928ff56..e5d9adeb3 100644
--- a/cyberdrop_dl/crawlers/EHentai_Spider.py
+++ b/cyberdrop_dl/crawlers/EHentai_Spider.py
@@ -12,6 +12,7 @@ class EHentaiCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Director for E-Hentai"""
album_obj = AlbumItem("Loose EHentai Files", [])
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
@@ -25,6 +26,7 @@ class EHentaiCrawler:
return album_obj
async def get_album(self, session: ScrapeSession, url: URL, album_obj: AlbumItem):
+ """Gets links from an album"""
try:
soup = await session.get_BS4(url)
title = await make_title_safe(soup.select_one("h1[id=gn]").get_text())
@@ -53,6 +55,7 @@ class EHentaiCrawler:
logger.debug(e)
async def get_image(self, session: ScrapeSession, url: URL, album_obj: AlbumItem):
+ """Gets media items from image links"""
try:
soup = await session.get_BS4(url)
image = soup.select_one("img[id=img]")
diff --git a/cyberdrop_dl/crawlers/Erome_Spider.py b/cyberdrop_dl/crawlers/Erome_Spider.py
index d67ecce44..7ac2afb15 100644
--- a/cyberdrop_dl/crawlers/Erome_Spider.py
+++ b/cyberdrop_dl/crawlers/Erome_Spider.py
@@ -14,7 +14,7 @@ class EromeCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
-
+ """Director function for Erome scraping"""
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
if 'a' in url.parts:
@@ -27,6 +27,7 @@ class EromeCrawler:
return domain_obj
async def handle_album(self, session: ScrapeSession, url: URL):
+ """Handler function for erome albums, adds media items to the domain item"""
try:
domain_obj = DomainItem("erome", {})
soup = await session.get_BS4(url)
@@ -74,6 +75,7 @@ class EromeCrawler:
return domain_obj
async def handle_profile(self, session: ScrapeSession, url: URL):
+ """Handler for erome profiles, sends albums to handle_album"""
try:
domain_obj = DomainItem("erome", {})
soup = await session.get_BS4(url)
diff --git a/cyberdrop_dl/crawlers/Fapello_Spider.py b/cyberdrop_dl/crawlers/Fapello_Spider.py
index 6788e95d3..8b3a418aa 100644
--- a/cyberdrop_dl/crawlers/Fapello_Spider.py
+++ b/cyberdrop_dl/crawlers/Fapello_Spider.py
@@ -13,6 +13,7 @@ class FapelloCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Basic director for fapello"""
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
album_obj = await self.parse_profile(session, url)
@@ -23,6 +24,7 @@ class FapelloCrawler:
return album_obj
async def parse_profile(self, session: ScrapeSession, url: URL):
+ """Profile parser, passes posts to parse_post"""
try:
soup, returned_url = await session.get_BS4_and_url(url)
title = soup.select_one('h2[class="font-semibold lg:text-2xl text-lg mb-2 mt-4"]').get_text()
@@ -59,6 +61,7 @@ class FapelloCrawler:
return
async def parse_post(self, session: ScrapeSession, url: URL):
+ """Parses posts, returns list of media_items"""
try:
soup = await session.get_BS4(url)
results = []
@@ -95,4 +98,4 @@ class FapelloCrawler:
logger.debug("Error encountered while handling %s", str(url), exc_info=True)
await log(f"[red]Error: {str(url)}[/red]", quiet=self.quiet)
logger.debug(e)
- return
\ No newline at end of file
+ return
diff --git a/cyberdrop_dl/crawlers/Gfycat_Spider.py b/cyberdrop_dl/crawlers/Gfycat_Spider.py
index 9c61cbbc0..b9fac584a 100644
--- a/cyberdrop_dl/crawlers/Gfycat_Spider.py
+++ b/cyberdrop_dl/crawlers/Gfycat_Spider.py
@@ -12,6 +12,7 @@ class GfycatCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Basic scraper for gfycat"""
try:
album_obj = AlbumItem("Gfycat", [])
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
@@ -34,6 +35,7 @@ class GfycatCrawler:
filename, ext = await get_filename_and_ext(video_link.name)
media_item = MediaItem(video_link, url, complete, filename, ext)
await album_obj.add_media(media_item)
+ await self.SQL_Helper.insert_album("gfycat", url_path, album_obj)
await log(f"[green]Finished: {str(url)}[/green]", quiet=self.quiet)
return album_obj
diff --git a/cyberdrop_dl/crawlers/GoFile_Spider.py b/cyberdrop_dl/crawlers/GoFile_Spider.py
index 0747edd41..46b7c7a14 100644
--- a/cyberdrop_dl/crawlers/GoFile_Spider.py
+++ b/cyberdrop_dl/crawlers/GoFile_Spider.py
@@ -19,6 +19,7 @@ class GoFileCrawler:
self.token = None
async def get_token(self, session: ScrapeSession):
+ """Creates an anon gofile account to use."""
if self.token:
return
@@ -35,6 +36,7 @@ class GoFileCrawler:
logger.debug(e)
async def set_cookie(self, session: ScrapeSession):
+ """Sets the given token as a cookie into the session (and client)"""
client_token = self.token
morsel = http.cookies.Morsel()
morsel['domain'] = 'gofile.io'
@@ -42,6 +44,7 @@ class GoFileCrawler:
session.client_session.cookie_jar.update_cookies({'gofile.io': morsel})
async def fetch(self, session: ScrapeSession, url: URL):
+ """Basic director for actual scraping"""
try:
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
domain_obj = DomainItem("gofile", {})
@@ -61,6 +64,7 @@ class GoFileCrawler:
logger.debug(e)
async def get_links(self, session: ScrapeSession, url: URL, content_id: str, title=None):
+ """Gets links from the given url, creates media_items"""
results = []
params = {
"token": self.token,
diff --git a/cyberdrop_dl/crawlers/HGameCG_Spider.py b/cyberdrop_dl/crawlers/HGameCG_Spider.py
index d13615efc..705ac1787 100644
--- a/cyberdrop_dl/crawlers/HGameCG_Spider.py
+++ b/cyberdrop_dl/crawlers/HGameCG_Spider.py
@@ -12,6 +12,7 @@ class HGameCGCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Basic director for HGameCG"""
album_obj = AlbumItem("Loose HGamesCG Files", [])
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
@@ -22,10 +23,11 @@ class HGameCGCrawler:
return album_obj
async def get_album(self, session: ScrapeSession, url: URL, album_obj: AlbumItem):
+ """Handles album scraping, adds media items to the album_obj"""
try:
soup = await session.get_BS4(url)
title = await make_title_safe(soup.select_one("div[class=navbar] h1").get_text())
- title = await album_obj.set_new_title(title)
+ await album_obj.set_new_title(title)
images = soup.select("div[class=image] a")
for image in images:
@@ -53,6 +55,7 @@ class HGameCGCrawler:
logger.debug(e)
async def get_image(self, session: ScrapeSession, url: URL):
+ """Gets image link from the given url."""
try:
soup = await session.get_BS4(url)
image = soup.select_one("div[class=hgamecgimage] img")
diff --git a/cyberdrop_dl/crawlers/ImgBox_Spider.py b/cyberdrop_dl/crawlers/ImgBox_Spider.py
index fae947026..1089631c6 100644
--- a/cyberdrop_dl/crawlers/ImgBox_Spider.py
+++ b/cyberdrop_dl/crawlers/ImgBox_Spider.py
@@ -14,6 +14,7 @@ class ImgBoxCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Director func for ImgBox scraping"""
album_obj = AlbumItem("Loose ImgBox Files", [])
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
@@ -59,6 +60,7 @@ class ImgBoxCrawler:
return album_obj
async def folder(self, session: ScrapeSession, url: URL):
+ """Gets links from a folder"""
soup = await session.get_BS4(url)
output = []
title = soup.select_one("div[id=gallery-view] h1").get_text()
@@ -72,6 +74,7 @@ class ImgBoxCrawler:
return title, output
async def singular(self, session: ScrapeSession, url: URL):
+ """Gets individual links"""
soup = await session.get_BS4(url)
link = URL(soup.select_one("img[id=img]").get('src'))
return link
diff --git a/cyberdrop_dl/crawlers/LoveFap_Spider.py b/cyberdrop_dl/crawlers/LoveFap_Spider.py
index 3e44ad127..a9146603b 100644
--- a/cyberdrop_dl/crawlers/LoveFap_Spider.py
+++ b/cyberdrop_dl/crawlers/LoveFap_Spider.py
@@ -1,5 +1,3 @@
-from pathlib import Path
-
from yarl import URL
from ..base_functions.base_functions import log, logger, make_title_safe, check_direct, get_filename_and_ext, \
@@ -16,6 +14,7 @@ class LoveFapCrawler:
self.quiet = quiet
async def fetch(self, session: ScrapeSession, url: URL):
+ """Director for lovefap scraping"""
album_obj = AlbumItem("Loose LoveFap Files", [])
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
@@ -47,6 +46,7 @@ class LoveFapCrawler:
return album_obj
async def fetch_album(self, session: ScrapeSession, url: URL, album_obj: AlbumItem):
+ """Gets media_items for albums, and adds them to the Album_obj"""
url_path = await get_db_path(url)
soup = await session.get_BS4(url)
@@ -78,6 +78,7 @@ class LoveFapCrawler:
await album_obj.add_media(media)
async def fetch_video(self, session: ScrapeSession, url: URL, album_obj: AlbumItem):
+ """Gets media_items for video links"""
soup = await session.get_BS4(url)
video = soup.select_one("video[id=main-video] source")
if video:
diff --git a/cyberdrop_dl/crawlers/NSFWXXXCrawler.py b/cyberdrop_dl/crawlers/NSFWXXXCrawler.py
index 65b8cd98b..df2beda37 100644
--- a/cyberdrop_dl/crawlers/NSFWXXXCrawler.py
+++ b/cyberdrop_dl/crawlers/NSFWXXXCrawler.py
@@ -15,6 +15,7 @@ class NSFWXXXCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Director for NSFW.XXX scraping"""
domain_obj = DomainItem("nsfw.xxx", {})
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
@@ -27,6 +28,7 @@ class NSFWXXXCrawler:
return domain_obj
async def get_user(self, session: ScrapeSession, url: URL, domain_obj: DomainItem):
+ """Gets posts for a user profile"""
try:
page = 1
while True:
@@ -51,6 +53,7 @@ class NSFWXXXCrawler:
logger.debug(e)
async def get_post_hrefs(self, posts):
+ """Gets links from post objects"""
posts_links = []
for post in posts:
url = URL(post.get("href"))
@@ -59,6 +62,7 @@ class NSFWXXXCrawler:
return posts_links
async def get_post(self, session: ScrapeSession, url: URL, domain_obj: DomainItem):
+ """Gets content for a given post url"""
try:
soup = await session.get_BS4(url)
model = await make_title_safe(soup.select_one("a[class=sh-section__name]").get_text()) + " (NSFW.XXX)"
diff --git a/cyberdrop_dl/crawlers/PimpAndHost_Spider.py b/cyberdrop_dl/crawlers/PimpAndHost_Spider.py
index 5c9feb4da..2da3069e6 100644
--- a/cyberdrop_dl/crawlers/PimpAndHost_Spider.py
+++ b/cyberdrop_dl/crawlers/PimpAndHost_Spider.py
@@ -2,7 +2,6 @@ from yarl import URL
from ..base_functions.base_functions import log, logger, get_filename_and_ext, get_db_path, make_title_safe
from ..base_functions.data_classes import AlbumItem, MediaItem
-from ..base_functions.error_classes import NoExtensionFailure
from ..base_functions.sql_helper import SQLHelper
from ..client.client import ScrapeSession
@@ -11,9 +10,9 @@ class PimpAndHostCrawler:
def __init__(self, quiet: bool, SQL_Helper: SQLHelper):
self.quiet = quiet
self.SQL_Helper = SQL_Helper
- self.api = URL('https://pixeldrain.com/api/')
async def fetch(self, session: ScrapeSession, url: URL):
+ """Director for pimpandhost scraping"""
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
album_obj = AlbumItem("Loose Pixeldrain Files", [])
@@ -32,6 +31,7 @@ class PimpAndHostCrawler:
return album_obj
async def get_listings(self, session: ScrapeSession, url: URL):
+ """Handles album media"""
media_items = []
try:
soup = await session.get_BS4(url)
@@ -51,6 +51,7 @@ class PimpAndHostCrawler:
logger.debug(e)
async def get_singular(self, session: ScrapeSession, url: URL):
+ """Handles singular files"""
try:
soup = await session.get_BS4(url)
img = soup.select_one("a img")
diff --git a/cyberdrop_dl/crawlers/PixelDrain_Spider.py b/cyberdrop_dl/crawlers/PixelDrain_Spider.py
index 4a1a2778e..d03044764 100644
--- a/cyberdrop_dl/crawlers/PixelDrain_Spider.py
+++ b/cyberdrop_dl/crawlers/PixelDrain_Spider.py
@@ -14,6 +14,7 @@ class PixelDrainCrawler:
self.api = URL('https://pixeldrain.com/api/')
async def fetch(self, session: ScrapeSession, url: URL):
+ """Director for pixeldrain scraping"""
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
album_obj = AlbumItem("Loose Pixeldrain Files", [])
@@ -37,6 +38,7 @@ class PixelDrainCrawler:
return album_obj
async def get_listings(self, session: ScrapeSession, identifier: str, url: URL):
+ """Handles album scraping"""
media_items = []
try:
content = await session.get_json((self.api / "list" / identifier))
@@ -59,10 +61,12 @@ class PixelDrainCrawler:
logger.debug(e)
async def get_file_name(self, session: ScrapeSession, identifier: str):
+ """Gets filename for the given file identifier"""
content = await session.get_json((self.api / 'file' / identifier / 'info'))
filename = content['name']
return filename
async def create_download_link(self, file: str):
+ """Gets download links for the file given"""
final_url = (self.api / 'file' / file).with_query('download')
return final_url
diff --git a/cyberdrop_dl/crawlers/PostImg_Spider.py b/cyberdrop_dl/crawlers/PostImg_Spider.py
index c5a755188..9745ccecd 100644
--- a/cyberdrop_dl/crawlers/PostImg_Spider.py
+++ b/cyberdrop_dl/crawlers/PostImg_Spider.py
@@ -13,6 +13,7 @@ class PostImgCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Director for PostImg scraping"""
album_obj = AlbumItem("Loose PostImg Files", [])
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
@@ -35,6 +36,7 @@ class PostImgCrawler:
return album_obj
async def get_folder(self, session: ScrapeSession, url: URL):
+ """Handles folder scraping"""
album = url.raw_name
data = {"action": "list", "album": album}
content = []
@@ -63,6 +65,7 @@ class PostImgCrawler:
return content
async def get_singular(self, session: ScrapeSession, url: URL):
+ """Handles singular folder scraping"""
soup = await session.get_BS4(url)
link = URL(soup.select_one("a[id=download]").get('href').replace("?dl=1", ""))
diff --git a/cyberdrop_dl/crawlers/Saint_Spider.py b/cyberdrop_dl/crawlers/Saint_Spider.py
index a2edd299a..f897af707 100644
--- a/cyberdrop_dl/crawlers/Saint_Spider.py
+++ b/cyberdrop_dl/crawlers/Saint_Spider.py
@@ -12,6 +12,7 @@ class SaintCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Basic director for saint scraping"""
album_obj = AlbumItem("Loose Saint Files", [])
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
diff --git a/cyberdrop_dl/crawlers/ShareX_Spider.py b/cyberdrop_dl/crawlers/ShareX_Spider.py
index 40226b661..0037f5006 100644
--- a/cyberdrop_dl/crawlers/ShareX_Spider.py
+++ b/cyberdrop_dl/crawlers/ShareX_Spider.py
@@ -17,6 +17,7 @@ class ShareXCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Director for ShareX scraper"""
domain_obj = DomainItem(url.host.lower(), {})
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
@@ -38,11 +39,12 @@ class ShareXCrawler:
await self.parse_profile(session, url, domain_obj)
url_path = await get_db_path(url)
- await self.SQL_Helper.insert_domain("gofile", url_path, domain_obj)
+ await self.SQL_Helper.insert_domain("sharex", url_path, domain_obj)
await log(f"[green]Finished: {str(url)}[/green]", quiet=self.quiet)
return domain_obj
async def get_albums(self, session: ScrapeSession, url: URL, domain_obj: DomainItem):
+ """Handles scraping for Albums"""
try:
soup = await session.get_BS4(url)
albums = soup.select("a[class='image-container --media']")
@@ -65,6 +67,7 @@ class ShareXCrawler:
logger.debug(e)
async def get_singular(self, session: ScrapeSession, url: URL, domain_obj: DomainItem):
+ """Handles scraping for singular files"""
await asyncio.sleep(1)
try:
soup = await session.get_BS4(url)
@@ -72,7 +75,7 @@ class ShareXCrawler:
link = link.with_name(link.name.replace('.md.', '.').replace('.th.', '.'))
url_path = await get_db_path(link)
- complete = await self.SQL_Helper.check_complete_singular("anonfiles", url_path)
+ complete = await self.SQL_Helper.check_complete_singular("sharex", url_path)
filename, ext = await get_filename_and_ext(link.name)
media_item = MediaItem(link, url, complete, filename, ext)
await domain_obj.add_media("Loose ShareX Files", media_item)
@@ -96,7 +99,7 @@ class ShareXCrawler:
logger.debug(e)
async def parse_profile(self, session: ScrapeSession, url: URL, domain_obj: DomainItem):
-
+ """Handles scraping for profiles"""
try:
soup = await session.get_BS4(url)
title = soup.select_one("div[class=header] h1 strong").get_text()
@@ -114,6 +117,7 @@ class ShareXCrawler:
logger.debug(e)
async def get_list_links(self, session: ScrapeSession, url: URL, title: str, domain_obj: DomainItem):
+ """Gets final links and adds to domain_obj"""
try:
soup = await session.get_BS4(url)
if url.host == 'jpg.fish' or url.host == 'jpg.church':
@@ -130,7 +134,7 @@ class ShareXCrawler:
logger.debug("Couldn't get extension for %s", str(link))
continue
url_path = await get_db_path(link)
- complete = await self.SQL_Helper.check_complete_singular("anonfiles", url_path)
+ complete = await self.SQL_Helper.check_complete_singular("sharex", url_path)
media_item = MediaItem(link, url, complete, filename, ext)
await domain_obj.add_media(title, media_item)
diff --git a/cyberdrop_dl/crawlers/XBunkr_Spider.py b/cyberdrop_dl/crawlers/XBunkr_Spider.py
index a991b847d..69bb71eb2 100644
--- a/cyberdrop_dl/crawlers/XBunkr_Spider.py
+++ b/cyberdrop_dl/crawlers/XBunkr_Spider.py
@@ -13,12 +13,13 @@ class XBunkrCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Director for XBunkr scraping"""
album_obj = AlbumItem("Loose XBunkr Files", [])
try:
if "media" in url.host:
url_path = await get_db_path(url)
- complete = await self.SQL_Helper.check_complete_singular("cyberdrop", url_path)
+ complete = await self.SQL_Helper.check_complete_singular("xbunkr", url_path)
filename, ext = await get_filename_and_ext(url.name)
media_item = MediaItem(url, url, complete, filename, ext)
await album_obj.add_media(media_item)
@@ -37,7 +38,7 @@ class XBunkrCrawler:
logger.debug("Couldn't get extension for %s", str(link))
continue
url_path = await get_db_path(link)
- complete = await self.SQL_Helper.check_complete_singular("anonfiles", url_path)
+ complete = await self.SQL_Helper.check_complete_singular("xbunkr", url_path)
media_item = MediaItem(link, url, complete, filename, ext)
await album_obj.add_media(media_item)
diff --git a/cyberdrop_dl/crawlers/Xenforo_Spider.py b/cyberdrop_dl/crawlers/Xenforo_Spider.py
index fa0af4782..9523c26df 100644
--- a/cyberdrop_dl/crawlers/Xenforo_Spider.py
+++ b/cyberdrop_dl/crawlers/Xenforo_Spider.py
@@ -40,6 +40,7 @@ class XenforoCrawler:
self.SQL_Helper = SQL_Helper
async def fetch(self, session: ScrapeSession, url: URL):
+ """Xenforo forum director"""
await log(f"[green]Starting: {str(url)}[/green]", quiet=self.quiet)
cascade = CascadeItem({})
@@ -67,6 +68,7 @@ class XenforoCrawler:
return cascade, title
async def simpcity_login(self, session: ScrapeSession, url: URL):
+ """Handles logging in for simpcity"""
if self.simpcity_username and self.simpcity_username:
if not self.simpcity_lock:
while True:
@@ -99,6 +101,7 @@ class XenforoCrawler:
raise FailedLoginFailure()
async def socialmediagirls_login(self, session: ScrapeSession, url: URL):
+ """Handles logging in for SMG"""
if self.socialmediagirls_username and self.socialmediagirls_username:
if self.socialmediagirls_lock:
while True:
@@ -131,6 +134,7 @@ class XenforoCrawler:
raise FailedLoginFailure()
async def xbunker_login(self, session: ScrapeSession, url: URL):
+ """Handles logging in for XBunker"""
if self.xbunker_username and self.xbunker_password:
if self.xbunker_lock:
while True:
@@ -163,6 +167,7 @@ class XenforoCrawler:
raise FailedLoginFailure()
async def get_thread_url_and_post_num(self, url: URL):
+ """Splits the thread url and returns the url and post number if provided"""
post_number = 0
if "post-" in str(url):
post_number_parts = str(url).rsplit("post-", 1)
@@ -171,6 +176,7 @@ class XenforoCrawler:
return url, post_number
async def get_links(self, post_content, selector, attribute, domain, temp_title):
+ """Grabs links from the post content based on the given selector and attribute"""
found_links = []
links = post_content.select(selector)
for link in links:
@@ -185,6 +191,7 @@ class XenforoCrawler:
return found_links
async def get_embedded(self, post_content, selector, attribute, domain, temp_title):
+ """Gets embedded media from post content based on selector and attribute provided"""
found_links = []
links = post_content.select(selector)
for link in links:
@@ -208,6 +215,8 @@ class XenforoCrawler:
return found_links
async def filter_content_links(self, cascade: CascadeItem, content_links: list, url: URL, domain: str):
+ """Splits given links into direct links and external links,
+ returns external links, adds internal to the cascade"""
forum_direct_urls = [x for x in content_links if x[0].host.replace(".st", ".su") in url.host]
content_links = [x for x in content_links if x not in forum_direct_urls]
for link_title_bundle in forum_direct_urls:
@@ -227,6 +236,7 @@ class XenforoCrawler:
return content_links
async def handle_external_links(self, content_links: list, referer: URL):
+ """Maps external links to the scraper class"""
tasks = []
for link_title_bundle in content_links:
link = link_title_bundle[0]
@@ -236,6 +246,7 @@ class XenforoCrawler:
async def parse_simpcity(self, session: ScrapeSession, url: URL, cascade: CascadeItem, title: str,
post_number: int):
+ """Parses simpcity threads"""
soup = await session.get_BS4(url)
domain = URL("https://" + url.host)
@@ -318,6 +329,7 @@ class XenforoCrawler:
async def parse_socialmediagirls(self, session: ScrapeSession, url: URL, cascade: CascadeItem, title: str,
post_number: int):
+ """Parses SMG threads"""
soup = await session.get_BS4(url)
domain = URL("https://" + url.host)
@@ -397,6 +409,7 @@ class XenforoCrawler:
async def parse_xbunker(self, session: ScrapeSession, url: URL, cascade: CascadeItem, title: str,
post_number: int):
+ """Parses XBunker threads"""
soup = await session.get_BS4(url)
domain = URL("https://" + url.host)
diff --git a/cyberdrop_dl/downloader/downloaders.py b/cyberdrop_dl/downloader/downloaders.py
index 02f8fec89..2df11017d 100644
--- a/cyberdrop_dl/downloader/downloaders.py
+++ b/cyberdrop_dl/downloader/downloaders.py
@@ -15,7 +15,8 @@ from yarl import URL
from .progress_definitions import get_forum_table, cascade_progress, domain_progress, album_progress, file_progress, \
forum_progress, get_cascade_table
-from cyberdrop_dl.base_functions.base_functions import log, logger, check_free_space, allowed_filetype, get_db_path
+from cyberdrop_dl.base_functions.base_functions import log, logger, check_free_space, allowed_filetype, get_db_path, \
+ clear
from cyberdrop_dl.base_functions.error_classes import DownloadFailure
from cyberdrop_dl.base_functions.sql_helper import SQLHelper
from cyberdrop_dl.base_functions.data_classes import AlbumItem, CascadeItem, FileLock, ForumItem, DomainItem, MediaItem
@@ -29,6 +30,7 @@ async def basic_auth(username, password):
def retry(f):
+ """This function is a wrapper that handles retrying for failed downloads"""
@wraps(f)
async def wrapper(self, *args, **kwargs):
while True:
@@ -51,6 +53,7 @@ def retry(f):
class Files:
+ """Class that keeps that of completed, skipped and failed files"""
def __init__(self):
self.completed_files = 0
self.skipped_files = 0
@@ -58,6 +61,7 @@ class Files:
class Downloader:
+ """Downloader class, directs downloading for domain objects"""
def __init__(self, args: dict, client: Client, SQL_Helper: SQLHelper, scraper: ScrapeMapper, max_workers: int,
domain: str, domain_obj: DomainItem, semaphore: asyncio.Semaphore, files: Files):
self.backup_scraper = scraper
@@ -97,6 +101,7 @@ class Downloader:
self.required_free_space = args["Runtime"]["required_free_space"]
async def start_domain(self, cascade_task: TaskID):
+ """Handler for domains and the progress bars for it"""
domain_task = domain_progress.add_task("[light_pink3]" + self.domain.upper(), progress_type="domain",
total=len(self.domain_obj.albums))
for album, album_obj in self.domain_obj.albums.items():
@@ -105,6 +110,7 @@ class Downloader:
domain_progress.update(domain_task, visible=False)
async def start_album(self, domain_task: TaskID, album: str, album_obj: AlbumItem):
+ """Handler for albums and the progress bars for it"""
if await album_obj.is_empty():
return
album_task = album_progress.add_task("[pink3]" + album.upper(), progress_type="album", total=len(album_obj.media))
@@ -116,6 +122,7 @@ class Downloader:
domain_progress.advance(domain_task, 1)
async def start_file(self, album_task: TaskID, album: str, media: MediaItem):
+ """Handler for files and the progress bars for it"""
if media.complete:
await log(f"Previously Downloaded: {media.filename}", quiet=True)
self.files.skipped_files += 1
@@ -135,6 +142,7 @@ class Downloader:
async def check_file_exists(self, complete_file, partial_file, media, album, url_path, original_filename,
current_throttle):
+ """Complicated checker for if a file already exists, and was already downloaded"""
expected_size = None
proceed = True
while True:
@@ -179,6 +187,7 @@ class Downloader:
@retry
async def download_file(self, album_task: TaskID, album: str, media: MediaItem):
+ """File downloader"""
if not await check_free_space(self.required_free_space, self.download_dir):
await log("We've run out of free space.", quiet=True)
self.files.skipped_files += 1
@@ -303,6 +312,7 @@ class Downloader:
async def download_cascade(args: dict, Cascade: CascadeItem, SQL_Helper: SQLHelper, client: Client,
scraper: ScrapeMapper) -> None:
+ """Handler for cascades and the progress bars for it"""
user_threads = args["Runtime"]["simultaneous_downloads"]
files = Files()
@@ -324,11 +334,13 @@ async def download_cascade(args: dict, Cascade: CascadeItem, SQL_Helper: SQLHelp
tasks.append(downloader.start_domain(cascade_task))
await asyncio.gather(*tasks)
+ await clear()
await log(f"| [green]Files Complete: {files.completed_files}[/green] - [yellow]Files Skipped: {files.skipped_files}[/yellow] - [red]Files Failed: {files.failed_files}[/red] |")
async def download_forums(args: dict, Forums: ForumItem, SQL_Helper: SQLHelper, client: Client,
scraper: ScrapeMapper) -> None:
+ """Handler for forum threads and the progress bars for it"""
user_threads = args["Runtime"]["simultaneous_downloads"]
files = Files()
@@ -352,6 +364,8 @@ async def download_forums(args: dict, Forums: ForumItem, SQL_Helper: SQLHelper,
for downloader in downloaders:
tasks.append(downloader.start_domain(cascade_task))
await asyncio.gather(*tasks)
+ cascade_progress.update(cascade_task, visible=False)
forum_progress.advance(forum_task, 1)
- await log("")
+
+ await clear()
await log(f"| [green]Files Complete: {files.completed_files}[/green] - [yellow]Files Skipped: {files.skipped_files}[/yellow] - [red]Files Failed: {files.failed_files}[/red] |")
diff --git a/cyberdrop_dl/downloader/progress_definitions.py b/cyberdrop_dl/downloader/progress_definitions.py
index 2a339ddb1..23eac5c4d 100644
--- a/cyberdrop_dl/downloader/progress_definitions.py
+++ b/cyberdrop_dl/downloader/progress_definitions.py
@@ -35,6 +35,7 @@ file_progress = Progress(SpinnerColumn(),
async def get_forum_table():
+ """Table creator for forum threads"""
progress_table = Table.grid(expand=True)
progress_table.add_row(Panel.fit(forum_progress, title="Total Thread", border_style="green", padding=(1, 1)))
progress_table.add_row(Panel.fit(cascade_progress, title="Current Thread", border_style="green", padding=(1, 1)))
@@ -45,6 +46,7 @@ async def get_forum_table():
async def get_cascade_table():
+ """Table creator for cascade objects"""
progress_table = Table.grid(expand=True)
progress_table.add_row(Panel.fit(cascade_progress, title="Current Thread", border_style="green", padding=(1, 1)))
progress_table.add_row(Panel.fit(domain_progress, title="Domains Being Downloaded", border_style="green", padding=(1, 1)))
diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.py
index 3c0b32d82..5e764052e 100644
--- a/cyberdrop_dl/main.py
+++ b/cyberdrop_dl/main.py
@@ -126,6 +126,7 @@ async def consolidate_links(args: dict, links: list) -> list:
async def scrape_links(scraper: ScrapeMapper, links: list, quiet=False) -> CascadeItem:
+ """Maps links from URLs.txt or command to the scraper class"""
await log("[green]Starting Scrape[/green]", quiet=quiet)
tasks = []
@@ -142,14 +143,6 @@ async def scrape_links(scraper: ScrapeMapper, links: list, quiet=False) -> Casca
return Cascade, Forums
-async def download(Cascade: CascadeItem, Forums: ForumItem):
- if not Cascade.is_empty():
- await log("[green]Downloading Loose Links[/green]")
-
- if not Forums.is_empty():
- await log("[green]Downloading Forum Threads[/green]")
-
-
async def director(args: dict, links: list) -> None:
"""This is the overarching director coordinator for CDL."""
await clear()
@@ -170,6 +163,7 @@ async def director(args: dict, links: list) -> None:
Cascade, Forums = await scrape_links(Scraper, links)
await asyncio.sleep(5)
await clear()
+
if not await Cascade.is_empty():
await download_cascade(args, Cascade, SQL_Helper, client, Scraper)
if not await Forums.is_empty():
diff --git a/cyberdrop_dl/scraper/JDownloader_Integration.py b/cyberdrop_dl/scraper/JDownloader_Integration.py
index c236946bf..fe4a425fe 100644
--- a/cyberdrop_dl/scraper/JDownloader_Integration.py
+++ b/cyberdrop_dl/scraper/JDownloader_Integration.py
@@ -8,6 +8,7 @@ from cyberdrop_dl.base_functions.error_classes import JDownloaderFailure
class JDownloader:
+ """Class that handles connecting and passing links to JDownloader"""
def __init__(self, jdownloader_args: dict, quiet: bool):
self.jdownloader_device = jdownloader_args['jdownloader_device']
self.jdownloader_username = jdownloader_args['jdownloader_username']
@@ -18,6 +19,7 @@ class JDownloader:
self.quiet = quiet
async def jdownloader_setup(self):
+ """Setup function for JDownloader"""
try:
if not self.jdownloader_username or not self.jdownloader_password or not self.jdownloader_device:
raise JDownloaderFailure("jdownloader credentials were not provided.")
@@ -30,6 +32,7 @@ class JDownloader:
self.jdownloader_enable = False
async def direct_unsupported_to_jdownloader(self, url: URL, title: str):
+ """Sends links to JDownloader"""
if self.jdownloader_enable:
if not self.jdownloader_agent:
await self.jdownloader_setup()
diff --git a/cyberdrop_dl/scraper/Scraper.py b/cyberdrop_dl/scraper/Scraper.py
index 45ece574e..20991b806 100644
--- a/cyberdrop_dl/scraper/Scraper.py
+++ b/cyberdrop_dl/scraper/Scraper.py
@@ -1,5 +1,4 @@
import asyncio
-import logging
from typing import Dict, Optional
import aiofiles
@@ -35,6 +34,7 @@ from cyberdrop_dl.scraper.JDownloader_Integration import JDownloader
class ScrapeMapper:
+ """This class maps links to their respective handlers, or JDownloader if they are unsupported"""
def __init__(self, args: Dict, client: Client, SQL_Helper: SQLHelper, quiet: bool):
self.args = args
self.client = client