Last active
March 13, 2024 21:30
-
-
Save KorigamiK/3f434ea854a03a49f6da75d97929a0d3 to your computer and use it in GitHub Desktop.
Create YouTube Playlists from videos
This file contains hidden or 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
import os, io | |
import webbrowser | |
import json | |
from urllib import request | |
videos = [] | |
getVideoId = lambda s: s.split("=")[-1] | |
with open("playlist.json") as data_file: | |
data = json.load(data_file) | |
for x in data: | |
for y in x: | |
print(y.get("data"), y.get("meta")) | |
videos.append(getVideoId(y.get("data"))) | |
listOfVideos = "http://www.youtube.com/watch_videos?video_ids=" + ",".join(videos) | |
print(listOfVideos) | |
response = request.urlopen(listOfVideos) | |
playListLink = response.geturl().split("list=")[1] | |
# edit playlist with this URL | |
playListURL = ( | |
f"https://www.youtube.com/playlist?list={playListLink}&disable_polymer=true" | |
) | |
# or start playing from first to last with this one | |
playNowURL = "https://www.youtube.com/watch?v=" + videos[0] + "&list=" + playListLink | |
webbrowser.open(playListURL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment