Skip to content

Instantly share code, notes, and snippets.

@chrisglass
Created February 8, 2013 07:45
Show Gist options
  • Save chrisglass/4737334 to your computer and use it in GitHub Desktop.
Save chrisglass/4737334 to your computer and use it in GitHub Desktop.
Given a playlist, copy all the music files it contains to a /tmp folder.
#!/usr/bin/python
import os
import urllib
import shutil
lines = []
playlist = "/tmp/Test.pls"
playlist_name = playlist.split("/")[-1]
playlist_name = playlist_name.split(".")[0]
destination_folder = "/tmp/%s" % playlist_name
if not os.path.exists(destination_folder):
os.mkdir(destination_folder)
with open(playlist, "r") as f:
lines = f.readlines()
for line in lines:
if "file://" in line:
# Strip all that isn't the URL
line = line.split("=")[1]
# Remove the trailin /n
line = line.replace("\n", "")
# remove the leading "file://"
line = line.replace("file://", "")
nice_line = urllib.unquote(line)
#nice_line = nice_line.replace(" ", "\ ")
#nice_line = nice_line.replace("(", "\(")
#nice_line = nice_line.replace(")", "\)")
filename = nice_line.split("/")[-1]
if os.path.exists(nice_line):
destination = destination_folder + "/" + filename
shutil.copyfile(nice_line, destination)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment