Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Organize imports according to PEP 8
rdnkarchiverfb6dd157cb08
diff --git a/main.py b/main.pyindex 2a1ab0663..a13fb035c 100644--- a/main.py+++ b/main.py@@ -1,12 +1,19 @@-import loggingimport asyncio-import requests+import loggingimport os+from pathlib import Pathimport reimport warnings++from colorama import Fore, Style+import nest_asyncioimport readchar+import requests+import settings-import nest_asyncio+from utils.scraper import scrape+from utils.downloaders import get_downloaders+# Fixes reactor already installed error (issue using Scrapy with Asyncio)try:@@ -14,11 +21,6 @@ try:except Exception:pass-from pathlib import Path-from utils.scraper import scrape-from utils.downloaders import get_downloaders-from colorama import Fore, Style-logging.basicConfig(level=logging.DEBUG, filename='logs.log',format='%(asctime)s:%(levelname)s:%(module)s:%(filename)s:%(lineno)d:%(message)s',filemode='w')diff --git a/requirements.txt b/requirements.txtindex 0c7074f72..b5a84243a 100644--- a/requirements.txt+++ b/requirements.txt@@ -1,13 +1,12 @@-requests==2.27.1-colorama~=0.4.4-Scrapy~=2.6.0aiofiles~=0.8.0aiohttp~=3.8.1-tqdm==4.63.0-sanitize-filename~=1.2.0-readchar~=3.0.4certifi~=2021.10.8-nest-asyncio~=1.5.4-asyncio~=3.4.3-yarl~=1.7.2+colorama~=0.4.4gofile-client~=1.0.0+nest-asyncio~=1.5.4+readchar~=3.0.4+requests==2.27.1+sanitize-filename~=1.2.0+Scrapy~=2.6.0+tqdm==4.63.0+yarl~=1.7.2\ No newline at end of filediff --git a/utils/crawlers/Chibisafe_Spider.py b/utils/crawlers/Chibisafe_Spider.pyindex cf2cf0c7d..df2fbbf18 100644--- a/utils/crawlers/Chibisafe_Spider.py+++ b/utils/crawlers/Chibisafe_Spider.py@@ -1,10 +1,11 @@import re-import settings+from urllib.parse import urlparse-from scrapy import signals, Spider+from scrapy import Spiderfrom scrapy.http.request import Request-from urllib.parse import urlparse-from urllib.parse import urljoin++import settings+title_setting = settings.include_id_in_download_folder_namediff --git a/utils/crawlers/Erome_Spider.py b/utils/crawlers/Erome_Spider.pyindex d09dda5c2..b00256450 100644--- a/utils/crawlers/Erome_Spider.py+++ b/utils/crawlers/Erome_Spider.py@@ -1,9 +1,12 @@-from scrapy import signals, Spider-from scrapy.http.request import Request-from urllib.parse import urlparseimport re+from urllib.parse import urlparse++from scrapy import Spider+from scrapy.http.request import Request+import settings+title_setting = settings.include_id_in_download_folder_namediff --git a/utils/crawlers/GoFile_Spider.py b/utils/crawlers/GoFile_Spider.pyindex 06c47adb5..1d4170833 100644--- a/utils/crawlers/GoFile_Spider.py+++ b/utils/crawlers/GoFile_Spider.py@@ -1,4 +1,5 @@from typing import Union+from gofile import Gofile# import settingsdiff --git a/utils/crawlers/ShareX_Spider.py b/utils/crawlers/ShareX_Spider.pyindex ca94eb568..543d4ddbd 100644--- a/utils/crawlers/ShareX_Spider.py+++ b/utils/crawlers/ShareX_Spider.py@@ -1,9 +1,12 @@-from scrapy import signals, Spider-from scrapy.http.request import Request-from urllib.parse import urlparseimport re+from urllib.parse import urlparse++from scrapy import Spider+from scrapy.http.request import Request+import settings+title_setting = settings.include_id_in_download_folder_namediff --git a/utils/downloaders.py b/utils/downloaders.pyindex ff36494cc..6cff84706 100644--- a/utils/downloaders.py+++ b/utils/downloaders.py@@ -1,28 +1,26 @@import asyncio+from functools import wrapsimport http+import loggingimport multiprocessing+from pathlib import Path+import sslimport timeimport traceback-import typing+from typing import Any, cast, Callable, Iterable, Optional, Type, TypeVar, Unionimport aiofilesimport aiofiles.osimport aiohttpimport aiohttp.client_exceptions-import logging-import sslimport certifi+from colorama import Fore, Style+from sanitize_filename import sanitize+from tqdm import tqdmimport yarlimport settings-from functools import wraps-from pathlib import Path-from typing import Any, Callable, Iterable, List, Optional, Type, TypeVar, Union, cast, Dict-from requests.structures import CaseInsensitiveDict-from tqdm import tqdm-from colorama import Fore, Style-from sanitize_filename import sanitize-from http.cookies import SimpleCookie+asyncio.get_event_loop()logger = logging.getLogger(__name__)@@ -91,7 +89,7 @@ async def throttle(self, url: yarl.URL) -> None:if delay is None:return- key: typing.Optional[str] = None+ key: Optional[str] = Nonewhile True:if key is None:key = 'throttle:{}'.format(host)@@ -111,7 +109,7 @@ async def throttle(self, url: yarl.URL) -> None:class Downloader:- def __init__(self, links: List[List[str]], morsels, folder: Path, title: str, max_workers: int):+ def __init__(self, links: list[list[str]], morsels, folder: Path, title: str, max_workers: int):self.links = linksself.morsels = morselsself.folder = folder@@ -206,7 +204,7 @@ class Downloader:async def download_all(self,- links: Iterable[List[str]],+ links: Iterable[list[str]],session: aiohttp.ClientSession,show_progress: bool = True) -> None:@@ -245,7 +243,7 @@ def simple_cookies(cookies):return morsels-def get_downloaders(urls: Dict[str, Dict[str, List[str]]], cookies: Iterable[str], folder: Path) -> List[Downloader]:+def get_downloaders(urls: dict[str, dict[str, list[str]]], cookies: Iterable[str], folder: Path) -> 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 todiff --git a/utils/scraper.py b/utils/scraper.pyindex c55d2dc94..b68369199 100644--- a/utils/scraper.py+++ b/utils/scraper.py@@ -1,18 +1,21 @@-from scrapy import signals, Spider-from scrapy.crawler import CrawlerProcess-from scrapy.utils.project import get_project_settings-from scrapy.signalmanager import dispatcher-from urllib.parse import urlparse-import logging-from colorama import Fore, Stylefrom collections import OrderedDict+import loggingimport re+from urllib.parse import urlparse++from colorama import Fore, Style+from scrapy import signals+from scrapy.crawler import CrawlerProcess+from scrapy.signalmanager import dispatcher+from scrapy.utils.project import get_project_settings+import settingsfrom utils.crawlers.ShareX_Spider import ShareX_Spiderfrom utils.crawlers.Erome_Spider import Erome_Spiderfrom utils.crawlers.Chibisafe_Spider import Chibisafe_Spiderfrom utils.crawlers.GoFile_Spider import GofileCrawler+logger = logging.getLogger(__name__)title_setting = settings.include_id_in_download_folder_name