Advertisement
Jacobacon215

Twitch Music Chat Bot

Mar 12th, 2020
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. import os
  2. os.system('pip install twitch-listener')
  3. os.system('pip install mutagen')
  4. os.system('pip install ffmpeg')
  5. os.system('pip install youtube-dl')
  6. from twitch_listener import listener
  7. from mutagen.mp3 import MP3
  8. import ffmpeg
  9. import time
  10. file = open('<your twitch username>.log','r+')
  11. file.truncate(0)
  12. file.close()
  13. counter = 1
  14. bot = listener.connect_twitch('<your twitch username>',
  15.                               '<your twitch oauth code>',
  16.                               'o9lf8le4qyj1ckjmj8pd0pya1z6psc')
  17. channels_to_listen_to = ['<your twitch username>']
  18. while 1 == 1:
  19.     bot.listen(channels_to_listen_to, duration = 1)
  20.     file = open("<your twitch username>.log","r")
  21.     filetext = file.read()
  22.     playtest = filetext.count("-play ") > 0
  23.     if playtest == True:
  24.         watchindex = int(filetext.find("watch?v=")) + 8
  25.         watchcodeEnd = int(watchindex + 11)
  26.         youtubeurl = "youtube.com/watch?v=" + filetext[watchindex:watchcodeEnd]
  27.         os.system('youtube-dl -f mp4 --output C:\\Users\\<your profile name>\\musicfile' + str(counter) + '.mp4 "' + youtubeurl + '"')
  28.         os.system('ffmpeg -i "C:\\Users\\<your profile name>\\musicfile' + str(counter) + '.mp4" C:\\Users\\<your profile name>\\musicfile' + str(counter) + '.mp3"')
  29.         os.system('del C:\\Users\\<your profile name>\\musicfile' + str(counter) + '.mp4"')
  30.         audio = MP3('C:\\Users\\<your profile name>\\musicfile' + str(counter) + '.mp3')
  31.         audiolength = int(audio.info.length)
  32.         os.system('C:\\Users\\<your profile name>\\musicfile' + str(counter) + '.mp3"')
  33.         time.sleep(audiolength + 5)
  34.         os.system('del C:\\Users\\<your profile name>\\musicfile' + str(counter) + '.mp3"')
  35.         os.system('taskkill /im Music.UI.exe /T /F')
  36.         file.close()
  37.         file = open('jacobacon215.log','r+')
  38.         file.truncate(0)
  39.         file.close()
  40.         counter = counter + 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement