Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Moved bunkr URL fixing to scraper
Jules-WinnfieldX7b614f6d606c
diff --git a/utils/crawlers/Chibisafe_Spider.py b/utils/crawlers/Chibisafe_Spider.pyindex 32fe9839a..cf2cf0c7d 100644--- a/utils/crawlers/Chibisafe_Spider.py+++ b/utils/crawlers/Chibisafe_Spider.py@@ -1,8 +1,10 @@+import re+import settings+from scrapy import signals, Spiderfrom scrapy.http.request import Requestfrom urllib.parse import urlparse-import re-import settings+from urllib.parse import urljointitle_setting = settings.include_id_in_download_folder_name@@ -25,6 +27,19 @@ FILE_FORMATS = {}+def bunkr_parse(url: str) -> str:+ """Fix the URL for bunkr.is and construct the headers."""+ extension = '.' + url.split('.')[-1]+ if extension.lower() in FILE_FORMATS['Videos']:+ changed_url = url.replace('cdn.bunkr', 'media-files.bunkr').split('/')+ changed_url = ''.join(map(lambda x: urljoin('/', x), changed_url))+ return changed_url+ if extension.lower() in FILE_FORMATS['Images']:+ changed_url = url.replace('i.bunkr', 'cdn.bunkr')+ return changed_url+ return url++class Chibisafe_Spider(Spider):name = 'Chibisafe'@@ -45,13 +60,13 @@ class Chibisafe_Spider(Spider):def individual_file(self, response):netloc = urlparse(response.url).netloc.replace('www.', '')title = "Chibisafe Loose Files"- yield {'netloc': netloc, 'url': response.url, 'title': title, 'referal': response.url, 'cookies': ''}+ yield {'netloc': netloc, 'url': bunkr_parse(response.url), 'title': title, 'referal': response.url, 'cookies': ''}def individual_bunkr_video(self, response):netloc = urlparse(response.url).netloc.replace('www.', '')title = "Chibisafe Loose Files"link = response.url.replace('stream.bunkr.is/v/', 'media-files.bunkr.is/')- yield {'netloc': netloc, 'url': link, 'title': title, 'referal': response.url, 'cookies': ''}+ yield {'netloc': netloc, 'url': bunkr_parse(link), 'title': title, 'referal': response.url, 'cookies': ''}def parse(self, response, **kwargs):links = response.css('a[class=image]::attr(href)').getall()@@ -67,4 +82,4 @@ class Chibisafe_Spider(Spider):for link in links:netloc = urlparse(link).netloc.replace('www.', '')- yield {'netloc': netloc, 'url': link, 'title': title, 'referal': response.url, 'cookies': ''}\ No newline at end of file+ yield {'netloc': netloc, 'url': bunkr_parse(link), 'title': title, 'referal': response.url, 'cookies': ''}\ No newline at end of filediff --git a/utils/downloaders.py b/utils/downloaders.pyindex b6cec1f99..8f69043c0 100644--- a/utils/downloaders.py+++ b/utils/downloaders.py@@ -2,25 +2,23 @@ import asyncioimport httpimport timeimport typing-from functools import wraps-from pathlib import Path-from typing import Any, Callable, Iterable, List, Optional, Type, TypeVar, Union, cast, Dict-from urllib.parse import urljoinimport aiofilesimport aiofiles.osimport aiohttpimport aiohttp.client_exceptions+import logging+import settings+import multiprocessing+import yarl++from functools import wraps+from pathlib import Path+from typing import Any, Callable, Iterable, List, Optional, Type, TypeVar, Union, cast, Dictfrom requests.structures import CaseInsensitiveDictfrom tqdm import tqdm-import loggingfrom colorama import Fore, Stylefrom sanitize_filename import sanitize-import ssl-import certififrom http.cookies import SimpleCookie-import settings-import multiprocessing-import yarlasyncio.get_event_loop()@@ -126,19 +124,6 @@ class Downloader:self.delay = {'media-files.bunkr.is': 2}self.state = {}- @staticmethod- def bunkr_parse(url: str) -> str:- """Fix the URL for bunkr.is and construct the headers."""- extension = '.' + url.split('.')[-1]- if extension.lower() in FILE_FORMATS['Videos']:- changed_url = url.replace('cdn.bunkr', 'media-files.bunkr').split('/')- changed_url = ''.join(map(lambda x: urljoin('/', x), changed_url))- return changed_url- if extension.lower() in FILE_FORMATS['Images']:- changed_url = url.replace('i.bunkr', 'cdn.bunkr')- return changed_url- return url-"""Changed from aiohttp exceptions caught to FailureException to allow for partial downloads."""@retry(attempts=settings.download_attempts, timeout=4, exceptions=FailureException)async def download_file(@@ -154,12 +139,8 @@ class Downloader:temp_file = (self.folder / self.title / filename).with_suffix(".download")resume_point = 0downloaded = bytearray()- ssl_context = ssl.create_default_context(cafile=certifi.where())user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36'- if 'bunkr' in url:- url = self.bunkr_parse(url)-headers = {'Referer': referal, 'user-agent': user_agent}if temp_file.exists():@@ -169,7 +150,7 @@ class Downloader:try:async with self._semaphore:await throttle(self, yarl.URL(url))- resp = await session.get(url, headers=headers, ssl=ssl_context, raise_for_status=True)+ resp = await session.get(url, headers=headers, raise_for_status=True)total = int(resp.headers.get('Content-Length', 0)) + resume_pointwith tqdm(total=total, unit_scale=True,