Python 3 script that converts Youtube playlists through youtube-dl into format-agnostic VLC-compatible .m3u8 playlist file in the order of the source playlist
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
# MADE AND TESTED ONLY FOR YOUTUBE PLAYLISTS | |
# Requires youtube-dl option `--write-info-json` to work | |
# For this to work, you need to put this script into the directory (folder) of the videos and JSON files | |
import os | |
import json | |
# Separate JSON metadata files and media files | |
for path, dirname, filenames in os.walk(os.getcwd()): | |
json_filenames = [name for name in filenames if name.endswith('.info.json')] | |
media_filenames = [name for name in filenames if not name.endswith('.info.json')] | |
# Creates playlist that will fit exactly all the media files in the directory/folder | |
playlist = [''] * len(json_filenames) | |
# Finds matching media filename per JSON files, then add it into the playlist file | |
for json_name in json_filenames: | |
if any(name.startswith(json_name[:-10]) for name in media_filenames) is True: | |
media_name = list(filter(lambda x: x.startswith(json_name[:-10]), media_filenames))[0] | |
info = json.loads(open(json_name).read()) | |
playlist[info['playlist_index']-1] = media_name | |
# Write the playlist into at least a VLC-compatible playlist file; WARNING: WILL WRITE OVER EXISTING FILE | |
with open('playlist.m3u8', 'w', encoding='utf-8') as f: | |
f.write('\n'.join(playlist)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment