youtubero-telegram.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. #Youtubero-telegram - simpatico script che esegue youtubero in modalita' bot di telegram
  3. import os
  4. import validators
  5. from telegram.ext import Updater, MessageHandler, Filters
  6. import youtubero
  7. def msg_parser(bot, update):
  8. print("Messaggio ricevuto")
  9. urlz = update.message.text
  10. #update.message.reply_text("Ciao " + update.message.from_user.username)
  11. update.message.reply_text("Messaggio ricevuto. Elaboro...")
  12. for url in [s for s in urlz.splitlines() if s.strip() != ""]:
  13. #update.message.reply_text("Scarico %s" %(url))
  14. # start the download
  15. dl = youtubero.download_video(url, update.message.from_user.username)
  16. update.message.reply_text(dl)
  17. def main():
  18. print ("Bot avviato")
  19. # Create the EventHandler and pass it your bot's token.
  20. updater = Updater(os.environ['TELEGRAM_TOKEN'])
  21. # Get the dispatcher to register handlers
  22. dp = updater.dispatcher
  23. # parse message
  24. dp.add_handler(MessageHandler(Filters.text, msg_parser))
  25. # Start the Bot
  26. updater.start_polling()
  27. # Run the bot until you press Ctrl-C
  28. updater.idle()
  29. if __name__ == '__main__':
  30. main()