From ee02d43bf2e79c4a1029128fc43d376620d81be2 Mon Sep 17 00:00:00 2001 From: cpanel10x Date: Wed, 19 Jun 2024 11:11:28 +0700 Subject: [PATCH 1/2] Update builder.yaml --- .github/workflows/builder.yaml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/.github/workflows/builder.yaml b/.github/workflows/builder.yaml index 00ed0c4c..a4867014 100644 --- a/.github/workflows/builder.yaml +++ b/.github/workflows/builder.yaml @@ -32,24 +32,12 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Lower case for Docker Hub id: dh_string uses: ASzc/change-string-case-action@v5 with: - string: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }} + string: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}_tb:${{ github.ref_name }} - - name: Lower case for ghcr - id: ghcr_string - uses: ASzc/change-string-case-action@v5 - with: - string: ${{ github.event.repository.full_name }} - name: Build and push uses: docker/build-push-action@v4 @@ -59,7 +47,6 @@ jobs: push: true tags: | ${{ steps.dh_string.outputs.lowercase }} - ghcr.io/${{ steps.ghcr_string.outputs.lowercase }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max From 18d807aaac536dd51efcc474f18f2ed535bc21aa Mon Sep 17 00:00:00 2001 From: Sanuja Seneviratne <66342986+SanujaNS@users.noreply.github.com> Date: Sun, 30 Jun 2024 13:51:31 +0530 Subject: [PATCH 2/2] 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 6feb473dcfcf7ce511462883605a2d33814e0af0. * shortening URL in the caption if it's too long * section for advance users --- ytdlbot/config.py | 28 +++++++++++++--------------- ytdlbot/tasks.py | 14 +++++++++++++- ytdlbot/utils.py | 7 +++++++ ytdlbot/ytdl_bot.py | 1 - 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/ytdlbot/config.py b/ytdlbot/config.py index b9e62376..6bec4bb2 100644 --- a/ytdlbot/config.py +++ b/ytdlbot/config.py @@ -20,13 +20,6 @@ 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_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_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 @@ 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 diff --git a/ytdlbot/tasks.py b/ytdlbot/tasks.py index b605a999..070d19ec 100644 --- a/ytdlbot/tasks.py +++ b/ytdlbot/tasks.py @@ -44,6 +44,7 @@ TMPFILE_PATH, WORKERS, FileTooBig, + CAPTION_URL_LENGTH_LIMIT, ) from constant import BotText from database import Redis, MySQL @@ -57,6 +58,7 @@ 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 diff --git a/ytdlbot/utils.py b/ytdlbot/utils.py index d4995256..6ebe2287 100644 --- a/ytdlbot/utils.py +++ b/ytdlbot/utils.py @@ -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() diff --git a/ytdlbot/ytdl_bot.py b/ytdlbot/ytdl_bot.py index c9878c26..4cd44c35 100644 --- a/ytdlbot/ytdl_bot.py +++ b/ytdlbot/ytdl_bot.py @@ -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