mirror of
https://github.com/tgbot-collection/ytdlbot.git
synced 2025-02-24 15:24:03 +08:00
Shortening URL in the caption if it's too long and some cleanup (#400)
* remove unnecessary line
* shortening URL in the caption if it's too long
* Revert "shortening URL in the caption if it's too long"
This reverts commit 6feb473dcf
.
* shortening URL in the caption if it's too long
* section for advance users
This commit is contained in:
parent
d1e702f111
commit
18d807aaac
4 changed files with 33 additions and 17 deletions
|
@ -20,13 +20,6 @@ TOKEN = os.getenv("TOKEN", "1234")
|
|||
|
||||
REDIS = os.getenv("REDIS", "redis")
|
||||
|
||||
TG_PREMIUM_MAX_SIZE = 4000 * 1024 * 1024
|
||||
TG_NORMAL_MAX_SIZE = 2000 * 1024 * 1024
|
||||
# TG_NORMAL_MAX_SIZE = 10 * 1024 * 1024
|
||||
|
||||
|
||||
EXPIRE = 24 * 3600
|
||||
|
||||
ENABLE_VIP = os.getenv("VIP", False)
|
||||
OWNER = os.getenv("OWNER", "BennyThink")
|
||||
|
||||
|
@ -44,23 +37,16 @@ MYSQL_HOST = os.getenv("MYSQL_HOST", "mysql")
|
|||
MYSQL_USER = os.getenv("MYSQL_USER", "root")
|
||||
MYSQL_PASS = os.getenv("MYSQL_PASS", "root")
|
||||
|
||||
AUDIO_FORMAT = os.getenv("AUDIO_FORMAT")
|
||||
ARCHIVE_ID = os.getenv("ARCHIVE_ID")
|
||||
|
||||
IPv6 = os.getenv("IPv6", False)
|
||||
ENABLE_FFMPEG = os.getenv("ENABLE_FFMPEG", False)
|
||||
AUDIO_FORMAT = os.getenv("AUDIO_FORMAT")
|
||||
|
||||
PLAYLIST_SUPPORT = os.getenv("PLAYLIST_SUPPORT", False)
|
||||
M3U8_SUPPORT = os.getenv("M3U8_SUPPORT", False)
|
||||
ENABLE_ARIA2 = os.getenv("ENABLE_ARIA2", False)
|
||||
|
||||
RATE_LIMIT = os.getenv("RATE_LIMIT", 120)
|
||||
RCLONE_PATH = os.getenv("RCLONE")
|
||||
# This will set the value for the tmpfile path(download path) if it is set.
|
||||
# If TMPFILE is not set, it will return None and use system’s default temporary file path.
|
||||
# Please ensure that the directory exists and you have necessary permissions to write to it.
|
||||
# If you don't know what this is just leave it as it is.
|
||||
TMPFILE_PATH = os.getenv("TMPFILE")
|
||||
|
||||
# payment settings
|
||||
AFD_LINK = os.getenv("AFD_LINK", "https://afdian.net/@BennyThink")
|
||||
|
@ -70,6 +56,7 @@ AFD_TOKEN = os.getenv("AFD_TOKEN")
|
|||
AFD_USER_ID = os.getenv("AFD_USER_ID")
|
||||
PROVIDER_TOKEN = os.getenv("PROVIDER_TOKEN") or "1234"
|
||||
FREE_DOWNLOAD = os.getenv("FREE_DOWNLOAD", 10)
|
||||
EXPIRE = 24 * 3600
|
||||
TOKEN_PRICE = os.getenv("BUY_UNIT", 20) # one USD=20 credits
|
||||
TRONGRID_KEY = os.getenv("TRONGRID_KEY", "").split(",")
|
||||
# the default mnemonic is for nile testnet
|
||||
|
@ -78,6 +65,17 @@ TRX_SIGNAL = signal("trx_received")
|
|||
|
||||
PREMIUM_USER = int(os.getenv("PREMIUM_USER", "0"))
|
||||
|
||||
# For advance users
|
||||
# Please do not change, if you don't know what these are.
|
||||
TG_PREMIUM_MAX_SIZE = 4000 * 1024 * 1024
|
||||
TG_NORMAL_MAX_SIZE = 2000 * 1024 * 1024
|
||||
CAPTION_URL_LENGTH_LIMIT = 150
|
||||
IPv6 = os.getenv("IPv6", False)
|
||||
RATE_LIMIT = os.getenv("RATE_LIMIT", 120)
|
||||
# This will set the value for the tmpfile path(download path). If not, will return None and use system’s default path.
|
||||
# Please ensure that the directory exists and you have necessary permissions to write to it.
|
||||
TMPFILE_PATH = os.getenv("TMPFILE_PATH")
|
||||
|
||||
|
||||
class FileTooBig(Exception):
|
||||
pass
|
||||
|
|
|
@ -44,6 +44,7 @@ from config import (
|
|||
TMPFILE_PATH,
|
||||
WORKERS,
|
||||
FileTooBig,
|
||||
CAPTION_URL_LENGTH_LIMIT,
|
||||
)
|
||||
from constant import BotText
|
||||
from database import Redis, MySQL
|
||||
|
@ -57,6 +58,7 @@ from utils import (
|
|||
get_metadata,
|
||||
get_revision,
|
||||
sizeof_fmt,
|
||||
shorten_url,
|
||||
)
|
||||
|
||||
customize_logger(["pyrogram.client", "pyrogram.session.session", "pyrogram.connection.connection"])
|
||||
|
@ -544,8 +546,18 @@ def gen_cap(bm, url, video_path):
|
|||
worker = f"Downloaded by {worker_name}"
|
||||
else:
|
||||
worker = ""
|
||||
# Shorten the URL if necessary
|
||||
try:
|
||||
if len(url) > CAPTION_URL_LENGTH_LIMIT:
|
||||
url_for_cap = shorten_url(url, CAPTION_URL_LENGTH_LIMIT)
|
||||
else:
|
||||
url_for_cap = url
|
||||
except Exception as e:
|
||||
logging.warning(f"Error shortening URL: {e}")
|
||||
url_for_cap = url
|
||||
|
||||
cap = (
|
||||
f"{user_info}\n{file_name}\n\n{url}\n\nInfo: {meta['width']}x{meta['height']} {file_size}\t"
|
||||
f"{user_info}\n{file_name}\n\n{url_for_cap}\n\nInfo: {meta['width']}x{meta['height']} {file_size}\t"
|
||||
f"{meta['duration']}s\n{remain}\n{worker}\n{bot_text.custom_text}"
|
||||
)
|
||||
return cap, meta
|
||||
|
|
|
@ -242,5 +242,12 @@ def extract_code_from_instagram_url(url):
|
|||
return None
|
||||
|
||||
|
||||
def shorten_url(url, CAPTION_URL_LENGTH_LIMIT):
|
||||
#Shortens a URL by cutting it to a specified length.
|
||||
shortened_url = url[:CAPTION_URL_LENGTH_LIMIT - 3] + "..."
|
||||
|
||||
return shortened_url
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
auto_restart()
|
||||
|
|
|
@ -202,7 +202,6 @@ def purge_handler(client: Client, message: types.Message):
|
|||
|
||||
@app.on_message(filters.command(["ping"]))
|
||||
def ping_handler(client: Client, message: types.Message):
|
||||
redis = Redis()
|
||||
chat_id = message.chat.id
|
||||
client.send_chat_action(chat_id, enums.ChatAction.TYPING)
|
||||
message_sent = False
|
||||
|
|
Loading…
Reference in a new issue