Skip to content

Commit

Permalink
ADD/FIX
Browse files Browse the repository at this point in the history
-Add more shorteners: linkvertise, shorte and bitly
-Minor fixes

Co-authored-by: Juned KH <[email protected]>

Signed-off-by: anas <[email protected]>
  • Loading branch information
anasty17 committed Aug 27, 2021
1 parent b9656e3 commit 10237fd
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 57 deletions.
27 changes: 27 additions & 0 deletions bot/helper/ext_utils/shortenurl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import requests
import random
import base64
import pyshorteners
from urllib.parse import quote
from urllib3 import disable_warnings
from bot import SHORTENER, SHORTENER_API


def short_url(longurl):
if "shorte.st" in SHORTENER:
disable_warnings()
return requests.get(f'http://api.shorte.st/stxt/{SHORTENER_API}/{longurl}', verify=False).text
elif "linkvertise" in SHORTENER:
url = quote(base64.b64encode(longurl.encode("utf-8")))
linkvertise = [
f"https://link-to.net/{SHORTENER_API}/{random.random() * 1000}/dynamic?r={url}",
f"https://up-to-down.net/{SHORTENER_API}/{random.random() * 1000}/dynamic?r={url}",
f"https://direct-link.net/{SHORTENER_API}/{random.random() * 1000}/dynamic?r={url}",
f"https://file-link.net/{SHORTENER_API}/{random.random() * 1000}/dynamic?r={url}"]
return random.choice(linkvertise)
elif "bitly.com" in SHORTENER:
s = pyshorteners.Shortener(api_key=SHORTENER_API)
bitly = s.bitly.short(longurl)
return bitly
else:
return requests.get(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={longurl}&format=text').text
27 changes: 0 additions & 27 deletions bot/helper/mirror_utils/download_utils/download_helper.py

This file was deleted.

13 changes: 8 additions & 5 deletions bot/helper/mirror_utils/download_utils/mega_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ def onRequestFinish(self, api, request, error):
self.continue_event.set()

def onRequestTemporaryError(self, api, request, error: MegaError):
LOGGER.info(f'Mega Request error in {error}')
LOGGER.error(f'Mega Request error in {error}')
if not self.is_cancelled:
self.listener.onDownloadError("RequestTempError: " + error.toString())
self.is_cancelled = True
self.listener.onDownloadError("RequestTempError: " + error.toString())
self.error = error.toString()
self.continue_event.set()

Expand All @@ -90,12 +90,15 @@ def onTransferStart(self, api: MegaApi, transfer: MegaTransfer):
def onTransferUpdate(self, api: MegaApi, transfer: MegaTransfer):
if self.is_cancelled:
api.cancelTransfer(transfer, None)
return
self.__speed = transfer.getSpeed()
self.__bytes_transferred = transfer.getTransferredBytes()

def onTransferFinish(self, api: MegaApi, transfer: MegaTransfer, error):
try:
if transfer.isFolderTransfer() and transfer.isFinished() or transfer.getFileName() == self.name and not self.is_cancelled:
if self.is_cancelled:
self.continue_event.set()
elif transfer.isFinished() and (transfer.isFolderTransfer() or transfer.getFileName() == self.name):
self.listener.onDownloadComplete()
self.continue_event.set()
except Exception as e:
Expand All @@ -105,7 +108,7 @@ def onTransferTemporaryError(self, api, transfer, error):
filen = transfer.getFileName()
state = transfer.getState()
errStr = error.toString()
LOGGER.info(f'Mega download error in file {transfer} {filen}: {error}')
LOGGER.error(f'Mega download error in file {transfer} {filen}: {error}')

if state == 1 or state == 4:
# Sometimes MEGA (offical client) can't stream a node either and raises a temp failed error.
Expand Down Expand Up @@ -163,7 +166,7 @@ def add_download(mega_link: str, path: str, listener):
executor.do(folder_api.loginToFolder, (mega_link,))
node = folder_api.authorizeNode(mega_listener.node)
if mega_listener.error is not None:
return listener.onDownloadError(str(mega_listener.error))
return sendMessage(str(mega_listener.error), listener.bot, listener.update)
if STOP_DUPLICATE:
LOGGER.info(f'Checking File/Folder if already in Drive')
mname = node.getName()
Expand Down
Loading

0 comments on commit 10237fd

Please sign in to comment.