Created
May 15, 2020 17:55
-
-
Save mzmmoazam/b944268df465691ee9e9cb02f10a54bf to your computer and use it in GitHub Desktop.
play youtube playlist in vlc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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