Skip to content

Instantly share code, notes, and snippets.

@vcsekhar
Forked from Decad/playlist.py
Created October 20, 2016 04:06
Show Gist options
  • Save vcsekhar/0e35b3eb4b8d3550b313a10ad0ca7ffc to your computer and use it in GitHub Desktop.
Save vcsekhar/0e35b3eb4b8d3550b313a10ad0ca7ffc to your computer and use it in GitHub Desktop.
Make a vlc playlist for a directory
from xml.dom.minidom import Document
import os
import sys
validExt = ('.avi') #only add files with these extensions to the playlist
if(len(sys.argv) > 1):
rootdir = sys.argv[1]+'/'
print(sys.argv[1])
else:
rootdir = os.getcwd()+'/'
def createTrack(file, path):
track = doc.createElement("track")
tracklist.appendChild(track)
location = doc.createElement("location")
locationText = doc.createTextNode('file:///'+path+file)
location.appendChild(locationText)
track.appendChild(location)
doc = Document()
playlist = doc.createElement("playlist")
playlist.setAttribute("version","1")
playlist.setAttribute("xmlns","http://xspf.org/ns/0/")
playlist.setAttribute("xmlns:vlc","http://www.videolan.org/vlc/playlist/ns/0/")
doc.appendChild(playlist)
title = doc.createElement("title")
titlet = doc.createTextNode("Playlist")
title.appendChild(titlet)
playlist.appendChild(title)
tracklist = doc.createElement("trackList")
playlist.appendChild(tracklist);
for subdir, dirs, files in os.walk(rootdir):
for file in files:
ext = os.path.splitext(file)
if(ext[1] in validExt):
createTrack(file, subdir)
f = open(rootdir+"playlist.xspf",'w')
f.write(doc.toxml())
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment