Skip to content

Bulk asynchronous downloader for multiple file hosts

Overhaul gofile scraper to use API

rdnkarchiver99de3ff6b58c
diff --git a/requirements.txt b/requirements.txt
index d0db8d620..0c7074f72 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -7,8 +7,7 @@ tqdm==4.63.0
sanitize-filename~=1.2.0
readchar~=3.0.4
certifi~=2021.10.8
-selenium==4.1.3
-chromedriver_autoinstaller~=0.3.1
nest-asyncio~=1.5.4
asyncio~=3.4.3
-yarl~=1.7.2
\ No newline at end of file
+yarl~=1.7.2
+gofile-client~=1.0.0
diff --git a/utils/crawlers/GoFile_Spider.py b/utils/crawlers/GoFile_Spider.py
index c34cedd64..080d85fab 100644
--- a/utils/crawlers/GoFile_Spider.py
+++ b/utils/crawlers/GoFile_Spider.py
@@ -1,65 +1,34 @@
-from scrapy import signals, Spider
-from scrapy.http.request import Request
-from urllib.parse import urlparse
-import chromedriver_autoinstaller
-from selenium import webdriver
-from selenium.webdriver.common.by import By
-from selenium.webdriver.support import expected_conditions as EC
-from selenium.webdriver.support.wait import WebDriverWait
-from selenium.webdriver.chrome.options import Options
-import re
-import settings
+from typing import Union
-title_setting = settings.include_id_in_download_folder_name
+from gofile import Gofile
+# import settings
-class GoFile_Spider(Spider):
- name = 'GoFile'
- def __init__(self, *args, **kwargs):
- self.myurls = kwargs.get('myurls', [])
- chromedriver_autoinstaller.install()
- chrome_options = Options()
- chrome_options.add_argument("--headless")
- self.driver = webdriver.Chrome(options=chrome_options)
- super(GoFile_Spider, self).__init__(*args, **kwargs)
+# title_setting = settings.include_id_in_download_folder_name
- def start_requests(self):
- for url in self.myurls:
- yield Request(url, self.parse)
-
- def parse(self, response, **kwargs):
- self.driver.get(response.url)
- element = WebDriverWait(self.driver, 10).until(
- EC.presence_of_element_located((By.ID, 'contentId-download'))
- )
- cookies = self.driver.get_cookies()
- folder_links = self.driver.find_elements(By.CSS_SELECTOR, "div[class='col-md text-center text-md-right'] a[class=ajaxLink]")
- links = self.driver.find_elements(By.XPATH, "//button[@id='contentId-download']/..")
-
- try:
- title = self.driver.find_element(By.ID, 'rowFolder-folderName').text
- if title_setting:
- title = title + " - " + response.url.split('/')[-1]
- title = re.sub(r'[/]', "-", title)
- except Exception as e:
- title = response.url.split('/')[-1]
- try:
- og_title = response.meta.get('title')
- title = og_title + "/" + title
- except:
- pass
-
- for folder_link in folder_links:
- link = folder_link.get_attribute("href")
- yield Request(link, self.parse, meta={'title': title})
+class GofileCrawler():
+ def __init__(self, **kwargs):
+ self.client = Gofile()
+ self.links: list[str] = kwargs.get("links", [])
+ def build_targets(self, targets = {}, **kwargs):
+ links = kwargs.get("links", self.links)
for link in links:
- link = link.get_attribute("href")
- if link is None:
+ content_id = link.split("/")[-1] if link.startswith("https://gofile.io/") else link
+ content = self.client.get_content(content_id)
+ if not content:
continue
- netloc = urlparse(link).netloc.replace('www.', '')
- yield {'netloc': netloc, 'url': link, 'title': title, 'referal': response.url, 'cookies': cookies}
- def closed(self, reason):
- self.driver.close()
\ No newline at end of file
+ title = content["name"]
+ targets[title] = []
+ contents: dict[str, dict[str, Union[str, int]]] = content["contents"]
+ for val in contents.values():
+ if val["type"] == "folder":
+ self.build_targets(targets, links=[val["code"]])
+ else:
+ targets[title].append([
+ val["link"] if val["link"] != "overloaded" else val["directLink"],
+ 'https://gofile.io/',
+ ])
+ return targets
diff --git a/utils/downloaders.py b/utils/downloaders.py
index 840747d9f..ff36494cc 100644
--- a/utils/downloaders.py
+++ b/utils/downloaders.py
@@ -232,10 +232,14 @@ def simple_cookies(cookies):
# https://docs.python.org/3/library/http.cookies.html#morsel-objects
morsel = http.cookies.Morsel()
morsel.set(cookie["name"], cookie["value"], cookie["value"])
- morsel["domain"] = cookie["domain"]
- morsel["httponly"] = cookie["httpOnly"]
- morsel["path"] = cookie["path"]
- morsel["secure"] = cookie["secure"]
+ if "domain" in cookie:
+ morsel["domain"] = cookie["domain"]
+ if "httpOnly" in cookie:
+ morsel["httponly"] = cookie["httpOnly"]
+ if "path" in cookie:
+ morsel["path"] = cookie["path"]
+ if "secure" in cookie:
+ morsel["secure"] = cookie["secure"]
morsels[cookie["name"]] = morsel
return morsels
diff --git a/utils/scraper.py b/utils/scraper.py
index 3f9262341..c55d2dc94 100644
--- a/utils/scraper.py
+++ b/utils/scraper.py
@@ -11,7 +11,7 @@ import settings
from utils.crawlers.ShareX_Spider import ShareX_Spider
from utils.crawlers.Erome_Spider import Erome_Spider
from utils.crawlers.Chibisafe_Spider import Chibisafe_Spider
-from utils.crawlers.GoFile_Spider import GoFile_Spider
+from utils.crawlers.GoFile_Spider import GofileCrawler
logger = logging.getLogger(__name__)
title_setting = settings.include_id_in_download_folder_name
@@ -144,7 +144,12 @@ def scrape(urls):
if Erome_urls:
process.crawl(Erome_Spider, myurls=Erome_urls)
if GoFile_urls:
- process.crawl(GoFile_Spider, myurls=GoFile_urls)
+ gofile_crawler = GofileCrawler(links=GoFile_urls)
+ result_links.setdefault('gofile.io', gofile_crawler.build_targets())
+ cookies.append({
+ 'name': 'accountToken',
+ 'value': gofile_crawler.client.token,
+ })
process.start()
- return cookies, result_links
\ No newline at end of file
+ return cookies, result_links