Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
create variable for current bunkr domain instead of specifying explicitly in multiple places, will make changes easier in the future
Jules-WinnfieldXc408231926b6
diff --git a/cyberdrop_dl/crawlers/Bunkr_Spider.py b/cyberdrop_dl/crawlers/Bunkr_Spider.pyindex 92ee16058..37d5dd810 100644--- a/cyberdrop_dl/crawlers/Bunkr_Spider.py+++ b/cyberdrop_dl/crawlers/Bunkr_Spider.py@@ -32,12 +32,14 @@ class BunkrCrawler:self.error_writer = error_writer+ self.primary_base_domain = URL("https://bunkrr.su")+async def fetch(self, session: ScrapeSession, url: URL) -> AlbumItem:"""Scraper for Bunkr"""album_obj = AlbumItem("Loose Bunkr Files", [])log(f"Starting: {url}", quiet=self.quiet, style="green")- url = BunkrCrawler.get_stream_link(url)+ url = await self.get_stream_link(url)if "v" in url.parts or "d" in url.parts:media = await self.get_file(session, url)@@ -77,6 +79,25 @@ class BunkrCrawler:log(f"Finished: {url}", quiet=self.quiet, style="green")return album_obj+ async def get_stream_link(self, url: URL):+ cdn_possibilities = r"^(?:media-files|cdn|c)[0-9]{0,2}\.bunkrr?\.[a-z]{2,3}$"++ if not re.match(cdn_possibilities, url.host):+ return url++ ext = url.suffix.lower()+ if ext == "":+ return url++ if ext in FILE_FORMATS['Images']:+ url = url.with_host(re.sub(r"^cdn(\d*)\.", r"i\1.", url.host))+ elif ext in FILE_FORMATS['Videos']:+ url = self.primary_base_domain / "v" / url.parts[-1]+ else:+ url = self.primary_base_domain / "d" / url.parts[-1]++ return url+async def remove_id(self, filename: str, ext: str):"""Removes the additional string bunkr adds to the end of every filename"""original_filename = filename@@ -97,8 +118,7 @@ class BunkrCrawler:async def get_file(self, session: ScrapeSession, url: URL):"""Gets the media item from the supplied url"""- ### Temp Fix ###- url = url.with_host("bunkrr.su")+ url = self.primary_base_domain.with_path(url.path)try:async with self.limiter:@@ -157,7 +177,7 @@ class BunkrCrawler:if link.startswith("/"):link = URL("https://" + url.host + link)link = URL(link)- referer = BunkrCrawler.get_stream_link(link)+ referer = await self.get_stream_link(link)try:filename, ext = await get_filename_and_ext(link.name)@@ -186,25 +206,3 @@ class BunkrCrawler:await self.error_writer.write_errored_scrape(url, e, self.quiet)return album-- @staticmethod- def get_stream_link(url: URL):- cdn_possibilities = r"^(?:media-files|cdn|c)[0-9]{0,2}\.bunkrr?\.[a-z]{2,3}$"-- if not re.match(cdn_possibilities, url.host):- return url-- ext = url.suffix.lower()- if ext == "":- return url-- if ext in FILE_FORMATS['Images']:- url = url.with_host(re.sub(r"^cdn(\d*)\.", r"i\1.", url.host))- elif ext in FILE_FORMATS['Videos']:- url = url.with_host('bunkrr.su')- url = url.with_path(os.path.join('/v', url.path[1:]))- else:- url = url.with_host('bunkrr.su')- url = url.with_path(os.path.join('/d', url.path[1:]))-- return urldiff --git a/tests/test_crawlers_bunkr_spider.py b/tests/test_crawlers_bunkr_spider.pydeleted file mode 100644index 2101d608a..000000000--- a/tests/test_crawlers_bunkr_spider.py+++ /dev/null@@ -1,49 +0,0 @@-import unittest-from yarl import URL--from cyberdrop_dl.crawlers.Bunkr_Spider import BunkrCrawler--# Run with: python3 -m unittest ./tests/test_crawlers_bunkr_spider.py-class TestBunkrCrawler(unittest.TestCase):- def assertExpectedURL(self, origURL, newURL):- self.assertEqual(BunkrCrawler.get_stream_link(URL(origURL)), URL(newURL))-- def test_get_stream_link_no_extension(self):- """Test that URLs with an unknown extension are returned without changing- """- self.assertExpectedURL("https://bunkr.ru/unknown-GT2Awd69m", "https://bunkr.ru/unknown-GT2Awd69m")- self.assertExpectedURL("https://bunkrr.su/unknown-GT2Awd69m", "https://bunkrr.su/unknown-GT2Awd69m")-- def test_get_stream_link_other_extension(self):- """Test that URLs with an extension other than video, audio, and image are changed correctly- """- self.assertExpectedURL("https://c.bunkr.ru/doc-GT2Awd69m.txt", "https://bunkrr.su/d/doc-GT2Awd69m.txt")- self.assertExpectedURL("https://media-files7.bunkr.ru/doc-GT2Awd69m.txt", "https://bunkrr.su/d/doc-GT2Awd69m.txt")-- def test_get_stream_link_caps_extension(self):- """Test that URLs with a capital file extension are changed correctly- """- self.assertExpectedURL("https://cdn.bunkr.ru/vid-GT2Awd69m.MP4", "https://bunkrr.su/v/vid-GT2Awd69m.MP4")- self.assertExpectedURL("https://cdn9.bunkrr.su/vid-GT2Awd69m.MP4", "https://bunkrr.su/v/vid-GT2Awd69m.MP4")-- def test_get_stream_link_image_extension(self):- """Test that URLs with an image file extension are changed correctly-- Image URLs do not have their domain updated except for changing "cdn" to "i" in the first part of the hostname- """- self.assertExpectedURL("https://cdn5.bunkr.la/pic-GT2Awd69m.jpg", "https://i5.bunkr.la/pic-GT2Awd69m.jpg")- self.assertExpectedURL("https://i5.bunkr.la/pic-GT2Awd69m.jpg", "https://i5.bunkr.la/pic-GT2Awd69m.jpg")- self.assertExpectedURL("https://i.bunkr.ru/pic-GT2Awd69m.jpg", "https://i.bunkr.ru/pic-GT2Awd69m.jpg")- self.assertExpectedURL("https://cdn9.bunkrr.su/pic-GT2Awd69m.JPG", "https://i9.bunkrr.su/pic-GT2Awd69m.JPG")-- def test_get_stream_link_video_extension(self):- """Test that URLs with a video extension are changed correctly- """- self.assertExpectedURL("https://c9.bunkrr.su/vid-GT2Awd69m.mp4", "https://bunkrr.su/v/vid-GT2Awd69m.mp4")- self.assertExpectedURL("https://c9.bunkr.ru/vid-GT2Awd69m.mp4", "https://bunkrr.su/v/vid-GT2Awd69m.mp4")- self.assertExpectedURL("https://bunkrr.su/v/vid-GT2Awd69m.mp4", "https://bunkrr.su/v/vid-GT2Awd69m.mp4")- self.assertExpectedURL("https://media-files9.bunkr.is/vid-GT2Awd69m.mp4", "https://bunkrr.su/v/vid-GT2Awd69m.mp4")- self.assertExpectedURL("https://bunkrr.su/v/vid-GT2Awd69m.mp4", "https://bunkrr.su/v/vid-GT2Awd69m.mp4")--if __name__ == '__main__':- unittest.main()