├── Procfile ├── requirements.txt ├── .gitignore ├── README.md ├── LICENSE └── main.py /Procfile: -------------------------------------------------------------------------------- 1 | worker: python3 main.py 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyrotgfork[fast] 2 | ytthumb 3 | python-dotenv 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/__pycache__ 2 | **/venv 3 | *.session 4 | *.session-journal 5 | *.pyc 6 | *.env 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # YouTube Thumbnail Downloader 2 | 3 | A youtube videos thumbnail downloader telegram bot 4 | 5 | --- 6 | 7 | ## How to run 8 | 9 | ##### In Linux 10 | 11 | ```sh 12 | python3 -m venv venv 13 | . ./venv/bin/activate 14 | pip3 install -r requirements.txt 15 | python3 main.py 16 | ``` 17 | 18 | ##### In Windows 19 | 20 | ```sh 21 | python3 -m venv venv 22 | venv/Scripts/activate 23 | pip install -r requirements.txt 24 | python main.py 25 | ``` 26 | 27 | --- 28 | 29 | ## Variables 30 | 31 | - `API_HASH` Your API Hash from my.telegram.org 32 | - `API_ID` Your API ID from my.telegram.org 33 | - `BOT_TOKEN` Your bot token from @BotFather 34 | 35 | --- 36 | 37 | ## Commands 38 | 39 | ``` 40 | start - For start bot 41 | ``` 42 | 43 | --- 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Fayas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # Author: Fayas (https://github.com/FayasNoushad) (@FayasNoushad) 2 | 3 | import os 4 | import ytthumb 5 | from dotenv import load_dotenv 6 | from pyrogram import Client, filters 7 | from pyrogram.types import ( 8 | InlineKeyboardMarkup, 9 | InlineKeyboardButton, 10 | InputMediaPhoto, 11 | LinkPreviewOptions, 12 | ) 13 | 14 | load_dotenv() 15 | 16 | Bot = Client( 17 | "YouTube-Thumbnail-Downloader", 18 | bot_token=os.environ.get("BOT_TOKEN"), 19 | api_id=int(os.environ.get("API_ID")), 20 | api_hash=os.environ.get("API_HASH"), 21 | ) 22 | 23 | START_TEXT = """Hello {}, \ 24 | I am a simple youtube thumbnail downloader telegram bot. \ 25 | Send a youtube video link or id, I will send the thumbnail in different qualities. 26 | 27 | Qualities:""" 28 | 29 | for quality in ytthumb.qualities(): 30 | START_TEXT += f"\n - {quality}: {ytthumb.qualities()[quality]}" 31 | 32 | BUTTON = [InlineKeyboardButton("Feedback", url="https://telegram.me/FayasNoushad")] 33 | 34 | photo_buttons = InlineKeyboardMarkup( 35 | [[InlineKeyboardButton("Other Qualities", callback_data="qualities")], BUTTON] 36 | ) 37 | 38 | 39 | @Bot.on_callback_query() 40 | async def cb_data(_, message): 41 | data = message.data.lower() 42 | if data == "qualities": 43 | await message.answer("Select a quality") 44 | buttons = [] 45 | for quality in ytthumb.qualities(): 46 | buttons.append( 47 | InlineKeyboardButton( 48 | text=ytthumb.qualities()[quality], callback_data=quality 49 | ) 50 | ) 51 | await message.edit_message_reply_markup( 52 | InlineKeyboardMarkup( 53 | [[buttons[0], buttons[1]], [buttons[2], buttons[3]], BUTTON] 54 | ) 55 | ) 56 | elif data == "back": 57 | await message.edit_message_reply_markup(photo_buttons) 58 | elif data in ytthumb.qualities(): 59 | thumbnail = ytthumb.thumbnail( 60 | video=message.message.reply_to_message.text.split(" | ")[0], 61 | quality=message.data, 62 | ) 63 | await message.answer("Updating") 64 | await message.edit_message_media( 65 | media=InputMediaPhoto(media=thumbnail), reply_markup=photo_buttons 66 | ) 67 | await message.answer("Updated Successfully") 68 | 69 | 70 | @Bot.on_message(filters.private & filters.command(["start", "help"])) 71 | async def start(_, message): 72 | await message.reply_text( 73 | text=START_TEXT.format(message.from_user.mention), 74 | reply_markup=InlineKeyboardMarkup([BUTTON]), 75 | quote=True, 76 | ) 77 | 78 | 79 | @Bot.on_message(filters.private & filters.text) 80 | async def send_thumbnail(bot, message): 81 | reply = await message.reply_text(text="`Analysing...`", quote=True) 82 | try: 83 | if " | " in message.text: 84 | video = message.text.split(" | ", -1)[0] 85 | quality = message.text.split(" | ", -1)[1] 86 | else: 87 | video = message.text 88 | quality = "sd" 89 | thumbnail = ytthumb.thumbnail(video=video, quality=quality) 90 | print(thumbnail) 91 | await message.reply_photo( 92 | photo=thumbnail, reply_markup=photo_buttons, quote=True 93 | ) 94 | await reply.delete() 95 | except Exception as error: 96 | await reply.edit_text( 97 | text=error, 98 | link_preview_options=LinkPreviewOptions(is_disabled=True), 99 | reply_markup=InlineKeyboardMarkup([BUTTON]), 100 | ) 101 | 102 | 103 | if __name__ == "__main__": 104 | print("Bot is starting") 105 | Bot.run() 106 | --------------------------------------------------------------------------------