export a *portable* playlist, including music files

Matt Price matt.price-H217xnMUJC0sA/PxXw9srA at public.gmane.org
Fri Oct 23 13:37:20 UTC 2009


On Thu, 2009-10-22 at 20:37 -0400, Kyle O'Donnell wrote:
> find /path/to/music -name "*.mp3..." > file.m3u
> 
> 
> then when you move the m3u file over make sure the path is the same or
> use  sed or vi to mass change if diff

that solution is totally straightforward, but doesn't really generate
the experience i'm looking for.  in the old days we would sit around a
record player together and make a mixed tape, which we would then
duplicate on our crappy tape-to-tape recorder, and distribute to each
other as a kind of present.  the recordings were terrible, but we shared
the experience in a casual way; it was a mode of friendship.  i'd like
to be able to sit around with my music collection -- and for me, right
now, that means a GUI of some kind where i can search for and casually
play clips from individual files --  and generate a playlist for
friends, then send it to them in a way that lets them just trivially
enjoy the experience.  

i have a kind of idea, though i'm not sure whether it'll work for
windows users with their forward slashes.  it goes like this:

create an m3u playlist with whatever gui tool.  Then parse it for file
names, copy those files to a new directory, and rewrite the playlistso
that it refers to the new files.  

Below is some quick python code i just put together to do this. does
anyone have a better suggestion -- maybe using pure shell scripting, for
instance?   

anyway here's what i've got so far:

#!/usr/bin/python 


# usage:
# playlistExporter.py -i oldplaylist -o newdirectory -n playlistname

import os.path, sys, shutil
from optparse import OptionParser

# parse the command line first
parser = OptionParser()
parser.add_option ("-i", "--input", dest="inputFile",
default="~/playlist.m3u",
                   help="get playlist from FILE",
                   action="store", type="string", )
parser.add_option("-o", "--output", dest="newFolder",
default="~/NewPlaylist",
                  action="store", type="string",
                  help="save songs and playlist to")
parser.add_option("-n", "--name", dest="playlistName",
default="myplaylist",
                  action="store", type="string",
                  help="save songs and playlist to")
(options, args) = parser.parse_args()

# now start the real script
# read the playlist, writing the song names to a new list
# called "songs"
oldPlaylist=open(options.inputFile)
songs=[]
newPlaylistText=""
while 1:
    line=oldPlaylist.readline()
    if not line:
        break
    if line[0] != "#":
        clean=line.strip('\n')
        songs.append(clean)

# create the new directory if it doesn't exist already
newDir = os.path.abspath(options.newFolder)
if not os.path.isdir(newDir):
    os.mkdir(newDir)

# copy the files and create the playlist
for song in songs:
    print(song)
    song=os.path.abspath(song)
    print(song)
    shutil.copy2(song,newDir)
    newPath=os.path.join("./", os.path.basename(song))
    newPlaylistText += "newPath" + "\n"

# write the new playlist to a file
newPlaylist=open(os.path.join(newDir,options.playlistName + ".m3u"),"w")
newPlaylist.write(newPlaylistText)
newPlaylist.close


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://gtalug.org/pipermail/legacy/attachments/20091023/c11b641d/attachment.sig>


More information about the Legacy mailing list