short_url minor update

This commit is contained in:
Juned KH 2021-11-26 20:14:25 +05:30
parent 300169489e
commit 804a59178c
3 changed files with 50 additions and 83 deletions

View File

@ -6,13 +6,16 @@ import base64
import pyshorteners
from urllib.parse import quote
from urllib3 import disable_warnings
from bot import SHORTENER, SHORTENER_API
from bot import LOGGER, SHORTENER, SHORTENER_API
def short_url(longurl):
if SHORTENER is None and SHORTENER_API is None:
return longurl
if "shorte.st" in SHORTENER:
disable_warnings()
return requests.get(f'http://api.shorte.st/stxt/{SHORTENER_API}/{longurl}', verify=False).text
link = 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 = [
@ -20,12 +23,17 @@ def short_url(longurl):
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)
link = random.choice(linkvertise)
elif "bitly.com" in SHORTENER:
s = pyshorteners.Shortener(api_key=SHORTENER_API)
return s.bitly.short(longurl)
link = s.bitly.short(longurl)
elif "ouo.io" in SHORTENER:
disable_warnings()
return requests.get(f'http://ouo.io/api/{SHORTENER_API}?s={longurl}', verify=False).text
link = requests.get(f'http://ouo.io/api/{SHORTENER_API}?s={longurl}', verify=False).text
else:
return requests.get(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={longurl}&format=text').text
link = requests.get(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={longurl}&format=text').text
if len(link) == 0:
LOGGER.error("Something is Wrong with the url shortener")
return longurl
return link

View File

@ -22,8 +22,7 @@ from tenacity import *
from telegram import InlineKeyboardMarkup
from bot.helper.telegram_helper import button_build
from bot import parent_id, DOWNLOAD_DIR, IS_TEAM_DRIVE, INDEX_URL, USE_SERVICE_ACCOUNTS, BUTTON_FOUR_NAME, \
BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, BUTTON_SIX_NAME, BUTTON_SIX_URL, SHORTENER, \
SHORTENER_API, VIEW_LINK, DRIVES_NAMES, DRIVES_IDS, INDEX_URLS
BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, BUTTON_SIX_NAME, BUTTON_SIX_URL, VIEW_LINK, DRIVES_NAMES, DRIVES_IDS, INDEX_URLS
from bot.helper.ext_utils.telegraph_helper import telegraph
from bot.helper.ext_utils.bot_utils import get_readable_file_size, setInterval
from bot.helper.ext_utils.fs_utils import get_mime_type, get_path_size
@ -380,29 +379,20 @@ class GoogleDriveHelper:
msg += f'\n<b>SubFolders: </b>{self.total_folders}'
msg += f'\n<b>Files: </b>{self.total_files}'
buttons = button_build.ButtonMaker()
if SHORTENER is not None and SHORTENER_API is not None:
surl = short_url(durl)
buttons.buildbutton("☁️ Drive Link", surl)
else:
buttons.buildbutton("☁️ Drive Link", durl)
durl = short_url(durl)
buttons.buildbutton("☁️ Drive Link", durl)
if INDEX_URL is not None:
url_path = requests.utils.quote(f'{meta.get("name")}')
url = f'{INDEX_URL}/{url_path}/'
if SHORTENER is not None and SHORTENER_API is not None:
siurl = short_url(url)
buttons.buildbutton("⚡ Index Link", siurl)
else:
buttons.buildbutton("⚡ Index Link", url)
url = short_url(url)
buttons.buildbutton("⚡ Index Link", url)
else:
file = self.copyFile(meta.get('id'), parent_id)
msg += f'<b>Name: </b><code>{file.get("name")}</code>'
durl = self.__G_DRIVE_BASE_DOWNLOAD_URL.format(file.get("id"))
buttons = button_build.ButtonMaker()
if SHORTENER is not None and SHORTENER_API is not None:
surl = short_url(durl)
buttons.buildbutton("☁️ Drive Link", surl)
else:
buttons.buildbutton("☁️ Drive Link", durl)
durl = short_url(durl)
buttons.buildbutton("☁️ Drive Link", durl)
try:
typ = file.get('mimeType')
except:
@ -415,17 +405,12 @@ class GoogleDriveHelper:
if INDEX_URL is not None:
url_path = requests.utils.quote(f'{file.get("name")}')
url = f'{INDEX_URL}/{url_path}'
urls = f'{INDEX_URL}/{url_path}?a=view'
if SHORTENER is not None and SHORTENER_API is not None:
siurl = short_url(url)
buttons.buildbutton("⚡ Index Link", siurl)
if VIEW_LINK:
siurls = short_url(urls)
buttons.buildbutton("🌐 View Link", siurls)
else:
buttons.buildbutton("⚡ Index Link", url)
if VIEW_LINK:
buttons.buildbutton("🌐 View Link", urls)
url = short_url(url)
buttons.buildbutton("⚡ Index Link", url)
if VIEW_LINK:
urls = f'{INDEX_URL}/{url_path}?a=view'
urls = short_url(urls)
buttons.buildbutton("🌐 View Link", urls)
if BUTTON_FOUR_NAME is not None and BUTTON_FOUR_URL is not None:
buttons.buildbutton(f"{BUTTON_FOUR_NAME}", f"{BUTTON_FOUR_URL}")
if BUTTON_FIVE_NAME is not None and BUTTON_FIVE_URL is not None:
@ -712,22 +697,16 @@ class GoogleDriveHelper:
if file.get('mimeType') == "application/vnd.google-apps.folder":
furl = f"https://drive.google.com/drive/folders/{file.get('id')}"
msg += f"📁 <code>{file.get('name')}<br>(folder)</code><br>"
if SHORTENER is not None and SHORTENER_API is not None:
sfurl = short_url(furl)
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
else:
msg += f"<b><a href={furl}>Drive Link</a></b>"
furl = short_url(furl)
msg += f"<b><a href={furl}>☁️ Drive Link</a></b>"
if INDEX_URLS[index] is not None:
if isRecur:
url_path = "/".join([requests.utils.quote(n, safe='') for n in self.get_recursive_list(file, parent_id)])
else:
url_path = requests.utils.quote(f'{file.get("name")}')
url = f'{INDEX_URLS[index]}/{url_path}/'
if SHORTENER is not None and SHORTENER_API is not None:
siurl = short_url(url)
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
else:
msg += f' <b>| <a href="{url}">Index Link</a></b>'
url = short_url(url)
msg += f' <b>| <a href="{url}">⚡ Index Link</a></b>'
elif file.get('mimeType') == 'application/vnd.google-apps.shortcut':
msg += f"⁍<a href='https://drive.google.com/drive/folders/{file.get('id')}'>{file.get('name')}" \
f"</a> (shortcut)"
@ -735,11 +714,8 @@ class GoogleDriveHelper:
else:
furl = f"https://drive.google.com/uc?id={file.get('id')}&export=download"
msg += f"📄 <code>{file.get('name')}<br>({get_readable_file_size(int(file.get('size')))})</code><br>"
if SHORTENER is not None and SHORTENER_API is not None:
sfurl = short_url(furl)
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
else:
msg += f"<b><a href={furl}>Drive Link</a></b>"
furl = short_url(furl)
msg += f"<b><a href={furl}>☁️ Drive Link</a></b>"
if INDEX_URLS[index] is not None:
if isRecur:
url_path = "/".join(
@ -750,17 +726,12 @@ class GoogleDriveHelper:
else:
url_path = requests.utils.quote(f'{file.get("name")}')
url = f'{INDEX_URLS[index]}/{url_path}'
urls = f'{INDEX_URLS[index]}/{url_path}?a=view'
if SHORTENER is not None and SHORTENER_API is not None:
siurl = short_url(url)
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
if VIEW_LINK:
siurls = short_url(urls)
msg += f' <b>| <a href="{siurls}">View Link</a></b>'
else:
msg += f' <b>| <a href="{url}">Index Link</a></b>'
if VIEW_LINK:
msg += f' <b>| <a href="{urls}">View Link</a></b>'
url = short_url(url)
msg += f' <b>| <a href="{url}">⚡ Index Link</a></b>'
if VIEW_LINK:
urls = f'{INDEX_URLS[index]}/{url_path}?a=view'
urls = short_url(urls)
msg += f' <b>| <a href="{urls}">🌐 View Link</a></b>'
msg += '<br><br>'
contents_count += 1
if len(msg.encode('utf-8')) > 40000 :

View File

@ -16,8 +16,7 @@ from requests.exceptions import RequestException
from bot import Interval, INDEX_URL, BUTTON_FOUR_NAME, BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, \
BUTTON_SIX_NAME, BUTTON_SIX_URL, BLOCK_MEGA_FOLDER, BLOCK_MEGA_LINKS, VIEW_LINK, aria2, \
dispatcher, DOWNLOAD_DIR, download_dict, download_dict_lock, SHORTENER, SHORTENER_API, \
ZIP_UNZIP_LIMIT, TG_SPLIT_SIZE, LOGGER
dispatcher, DOWNLOAD_DIR, download_dict, download_dict_lock, ZIP_UNZIP_LIMIT, TG_SPLIT_SIZE, LOGGER
from bot.helper.ext_utils import fs_utils, bot_utils
from bot.helper.ext_utils.shortenurl import short_url
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException, NotSupportedExtractionArchive
@ -259,34 +258,23 @@ class MirrorListener(listeners.MirrorListeners):
else:
msg += f'\n\n<b>Type: </b>{typ}'
buttons = button_build.ButtonMaker()
if SHORTENER is not None and SHORTENER_API is not None:
surl = short_url(link)
buttons.buildbutton("☁️ Drive Link", surl)
else:
buttons.buildbutton("☁️ Drive Link", link)
link = short_url(link)
buttons.buildbutton("☁️ Drive Link", link)
LOGGER.info(f'Done Uploading {download_dict[self.uid].name()}')
if INDEX_URL is not None:
url_path = requests.utils.quote(f'{download_dict[self.uid].name()}')
share_url = f'{INDEX_URL}/{url_path}'
if os.path.isdir(f'{DOWNLOAD_DIR}/{self.uid}/{download_dict[self.uid].name()}'):
share_url += '/'
if SHORTENER is not None and SHORTENER_API is not None:
siurl = short_url(share_url)
buttons.buildbutton("⚡ Index Link", siurl)
else:
buttons.buildbutton("⚡ Index Link", share_url)
share_url = short_url(share_url)
buttons.buildbutton("⚡ Index Link", share_url)
else:
share_urls = f'{INDEX_URL}/{url_path}?a=view'
if SHORTENER is not None and SHORTENER_API is not None:
siurl = short_url(share_url)
buttons.buildbutton("⚡ Index Link", siurl)
if VIEW_LINK:
siurls = short_url(share_urls)
buttons.buildbutton("🌐 View Link", siurls)
else:
buttons.buildbutton("⚡ Index Link", share_url)
if VIEW_LINK:
buttons.buildbutton("🌐 View Link", share_urls)
share_url = short_url(share_url)
buttons.buildbutton("⚡ Index Link", share_url)
if VIEW_LINK:
share_urls = f'{INDEX_URL}/{url_path}?a=view'
share_urls = short_url(share_urls)
buttons.buildbutton("🌐 View Link", share_urls)
if BUTTON_FOUR_NAME is not None and BUTTON_FOUR_URL is not None:
buttons.buildbutton(f"{BUTTON_FOUR_NAME}", f"{BUTTON_FOUR_URL}")
if BUTTON_FIVE_NAME is not None and BUTTON_FIVE_URL is not None: