├── requirements.txt ├── LICENSE ├── README.md └── main.py /requirements.txt: -------------------------------------------------------------------------------- 1 | pyrogram==1.0.7 2 | tgcrypto 3 | requests 4 | youtube-dl 5 | validators 6 | ffmpeg 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Yasin Javar | یاسین جاور 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Video Downloader Telegram Bot (Youtube Downloader) 2 | This bot use youtube dl to download video from Stream urls which you can't download from for example Youtube Videos 3 | 4 | * this bot based on Pyrogram library and YoutubeDL 5 | 6 | # Install Requirements 7 | Use this command : 8 | 9 | pip install -r requirements.txt 10 | or : 11 | 12 | pip3 install -r requirements.txt 13 | # Edit the code 14 | at line **8**,**9** and **10** paste your **api id** and **api hash** ( get from [Here](https://my.telegram.org) ) and **bot token** ( get it from [BotFather](t.me/botfather) ) 15 | 16 | other Edit lines are Commented in The **main.py** Source :) 17 | # Run The Bot 18 | 19 | After Install requirements and edit the code Run The bot Use this command or use your editor or etc, 20 | 21 | python3 main.py 22 | 23 | The Bot Need ffmpeg so here is some link to know How install it on your OS : 24 | 25 | * [ffmpeg for Windows 10](https://www.wikihow.com/Install-FFmpeg-on-Windows) 26 | * [ffmpeg for Linux Distro](https://www.tecmint.com/install-ffmpeg-in-linux/) 27 | * [ffmpeg for Mac Os](https://avpres.net/FFmpeg/install_Apple.html) 28 | 29 | > Thanks to my Dear Friend [Hassan Hoot](https://github.com/hassanhoot) For The Progress Bar 30 | 31 | **I hope Enjoy The Bot :)** 32 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import requests, os, validators 4 | import youtube_dl 5 | from pyrogram import Client, filters 6 | from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton 7 | 8 | api_id = 123456789 #int of api id get from my.telegram.org 9 | api_hash = " Your Api Hash Here " #str of api hash get from my.telegram.org 10 | token = ' Your Bot Token here ' #str of token get from BotFather 11 | app = Client("Downlaoder", api_id, api_hash, bot_token=token) # You Can Change The Session Name by Replace "Downlaoder" to your session name 12 | 13 | 14 | def downloada(url, quality): 15 | 16 | if quality == "1": 17 | ydl_opts_start = { 18 | 'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', #This Method Need ffmpeg 19 | 'outtmpl': f'localhoct/%(id)s.%(ext)s', 20 | 'no_warnings': True, 21 | 'ignoreerrors': True, 22 | 'noplaylist': True, 23 | 'http_chunk_size': 20097152, 24 | 'writethumbnail': True 25 | 26 | } 27 | with youtube_dl.YoutubeDL(ydl_opts_start) as ydl: 28 | result = ydl.extract_info("{}".format(url)) 29 | title = ydl.prepare_filename(result) 30 | ydl.download([url]) 31 | return title 32 | 33 | if quality == "2": 34 | ydl_opts_start = { 35 | 'format': 'best', #This Method Don't Need ffmpeg , if you don't have ffmpeg use This 36 | 'outtmpl': f'localhoct/%(id)s.%(ext)s', 37 | 'no_warnings': False, 38 | 'logtostderr': False, 39 | 'ignoreerrors': False, 40 | 'noplaylist': True, 41 | 'http_chunk_size': 2097152, 42 | 'writethumbnail': True 43 | } 44 | with youtube_dl.YoutubeDL(ydl_opts_start) as ydl: 45 | result = ydl.extract_info("{}".format(url)) 46 | title = ydl.prepare_filename(result) 47 | ydl.download([url]) 48 | return f'{title}' 49 | 50 | if quality == "3": 51 | ydl_opts_start = { 52 | 'format': 'best[height=480]', 53 | 'outtmpl': f'localhoct/%(id)s.%(ext)s', 54 | 'no_warnings': False, 55 | 'logtostderr': False, 56 | 'ignoreerrors': False, 57 | 'noplaylist': True, 58 | 'http_chunk_size': 2097152, 59 | 'writethumbnail': True 60 | } 61 | with youtube_dl.YoutubeDL(ydl_opts_start) as ydl: 62 | result = ydl.extract_info("{}".format(url)) 63 | title = ydl.prepare_filename(result) 64 | ydl.download([url]) 65 | return f'{title}' 66 | 67 | # here you can Edit Start message 68 | @app.on_message(filters.command('start', '/')) 69 | def start(c, m): # c Mean Client | m Mean Message 70 | m.reply_text('Hi Welcome To @iLoaderBot \n Just Send Video Url To me and i\'ll try to upload the video and send it to you') #Edit it and add your Bot ID :) 71 | 72 | 73 | @app.on_message(filters.regex( 74 | r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)")) 75 | def webpage(c, m): # c Mean Client | m Mean Message 76 | url1 = m.text 77 | if validators.url(url1): 78 | sample_url = "https://da.gd/s?url={}".format(url1) 79 | url = requests.get(sample_url).text 80 | chat_id = m.chat.id 81 | keys = c.send_message( 82 | chat_id, 83 | f"Okay!!🙄\n {url1} is Video Url😊 \n\nPlease Select Quality :\n💡The HD Button is Download the Best Quality is available so I recommend This Button😁 ", 84 | reply_markup=InlineKeyboardMarkup( 85 | [ 86 | [ 87 | InlineKeyboardButton( 88 | "HD (Recommended) - Need ffmpeg", 89 | callback_data="%s and 1" % url 90 | ), 91 | ], 92 | [ 93 | InlineKeyboardButton( 94 | "HD - Don't Need ffmpeg", 95 | callback_data="%s and 2" % url 96 | ), 97 | ], 98 | [ 99 | InlineKeyboardButton( 100 | "SD (480) Maybe Don't Work", 101 | callback_data= "%s and 3" % url 102 | ), 103 | ] 104 | ] 105 | ), disable_web_page_preview=True 106 | ) 107 | else: 108 | c.send_message(m.chat.id,"Send The Valid Url Please") 109 | 110 | 111 | @app.on_callback_query() 112 | def download(c, q): # c Mean Client | q Mean Query 113 | global check_current 114 | check_current = 0 115 | def progress(current, total): #Thanks to my dear friend Hassan Hoot for Progress Bar :) 116 | global check_current 117 | if ((current//1024//1024) % 50 )== 0 : 118 | if check_current != (current//1024//1024): 119 | check_current = (current//1024//1024) 120 | upmsg.edit(f"{current//1024//1024}MB of {total//1024//1024}MB Uploaded 😁") 121 | elif (current//1024//1024) == (total//1024//1024): 122 | upmsg.delete() 123 | 124 | chat_id = q.message.chat.id 125 | data = q.data 126 | url, quaitly = data.split(" and ") 127 | dlmsg = c.send_message(chat_id, 'Hmm!😋 Downloading...') 128 | path = downloada(url, quaitly) 129 | upmsg = c.send_message(chat_id, 'Yeah😁 Uploading...') 130 | dlmsg.delete() 131 | thumb = path.replace('.mp4',".jpg",-1) 132 | if os.path.isfile(thumb): 133 | thumb = open(thumb,"rb") 134 | path = open(path, 'rb') 135 | c.send_photo(chat_id,thumb,caption='Thumbnail of the video Downloaded by @iLoaderBot') #Edit it and add your Bot ID :) 136 | c.send_video(chat_id, path, caption='Downloaded by @iLoaderBot', 137 | file_name="iLoader", supports_streaming=True, progress=progress) #Edit it and add your Bot ID :) 138 | upmsg.delete() 139 | else: 140 | path = open(path, 'rb') 141 | c.send_video(chat_id, path, caption='Downloaded by @iLoaderBot', 142 | file_name="iLoader", supports_streaming=True, progress=progress) 143 | upmsg.delete() 144 | 145 | app.run() 146 | --------------------------------------------------------------------------------