Skip to content

Instantly share code, notes, and snippets.

@mzmmoazam
Created May 15, 2020 17:55
Show Gist options
  • Save mzmmoazam/b944268df465691ee9e9cb02f10a54bf to your computer and use it in GitHub Desktop.
Save mzmmoazam/b944268df465691ee9e9cb02f10a54bf to your computer and use it in GitHub Desktop.
play youtube playlist in vlc
'''
Well, it is to play youtube song playlists in your laptop (VLC).
you will say why would I do, it is much better
Try it
prerequisites
add vlc to your PATH
pip install pytube3
usage:
python youtube_in_vlc.py "https://www.youtube.com/watch?v=3AtDnEC4zak&list=PLjUxvbIPUHP2OjmL22waOqzvkOw-JAWrN&index=1"
'''
from pytube import Playlist
import subprocess as sub
import sys
def run_cmd(cmd):
# create subprocess
proc = sub.Popen(cmd, stdout=sub.PIPE, universal_newlines=True)
# read output line for line
while proc.poll() is None:
opt = proc.stdout.readline()
print(opt)
# print rest of output
print(proc.stdout.read())
return
try:
url = sys.argv[1]
except Exception as e:
url = 'https://www.youtube.com/watch?v=3AtDnEC4zak&list=PLjUxvbIPUHP2OjmL22waOqzvkOw-JAWrN&index=1'
playlist = Playlist(url)
print('Number of videos in playlist: %s' % len(playlist.video_urls))
cmd = ["vlc"]
cmd.extend(playlist.video_urls)
run_cmd(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment