mirror of
https://codeberg.org/JasterV/YoutuBot.git
synced 2026-04-26 18:40:02 +00:00
Add files via upload
This commit is contained in:
parent
58d0029c17
commit
02049bf0c1
1 changed files with 42 additions and 0 deletions
42
app.py
Normal file
42
app.py
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
import telebot
|
||||||
|
import time
|
||||||
|
import pafy
|
||||||
|
import os
|
||||||
|
|
||||||
|
bot_token = '837420348:AAEY2WT04zBjpCHYvOzCdy4FHhZf8jX6udE'
|
||||||
|
bot = telebot.TeleBot(token=bot_token)
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['start'])
|
||||||
|
def send_welcome(message):
|
||||||
|
bot.reply_to(message, 'Welcome! Send me a youtube video and i will send you an mp3 file!')
|
||||||
|
|
||||||
|
|
||||||
|
@bot.message_handler(func=lambda msg: msg.text is not None and ("youtube.com" in msg.text or "youtu.be" in msg.text))
|
||||||
|
def send_song(message):
|
||||||
|
filename = download_song(message)
|
||||||
|
path = os.path.join(os.getcwd(), filename)
|
||||||
|
while not os.path.exists(path):
|
||||||
|
continue
|
||||||
|
bot.send_message(message.chat.id, "Song downloaded")
|
||||||
|
song = open(filename, 'rb')
|
||||||
|
bot.send_message(message.chat.id, "Sending...")
|
||||||
|
bot.send_audio(message.chat.id, song)
|
||||||
|
bot.send_message(message.chat.id, "Enjoy it!")
|
||||||
|
os.remove(filename)
|
||||||
|
|
||||||
|
|
||||||
|
def download_song(message):
|
||||||
|
youtube_url = message.text
|
||||||
|
bot.send_message(message.chat.id, "downloading...")
|
||||||
|
video = pafy.new(youtube_url)
|
||||||
|
bestaudio = video.getbestaudio()
|
||||||
|
filename = bestaudio.download()
|
||||||
|
return filename
|
||||||
|
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
bot.polling()
|
||||||
|
except Exception:
|
||||||
|
time.sleep(15)
|
||||||
Loading…
Reference in a new issue