Skip to content

Instantly share code, notes, and snippets.

@nkpro2000
Created June 22, 2020 19:11
Show Gist options
  • Save nkpro2000/ac566ff0ef44491de921e92a66ce79a2 to your computer and use it in GitHub Desktop.
Save nkpro2000/ac566ff0ef44491de921e92a66ce79a2 to your computer and use it in GitHub Desktop.
To create playlist.m3u in alphabetical order from directory
from urllib.parse import quote
import os
playlist_name = input("Enter playlist name >")
dir_path = input("Enter directory path >")
dir_path = os.path.abspath(dir_path)
songs = os.listdir(dir_path)
songs = list(map((lambda x:os.path.join(dir_path, x)), songs))
with open(playlist_name+'.m3u', 'w') as playlist:
for song in songs:
playlist.write("file://"+quote(song)+"\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment