From f8a1266688e87668100d22669d6bb7aa0e602f3c Mon Sep 17 00:00:00 2001 From: kalanakt Date: Thu, 25 Aug 2022 11:49:14 +0530 Subject: [PATCH] custom thumbunali support ` v2.0.0.1` --- README.md | 9 ++++--- Uploader/button.py | 10 ++++++++ Uploader/dl_button.py | 12 ++++++--- Uploader/thumbunali.py | 56 ++++++++++++++++++++++++++++++++++++++++++ Uploader/youtube.py | 22 ++++++++++++----- 5 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 Uploader/thumbunali.py diff --git a/README.md b/README.md index f31052b9..d3bbf197 100644 --- a/README.md +++ b/README.md @@ -28,15 +28,15 @@ | -------------------- | --------------------- | ------------------------------------------------------------------------------ | | v 1.0.0 | Stable | Upload all ytdl links, direct links | | v 2.0.0 | Stable | Upload all ytdl links, direct links, google drive etc. (Speed is much higher than version 1) | -| - | - | - | +| v 2.0.1 | stable | custom thumbunali support, fixed youtube download |

To do

* [x] deploy to vps setup - * [ ] brodcast message to users - * [ ] users counter - * [ ] custom thumbunali support + * [x] custom thumbunali support * [ ] custom caption support + * [ ] mega.nz support + * [ ] pdisk support

Deploy

@@ -88,6 +88,7 @@ python3 bot.py

Detailed changes for each release are documented in the main commits

Full Changelog: v1.0.0 Full Changelog: v1.0.0...v2.0.0 +Full Changelog: v2.0.0...v2.0.1

Stay In Touch

