Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
Fix gofile & qiwi link generator.
  • Loading branch information
Dawn-India committed Mar 28, 2024
1 parent 51d2dc2 commit 3ba151c
Showing 1 changed file with 53 additions and 39 deletions.
92 changes: 53 additions & 39 deletions bot/helper/mirror_utils/download_utils/direct_link_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
from bot.helper.ext_utils.help_messages import PASSWORD_ERROR_MESSAGE

_caches = {}
user_agent = (
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36"
)


def direct_link_generator(link):
Expand Down Expand Up @@ -370,7 +373,7 @@ def solidfiles(url):
with create_scraper() as session:
try:
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36'
'User-Agent': user_agent
}
pageSource = session.get(url, headers=headers).text
mainOptions = str(
Expand Down Expand Up @@ -562,7 +565,7 @@ def sharer_scraper(url):
try:
url = cget('GET', url).url
raw = urlparse(url)
header = {"useragent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/7.0.548.0 Safari/534.10"}
header = {"useragent": user_agent}
res = cget('GET', url, headers=header)
except Exception as e:
raise DirectDownloadLinkException(f'ERROR: {e.__class__.__name__}')
Expand All @@ -576,7 +579,7 @@ def sharer_scraper(url):
headers = {
'Content-Type': f'multipart/form-data; boundary=----WebKitFormBoundary{boundary}',
'x-token': raw.hostname,
'useragent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/7.0.548.0 Safari/534.10'
'useragent': user_agent
}

data = f'------WebKitFormBoundary{boundary}\r\nContent-Disposition: form-data; name="action"\r\n\r\ndirect\r\n' \
Expand Down Expand Up @@ -755,88 +758,99 @@ def gofile(url):
_password = sha256(_password.encode("utf-8")).hexdigest()
url = url.split("::")[-2]
else:
_password = ''
_password = ""
_id = url.split("/")[-1]
except Exception as e:
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}")

def __get_token(session):
if 'gofile_token' in _caches:
__url = f"https://api.gofile.io/getAccountDetails?token={_caches['gofile_token']}"
else:
__url = 'https://api.gofile.io/createAccount'
headers = {
"User-Agent": user_agent,
"Accept-Encoding": "gzip, deflate, br",
"Accept": "*/*",
"Connection": "keep-alive",
}
__url = f"https://api.gofile.io/accounts"
try:
__res = session.get(__url, verify=False).json()
if __res["status"] != 'ok':
if 'gofile_token' in _caches:
del _caches['gofile_token']
return __get_token(session)
_caches['gofile_token'] = __res["data"]["token"]
return _caches['gofile_token']
__res = session.post(__url, headers=headers).json()
if __res["status"] != "ok":
raise DirectDownloadLinkException(f"ERROR: Failed to get token.")
return __res["data"]["token"]
except Exception as e:
raise e

def __fetch_links(session, _id, folderPath=''):
_url = f"https://api.gofile.io/getContent?contentId={_id}&token={token}&wt=4fd6sg89d7s6&cache=true"
def __fetch_links(session, _id, folderPath=""):
_url = f"https://api.gofile.io/contents/{_id}?wt=4fd6sg89d7s6&cache=true"
headers = {
"User-Agent": user_agent,
"Accept-Encoding": "gzip, deflate, br",
"Accept": "*/*",
"Connection": "keep-alive",
"Authorization": "Bearer" + " " + token,
}
if _password:
_url += f"&password={_password}"
try:
_json = session.get(_url, verify=False).json()
_json = session.get(_url, headers=headers).json()
except Exception as e:
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}")
if _json['status'] in 'error-passwordRequired':
raise DirectDownloadLinkException(f"ERROR:\n{PASSWORD_ERROR_MESSAGE.format(url)}")
if _json['status'] in 'error-passwordWrong':
raise DirectDownloadLinkException('ERROR: This password is wrong !')
if _json['status'] in 'error-notFound':
raise DirectDownloadLinkException("ERROR: File not found on gofile's server")
if _json['status'] in 'error-notPublic':
if _json["status"] in "error-passwordRequired":
raise DirectDownloadLinkException(
f"ERROR:\n{PASSWORD_ERROR_MESSAGE.format(url)}"
)
if _json["status"] in "error-passwordWrong":
raise DirectDownloadLinkException("ERROR: This password is wrong !")
if _json["status"] in "error-notFound":
raise DirectDownloadLinkException(
"ERROR: File not found on gofile's server"
)
if _json["status"] in "error-notPublic":
raise DirectDownloadLinkException("ERROR: This folder is not public")

data = _json["data"]

if not details['title']:
details['title'] = data['name'] if data['type'] == "folder" else _id
if not details["title"]:
details["title"] = data["name"] if data["type"] == "folder" else _id

contents = data["contents"]
contents = data["children"]
for content in contents.values():
if content["type"] == "folder":
if not content['public']:
if not content["public"]:
continue
if not folderPath:
newFolderPath = path.join(details['title'], content["name"])
newFolderPath = path.join(details["title"], content["name"])
else:
newFolderPath = path.join(folderPath, content["name"])
__fetch_links(session, content["id"], newFolderPath)
else:
if not folderPath:
folderPath = details['title']
folderPath = details["title"]
item = {
"path": path.join(folderPath),
"filename": content["name"],
"url": content["link"],
}
if 'size' in content:
if "size" in content:
size = content["size"]
if isinstance(size, str) and size.isdigit():
size = float(size)
details['total_size'] += size
details['contents'].append(item)
details["total_size"] += size
details["contents"].append(item)

details = {'contents':[], 'title': '', 'total_size': 0}
details = {"contents": [], "title": "", "total_size": 0}
with Session() as session:
try:
token = __get_token(session)
except Exception as e:
raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}")
details["header"] = f'Cookie: accountToken={token}'
details["header"] = f"Cookie: accountToken={token}"
try:
__fetch_links(session, _id)
except Exception as e:
raise DirectDownloadLinkException(e)

if len(details['contents']) == 1:
return (details['contents'][0]['url'], details['header'])
if len(details["contents"]) == 1:
return (details["contents"][0]["url"], details["header"])
return details

def mediafireFolder(url):
Expand Down Expand Up @@ -1305,7 +1319,7 @@ def qiwi(url):
if name := tree.xpath('//h1[@class="page_TextHeading__VsM7r"]/text()'):

ext = name[0].split('.')[-1]
return f"https://qiwi.lol/{file_id}.{ext}"
return f"https://spyderrock.com/{file_id}.{ext}"
else:
raise DirectDownloadLinkException("ERROR: File not found")

Expand Down

0 comments on commit 3ba151c

Please sign in to comment.