Home > Uncategorized > Sharing Playlists

Sharing Playlists

October 24th, 2009

OK, so here’s the problem: in the old days, if you wnated to share music, you would make your friends a mixed tape. This might even be a soical activity in which you sat around with your friends, possibly stoned, and laboriously copied songs one at a tie from your record player to a cassette.

In some ways this is a lot easier now. If you want to share music with your friends, you can just send them the mp3 files you’ve been listening to, maybe using Dropbox or something similar. Then htey import the music into their ocllection, using whatever tool (for most of my friends, it’s iTunes; for me it’s variously rhythmbox, amarok, or lately, goggles music manager. But when you do htat, you get the music without the playlist order. Alternatively, you can create a playlist (m3u, pls, xsmp, or i guess there are some nonfree formats) and send that to your friend — but when you do htat the file references will be all messed up, and even if your friend has the usic, they won’t be able to play it.

I have a partial solution, which works like this: use whatever tool to export an m3u playlist. Then run a script that reads the playlist, copies the music files into a new directory, then drops a modified playlist into the same directory — one which refers only to the *new*ly-created music files. Then you can drop that directory right into dropbox or whatever, and your friends should be able to play your music.

There’s stil la problem with this — the new music doesn’t get automatically added to your friend’s collection; and if she does add the files, she’s likely to end up with duplicates. So a better solution would

  • write the playlist in a more sophisticated format, probably xsmp
  • include some kind of a plugin for the usic application, which imported the playlist, checked the music collection for duplicates, and then imported the missing songs into the collection. Some music programs may already do this — does anyone know if iTunes does?

Despite the deficiencies, my current code is useful enough to share, so here it is. I’d love to hear back with some suggestions for improvements.

#!/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

admin Uncategorized

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.