Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Use contextlib.suppress instead of try-except-pass (#433)
Arkadiy Illarionovd1c32ae0f41b
diff --git a/cyberdrop_dl/crawlers/CyberFile_Spider.py b/cyberdrop_dl/crawlers/CyberFile_Spider.pyindex b88beb55d..ab5ef0933 100644--- a/cyberdrop_dl/crawlers/CyberFile_Spider.py+++ b/cyberdrop_dl/crawlers/CyberFile_Spider.py@@ -1,3 +1,4 @@+import contextlibfrom bs4 import BeautifulSoupfrom yarl import URL@@ -80,14 +81,11 @@ class CyberFileCrawler:total_pages = int(soup.select("a[onclick*=loadImages]")[-1].get('onclick').split(',')[2])listings = soup.select("div[class=fileListing] div")for listing in listings:- try:+ with contextlib.suppress(TypeError):nodes.append(int(listing.get('folderid')))- except TypeError:- pass- try:++ with contextlib.suppress(TypeError):contents.append((title, int(listing.get('fileid'))))- except TypeError:- passif page < total_pages:contents.extend(await self.get_folder_content(session, url, nodeId, page+1, original_title))@@ -139,15 +137,12 @@ class CyberFileCrawler:listings = soup.select("div[class=fileListing] div")for listing in listings:title = await make_title_safe(content['page_title'])- try:+ with contextlib.suppress(TypeError, AttributeError):title = title + '/' + await make_title_safe(listing.select_one('span[class=filename]').text)nodes.append((title, int(listing.get('folderid'))))- except (TypeError, AttributeError):- pass- try:++ with contextlib.suppress(TypeError):contents.append((title, int(listing.get('fileid'))))- except TypeError:- passif page < total_pages:nodes_temp, content_temp = await self.get_shared_ids_and_content(session, url, page + 1)@@ -177,16 +172,13 @@ class CyberFileCrawler:total_pages = int(soup.select("a[onclick*=loadImages]")[-1].get('onclick').split(',')[2])listings = soup.select("div[class=fileListing] div")for listing in listings:- try:+ with contextlib.suppress(TypeError, AttributeError):filename = listing.select_one('span[class=filename]')temp_title = title + '/' + await make_title_safe(filename.text)nodes.append((temp_title, int(listing.get('folderid'))))- except (TypeError, AttributeError):- pass- try:++ with contextlib.suppress(TypeError):contents.append((title, int(listing.get('fileid'))))- except TypeError:- passif page < total_pages:contents.extend(await self.get_shared_content(session, url, nodeId, page + 1, title))diff --git a/cyberdrop_dl/downloader/downloaders.py b/cyberdrop_dl/downloader/downloaders.pyindex 024261a63..a75774652 100644--- a/cyberdrop_dl/downloader/downloaders.py+++ b/cyberdrop_dl/downloader/downloaders.py@@ -1,6 +1,7 @@from __future__ import annotationsimport asyncio+import contextlibimport itertoolsimport loggingfrom http import HTTPStatus@@ -250,10 +251,8 @@ class Downloader:if await self.File_Lock.check_lock(filename):await self.File_Lock.remove_lock(filename)- try:+ with contextlib.suppress(Exception):file_progress.update(file_task, visible=False)- except Exception:- passif hasattr(e, "message"):logging.debug(f"\n{media.url} ({e.message})")diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex b6db4c618..b5260cac9 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -1,5 +1,6 @@import argparseimport asyncio+import contextlibimport loggingimport refrom pathlib import Path@@ -294,11 +295,9 @@ def main(args=None):filemode="w")- try:+ with contextlib.suppress(RuntimeError):loop = asyncio.get_event_loop()loop.run_until_complete(director(args, links))- except RuntimeError:- passif __name__ == '__main__':