diff --git a/Uploader/button.py b/Uploader/button.py index 2c10d13e..091eb0ab 100644 --- a/Uploader/button.py +++ b/Uploader/button.py @@ -201,6 +201,12 @@ async def youtube_dl_call_back(bot, update): download_directory)[0] + "." + "mkv" # https://stackoverflow.com/a/678242/4723940 file_size = os.stat(download_directory).st_size + + if download_location := f"{Config.DOWNLOAD_LOCATION}/{update.from_user.id}.jpg": + thumb = download_location + else: + thumb = None + if ((file_size > Config.TG_MAX_FILE_SIZE)): await update.message.edit_caption( @@ -223,6 +229,7 @@ async def youtube_dl_call_back(bot, update): caption=description, # parse_mode=enums.ParseMode.HTML, # reply_to_message_id=update.id, + thumb=thumb, progress=progress_for_pyrogram, progress_args=( Translation.UPLOAD_START, @@ -240,6 +247,7 @@ async def youtube_dl_call_back(bot, update): width=width, height=height, supports_streaming=True, + thumb=thumb, # reply_to_message_id=update.id, progress=progress_for_pyrogram, progress_args=( @@ -255,6 +263,7 @@ async def youtube_dl_call_back(bot, update): audio=download_directory, caption=description, duration=duration, + thumb=thumb, # reply_to_message_id=update.id, progress=progress_for_pyrogram, progress_args=( @@ -270,6 +279,7 @@ async def youtube_dl_call_back(bot, update): video_note=download_directory, duration=duration, length=width, + thumb=thumb, # reply_to_message_id=update.id, progress=progress_for_pyrogram, progress_args=( diff --git a/Uploader/dl_button.py b/Uploader/dl_button.py index 73e29b94..e8ea5ad9 100644 --- a/Uploader/dl_button.py +++ b/Uploader/dl_button.py @@ -97,6 +97,10 @@ async def ddl_call_back(bot, update): # sourcery skip: low-code-quality return False if os.path.exists(download_directory): save_ytdl_json_path = f"{Config.DOWNLOAD_LOCATION}/{str(update.message.chat.id)}.json" + if download_location := f"{Config.DOWNLOAD_LOCATION}/{update.from_user.id}.jpg": + thumb = download_location + else: + thumb = None if os.path.exists(save_ytdl_json_path): os.remove(save_ytdl_json_path) @@ -116,18 +120,18 @@ async def ddl_call_back(bot, update): # sourcery skip: low-code-quality start_time = time.time() if tg_send_type == "video": width, height, duration = await Mdata01(download_directory) - await bot.send_video(chat_id=update.message.chat.id, video=download_directory, caption=description, duration=duration, width=width, height=height, supports_streaming=True, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time)) + await bot.send_video(chat_id=update.message.chat.id, video=download_directory, thumb=thumb, caption=description, duration=duration, width=width, height=height, supports_streaming=True, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time)) elif tg_send_type == "audio": duration = await Mdata03(download_directory) - await bot.send_audio(chat_id=update.message.chat.id, audio=download_directory, caption=description, duration=duration, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time)) + await bot.send_audio(chat_id=update.message.chat.id, audio=download_directory, thumb=thumb, caption=description, duration=duration, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time)) elif tg_send_type == "vm": width, duration = await Mdata02(download_directory) - await bot.send_video_note(chat_id=update.message.chat.id, video_note=download_directory, duration=duration, length=width, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time)) + await bot.send_video_note(chat_id=update.message.chat.id, video_note=download_directory, thumb=thumb, duration=duration, length=width, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time)) else: - await bot.send_document(chat_id=update.message.chat.id, document=download_directory, caption=description, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time)) + await bot.send_document(chat_id=update.message.chat.id, document=download_directory, thumb=thumb, caption=description, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=(Translation.UPLOAD_START, update.message, start_time)) end_two = datetime.now() try: diff --git a/Uploader/thumbunali.py b/Uploader/thumbunali.py new file mode 100644 index 00000000..aededa43 --- /dev/null +++ b/Uploader/thumbunali.py @@ -0,0 +1,56 @@ +# MIT License + +# Copyright (c) 2022 Hash Minner + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE + +import os + +from pyrogram import Client, filters + +if bool(os.environ.get("WEBHOOK")): + from Uploader.config import Config +else: + from sample_config import Config + + +@Client.on_message(filters.photo & filters.incoming & filters.private) +async def save_photo(bot, message): + download_location = f"{Config.DOWNLOAD_LOCATION}/{message.from_user.id}.jpg" + await message.download(file_name=download_location) + + await message.reply_text( + text="your custom thumbunali is saved", + quote=True + ) + + +@Client.on_message(filters.command("thumb") & filters.incoming & filters.private) +async def send_photo(bot, message): + if download_location := f"{Config.DOWNLOAD_LOCATION}/{message.from_user.id}.jpg": + await message.reply_photo( + photo=download_location, + caption="your custom thumbunali", + quote=True + ) + else: + await message.reply_text( + text="you don't have set thumbunali yet!. send .jpg img to save as thumbunali.", + quote=True + ) diff --git a/Uploader/youtube.py b/Uploader/youtube.py index c78ec336..981d4af7 100644 --- a/Uploader/youtube.py +++ b/Uploader/youtube.py @@ -24,16 +24,18 @@ import wget import asyncio +from opencc import OpenCC +from youtube_dl import YoutubeDL from pyrogram import Client, filters, enums from pyrogram.types import Message from pyrogram import Client, filters -from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ReplyKeyboardMarkup, KeyboardButton +if bool(os.environ.get("WEBHOOK")): + from Uploader.config import Config +else: + from sample_config import Config from functions.help_ytdl import get_file_extension_from_url, get_resolution -from opencc import OpenCC -from youtube_dl import YoutubeDL - YTDL_REGEX = (r"^((?:https?:)?\/\/)") s2tw = OpenCC('s2tw.json').convert @@ -76,12 +78,16 @@ async def send_audio(message: Message, info_dict, audio_file): audio_file = audio_file_weba thumbnail_url = info_dict['thumbnail'] thumbnail_file = f"{basename}.{get_file_extension_from_url(thumbnail_url)}" + if download_location := f"{Config.DOWNLOAD_LOCATION}/{message.from_user.id}.jpg": + thumb = download_location + else: + thumb = thumbnail_file webpage_url = info_dict['webpage_url'] title = s2tw(info_dict['title']) caption = f'{title}' duration = int(float(info_dict['duration'])) performer = s2tw(info_dict['uploader']) - await message.reply_audio(audio_file, caption=caption, duration=duration, performer=performer, title=title, parse_mode=enums.ParseMode.HTML, thumb=thumbnail_file) + await message.reply_audio(audio_file, caption=caption, duration=duration, performer=performer, title=title, parse_mode=enums.ParseMode.HTML, thumb=thumb) os.remove(audio_file) os.remove(thumbnail_file) @@ -122,12 +128,16 @@ async def send_video(message: Message, info_dict, video_file): basename = video_file.rsplit(".", 1)[-2] thumbnail_url = info_dict['thumbnail'] thumbnail_file = f"{basename}.{get_file_extension_from_url(thumbnail_url)}" + if download_location := f"{Config.DOWNLOAD_LOCATION}/{message.from_user.id}.jpg": + thumb = download_location + else: + thumb = thumbnail_file webpage_url = info_dict['webpage_url'] title = s2tw(info_dict['title']) caption = f'{title}' duration = int(float(info_dict['duration'])) width, height = get_resolution(info_dict) - await message.reply_video(video_file, caption=caption, duration=duration, width=width, height=height, parse_mode=enums.ParseMode.HTML, thumb=thumbnail_file) + await message.reply_video(video_file, caption=caption, duration=duration, width=width, height=height, parse_mode=enums.ParseMode.HTML, thumb=thumb) os.remove(video_file) os.remove(thumbnail_file)