Created
February 8, 2019 21:30
-
-
Save EllieTheYeen/d561740dee547753c3023228a89c7381 to your computer and use it in GitHub Desktop.
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
import urllib | |
import sys | |
import os | |
def tourlpath(a): | |
drive, path = os.path.abspath(a).replace('\\', '/').split('/', 1) | |
return 'file:///' + drive + '/' + urllib.quote(path) | |
if len(sys.argv) < 2: exit('Specify the directory') | |
directory = sys.argv[1] | |
outfile = open('playlist.xspf', 'w') | |
outfile.write( | |
'<?xml version="1.0" encoding="UTF-8"?>' | |
'<playlist xmlns="http://xspf.org/ns/0/" xmlns:vlc="http://www.videolan.org/vlc/playlist/ns/0/" version="1">' | |
'<title>Playlist</title>' | |
'<trackList>\n'); | |
for folder, folders, files in os.walk(directory): | |
for file in files: | |
if not file.lower().endswith(('.mp3', '.mp4', '.wma', '.flac', '.ogg')): continue | |
path = tourlpath(os.path.join(folder, file)) | |
outfile.write('<track><location>%s</location></track>\n' % path) | |
outfile.flush() | |
outfile.write( | |
'</trackList>' | |
'<extension application="http://www.videolan.org/vlc/playlist/0">' | |
'<vlc:item tid="0"/>' | |
'</extension>' | |
'</playlist>\n'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment