Skip to content

Commit

Permalink
fix: thumbnail blocked
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Gorn committed Jun 10, 2024
1 parent f91d2a1 commit e8be45d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
__pycache__
.venv
.env
*.session
*.session
*.session-journal
DOWNLOADS
2 changes: 1 addition & 1 deletion Bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Config(object):
BotCommand('broadcast', 'broadcast message')
]

DUMP_ID = int(os.environ.get("DUMP_ID"))
DUMP_ID = int(os.environ.get("DUMP_ID", 0))

BOT_TOKEN = os.environ.get("BOT_TOKEN", "")

Expand Down
2 changes: 1 addition & 1 deletion Bot/functions/dl_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def ddl_call_back(bot: Client, update: CallbackQuery):
if client.guess_mime_type(download_directory) in ffmpeg_supported_video_mimetypes:
await run_cmd('ffmpeg -ss {} -i "{}" -vframes 1 "{}"'.format(random.randint(0, duration), download_directory, thumb_image_path))
# get the correct width, height, and duration for videos greater than 10MB
if os.path.exists(thumb_image_path) and not client.custom_thumbnail.get(update.from_user.id):
if os.path.exists(thumb_image_path):
width = 0
height = 0
metadata = extractMetadata(createParser(thumb_image_path))
Expand Down
3 changes: 2 additions & 1 deletion Bot/functions/youtube_dl_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ async def youtube_dl_call_back(bot: Client, update: CallbackQuery):
if client.guess_mime_type(download_directory) in ffmpeg_supported_video_mimetypes:
await run_cmd('ffmpeg -ss {} -i "{}" -vframes 1 "{}"'.format(random.randint(0, duration), download_directory, thumb_image_path))
# get the correct width, height, and duration for videos greater than 10MB
if os.path.exists(thumb_image_path) and not client.custom_thumbnail.get(update.from_user.id):
if os.path.exists(thumb_image_path):
width = 0
height = 0
metadata = extractMetadata(createParser(thumb_image_path))
Expand Down Expand Up @@ -236,6 +236,7 @@ async def youtube_dl_call_back(bot: Client, update: CallbackQuery):
thumb_image_path = None
start_time = time.time()
# try to upload file
client.logger.info(thumb_image_path)
if tg_send_type == "audio":
media = await bot.send_audio(
chat_id=update.message.chat.id,
Expand Down
2 changes: 1 addition & 1 deletion Bot/plugins/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ async def echo_http(bot: Client, update: Message):
if response_json["thumbnail"] is not None:
thumbnail = response_json["thumbnail"]
thumbnail_image = response_json["thumbnail"]
if not client.custom_thumbnail.get(update.from_user.id):
if thumbnail_image and not client.custom_thumbnail.get(update.from_user.id):
thumb_image_path = client.config.DOWNLOAD_LOCATION + \
"/" + str(update.from_user.id) + ".webp"
await download_coroutine(
Expand Down
10 changes: 10 additions & 0 deletions Bot/plugins/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from .. import client
from pyrogram import Client, filters
from pyrogram.types import Message
Expand Down Expand Up @@ -55,12 +56,21 @@ async def custom_thumbnail(bot: Client, update: Message):
return await update.reply(
text='Reply to a photo or `/thumbnail https.....jpg`'
)
if os.path.isfile(client.custom_thumbnail[update.from_user.id]):
os.remove(client.custom_thumbnail[update.from_user.id])
thumbnail = None
await update.reply(text='Custom thumbnail cleared.')
client.custom_thumbnail[update.from_user.id] = thumbnail


@Client.on_message(filters.private & filters.command('thumbnail') & filters.reply & filters.create(reply_to_photo_filter) & Filter.auth_users)
async def custom_thumbnail_reply(bot: Client, update: Message):
if client.database:
user = await client.database.xurluploader.users.find_one({'id': update.from_user.id})
if not user:
user = await client.database.xurluploader.users.insert_one({'id': update.from_user.id, 'banned': False})
else:
if user.get('banned'):
return await update.reply('You are banned.')
client.custom_thumbnail[update.from_user.id] = await update.reply_to_message.download(file_name=f'{client.config.DOWNLOAD_LOCATION}/{update.from_user.id}.jpg')
await update.reply(text='Custom thumbnail updated.')

0 comments on commit e8be45d

Please sign in to comment.