dvx3

Play songs and playlists from youtube in Kodi or VLC with youtube-dl

Feb 15th, 2021 (edited)
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. # Use with Kodi, install youtube-dl with (sudo) pip3 install youtube-dl
  2. # Save as yt.py
  3. # Add alias yt='python3 yt.py' in .bashrc (Raspberry Pi for example)
  4. # Use as yt https://www.youtube.com/playlist?list=PL55Jv4fGPIb8zQysIJQGi8Gl7ziO1P8O_
  5. # Select file.STRM from Kodi or VLC (or something other)
  6. # Works with .m3u8 files, single songs link, playlist links.
  7. from re import findall
  8. import subprocess
  9. from subprocess import Popen
  10. from sys import argv
  11. result = subprocess.Popen(["youtube-dl", "-g", argv[1]], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  12. output, error = result.communicate()
  13. output = output.decode('utf-8')
  14. urls = findall(r'(https?://\S+)', output)
  15. f = open("file.STRM", "w")
  16. blocked = 1
  17. for i, j in enumerate(urls):
  18.   if not ".m3u8" in j:
  19.     if blocked == 1:
  20.       blocked = 0
  21.       pass
  22.     elif blocked == 0:
  23.       f.write(urls[i] + "\n")
  24.       blocked = 1
  25.   else:
  26.     f.write(urls[i] + "\n")
  27. f.close()
Add Comment
Please, Sign In to add comment