Skip to content
Open

x #152

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions .github/workflows/builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,19 @@ refer guide here [kubernetes](k8s.md)
```
start - Let's start
about - What's this bot?
ping - Bot running status
help - Help
spdl - Use to download specific link downloader links
ytdl - Download video in group
direct - Download file directly
settings - Set your preference
buy - Buy token
direct - Download file directly
sub - Subscribe to YouTube Channel
unsub - Unsubscribe from YouTube Channel
sub_count - Check subscription status, owner only.
uncache - Delete cache for this link, owner only.
purge - Delete all tasks, owner only.
ping - Ping the Bot
stats - Bot running status
show_history - Show download history
clear_history - Clear download history
```
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
git+https://github.com/KurimuzonAkuma/pyrogram
tgcrypto==1.2.5
yt-dlp==2024.04.9
yt-dlp==2024.5.27
APScheduler==3.10.4
beautifultable==1.1.0
ffmpeg-python==0.2.0
Expand Down
28 changes: 13 additions & 15 deletions ytdlbot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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
14 changes: 13 additions & 1 deletion ytdlbot/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
TMPFILE_PATH,
WORKERS,
FileTooBig,
CAPTION_URL_LENGTH_LIMIT,
)
from constant import BotText
from database import Redis, MySQL
Expand All @@ -57,6 +58,7 @@
get_metadata,
get_revision,
sizeof_fmt,
shorten_url,
)

customize_logger(["pyrogram.client", "pyrogram.session.session", "pyrogram.connection.connection"])
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions ytdlbot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
25 changes: 24 additions & 1 deletion ytdlbot/ytdl_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import json
import logging
import os
import threading
import random
import re
import tempfile
Expand Down Expand Up @@ -201,11 +202,33 @@ def purge_handler(client: Client, message: types.Message):

@app.on_message(filters.command(["ping"]))
def ping_handler(client: Client, message: types.Message):
chat_id = message.chat.id
client.send_chat_action(chat_id, enums.ChatAction.TYPING)
message_sent = False
def send_message_and_measure_ping():
start_time = int(round(time.time() * 1000))
reply = client.send_message(chat_id, "Starting Ping...")
end_time = int(round(time.time() * 1000))
ping_time = int(round(end_time - start_time))
message_sent = True
if message_sent:
message.reply_text(f"Ping: {ping_time:.2f} ms", quote=True)
time.sleep(0.5)
client.edit_message_text(chat_id=reply.chat.id, message_id=reply.id, text="Ping Calculation Complete.")
time.sleep(1)
client.delete_messages(chat_id=reply.chat.id, message_ids=reply.id)

thread = threading.Thread(target=send_message_and_measure_ping)
thread.start()


@app.on_message(filters.command(["stats"]))
def stats_handler(client: Client, message: types.Message):
redis = Redis()
chat_id = message.chat.id
client.send_chat_action(chat_id, enums.ChatAction.TYPING)
if os.uname().sysname == "Darwin" or ".heroku" in os.getenv("PYTHONHOME", ""):
bot_info = "ping unavailable."
bot_info = "Stats Unavailable."
else:
bot_info = get_runtime("ytdlbot_ytdl_1", "YouTube-dl")
if message.chat.username == OWNER:
Expand Down