Skip to content

Bulk asynchronous downloader for multiple file hosts

Fix bunkr scraping

Jules-WinnfieldXf8c0c56a9ab0
diff --git a/cyberdrop_dl/__init__.py b/cyberdrop_dl/__init__.py
index def8f78cd..fa0a80142 100644
--- a/cyberdrop_dl/__init__.py
+++ b/cyberdrop_dl/__init__.py
@@ -1 +1 @@
-__version__ = "2.23.1"
+__version__ = "2.23.2"
diff --git a/cyberdrop_dl/utils/crawlers/Bunkr_Spider.py b/cyberdrop_dl/utils/crawlers/Bunkr_Spider.py
index 0b5d489d1..7c954945d 100644
--- a/cyberdrop_dl/utils/crawlers/Bunkr_Spider.py
+++ b/cyberdrop_dl/utils/crawlers/Bunkr_Spider.py
@@ -3,7 +3,7 @@ from colorama import Fore
from yarl import URL
import json
-from ..base_functions import log, logger, make_title_safe, ssl_context, check_direct
+from ..base_functions import log, logger, make_title_safe, ssl_context, check_direct, FILE_FORMATS
from ..data_classes import DomainItem
@@ -19,20 +19,10 @@ class BunkrCrawler():
return domain_obj
if "stream.bunkr." in url.host:
- try:
- async with session.get(url, ssl=ssl_context) as response:
- text = await response.text()
- soup = BeautifulSoup(text, 'html.parser')
- link = soup.select_one("a[id=downloadBtn]").get('href')
- await domain_obj.add_to_album("Bunkr Loose Files", URL(link), url)
-
- await log("Finished scrape of " + str(url), Fore.WHITE)
- return domain_obj
-
- except Exception as e:
- logger.debug("Error encountered while handling %s", str(url), exc_info=True)
- await log("Error scraping " + str(url))
- logger.debug(e)
+ link = await self.stream(session, url)
+ await domain_obj.add_to_album(link=link, referral=url, title="Bunkr Loose Files")
+ await log("Finished scrape of " + str(url), Fore.WHITE)
+ return domain_obj
await log("Starting scrape of " + str(url), Fore.WHITE)
@@ -40,7 +30,6 @@ class BunkrCrawler():
async with session.get(url, ssl=ssl_context) as response:
text = await response.text()
soup = BeautifulSoup(text, 'html.parser')
-
build_id = json.loads(soup.select_one("script[id=__NEXT_DATA__]").get_text())
json_fetch = URL("https://" + url.host + "/_next/data/" + build_id['buildId'] + url.path + '.json')
@@ -49,10 +38,11 @@ class BunkrCrawler():
json_obj = json.loads(text)['pageProps']
title = await make_title_safe(json_obj['album']['name'])
for file in json_obj['files']:
- if 'video' in file['type']:
- link = URL(file['node_mediafiles'] + '/' + file['name'])
+ ext = '.' + file['name'].split('.')[-1].lower()
+ if ext in FILE_FORMATS['Videos']:
+ link = await self.stream(session, URL("https://stream.bunkr.is/v/" + file['name']))
else:
- link = URL(file['node_cdn'] + '/' + file['name'])
+ link = URL(file['cdn'] + '/' + file['name'])
await domain_obj.add_to_album(title, link, url)
except Exception as e:
@@ -63,3 +53,20 @@ class BunkrCrawler():
await log("Finished scrape of " + str(url), Fore.WHITE)
return domain_obj
+
+ async def stream(self, session, url):
+ try:
+ async with session.get(url, ssl=ssl_context) as response:
+ text = await response.text()
+ soup = BeautifulSoup(text, 'html.parser')
+ json_obj = json.loads(soup.select_one("script[id=__NEXT_DATA__]").text)
+ if not json_obj['props']['pageProps']:
+ link = URL('https://media-files.bunkr.is/' + url.name)
+ else:
+ link = URL(json_obj['props']['pageProps']['file']['mediafiles'] + '/' + json_obj['props']['pageProps']['file']['name'])
+ return link
+
+ except Exception as e:
+ logger.debug("Error encountered while handling %s", str(url), exc_info=True)
+ await log("Error scraping " + str(url))
+ logger.debug(e)
\ No newline at end of file
diff --git a/cyberdrop_dl/utils/crawlers/GoFile_Spider.py b/cyberdrop_dl/utils/crawlers/GoFile_Spider.py
index 287b024b3..b4981a21e 100644
--- a/cyberdrop_dl/utils/crawlers/GoFile_Spider.py
+++ b/cyberdrop_dl/utils/crawlers/GoFile_Spider.py
@@ -40,8 +40,9 @@ class GofileCrawler():
content_id = url.name if url.host == 'gofile.io' else url
try:
content = self.client.get_content(content_id)
- except:
+ except Exception as e:
await log("Error scraping " + str(url))
+ await log(e)
return
if not content:
return
diff --git a/cyberdrop_dl/utils/data_classes.py b/cyberdrop_dl/utils/data_classes.py
index 0d07a8b92..aa3763070 100644
--- a/cyberdrop_dl/utils/data_classes.py
+++ b/cyberdrop_dl/utils/data_classes.py
@@ -46,8 +46,7 @@ class DomainItem:
if title in self.albums.keys():
await self.albums[title].add_link_pair(link, referral)
else:
- self.albums[title] = AlbumItem(
- title=title, link_pairs=[(link, referral)])
+ self.albums[title] = AlbumItem(title=title, link_pairs=[(link, referral)])
async def add_album(self, title: str, album: AlbumItem):
if title in self.albums.keys():
@@ -85,8 +84,7 @@ class CascadeItem:
if domain in self.domains.keys():
await self.domains[domain].add_to_album(title, link, referral)
else:
- self.domains[domain] = DomainItem(
- domain, {title: AlbumItem(title, [(link, referral)])})
+ self.domains[domain] = DomainItem(domain, {title: AlbumItem(title, [(link, referral)])})
async def add_album(self, domain: str, title: str, album: AlbumItem):
if domain in self.domains.keys():