youtubero/youtubero-telegram.py
2020-03-27 20:12:14 +01:00

49 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env python3
#Youtubero-telegram - simpatico script che esegue youtubero in modalita' bot di telegram
import os
import validators
from telegram.ext import Updater, MessageHandler, Filters
import youtubero
def msg_parser(bot, update):
print("Messaggio ricevuto")
urlz = update.message.text
#update.message.reply_text("Ciao " + update.message.from_user.username)
update.message.reply_text("Messaggio ricevuto. Elaboro...")
for url in [s for s in urlz.splitlines() if s.strip() != ""]:
#update.message.reply_text("Scarico %s" %(url))
# start the download
dl = youtubero.download_video(url, update.message.from_user.username)
update.message.reply_text(dl)
def main():
print ("Bot avviato")
# Create the EventHandler and pass it your bot's token.
updater = Updater(os.environ['TELEGRAM_TOKEN'])
# Get the dispatcher to register handlers
dp = updater.dispatcher
# parse message
dp.add_handler(MessageHandler(Filters.text, msg_parser))
# Start the Bot
updater.start_polling()
# Run the bot until you press Ctrl-C
updater.idle()
if __name__ == '__main__':
main()