From 303a09d9da9aeb679a627d88887db3f04a0d7baa Mon Sep 17 00:00:00 2001 From: Nicholas Piper Date: Sun, 7 May 2006 21:47:32 +0000 Subject: Allow add_song.py to create a playlist to put the new tracks into git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1259 f01d2545-417e-4e96-918e-98f8d0dbbcb6 --- bindings/python/examples/add_song.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'bindings/python/examples') diff --git a/bindings/python/examples/add_song.py b/bindings/python/examples/add_song.py index a913d1d..6a37bb6 100755 --- a/bindings/python/examples/add_song.py +++ b/bindings/python/examples/add_song.py @@ -60,6 +60,8 @@ parser = OptionParser() parser.add_option("-m", "--mountpoint", dest="mountpoint", default="/mnt/ipod", help="use iPod at MOUNTPOINT", metavar="MOUNTPOINT") +parser.add_option("-l", "--playlist", dest="playlist", + help="add tracks to PLAYLIST", metavar="PLAYLIST") parser.add_option("-p", "--podcast", dest="ispodcast", action="store_true", @@ -72,6 +74,15 @@ if len(args) == 0: db = gpod.Database(options.mountpoint) +playlist = None +if options.playlist: + for pl in db.Playlists: + if pl.name == options.playlist: + playlist = pl + if not playlist: + print "Creating new playlist" + playlist = gpod.Playlist(db,title=options.playlist) + for path in args: deleteWhenDone = [] transport = urlparse.urlsplit(path)[0] @@ -86,22 +97,24 @@ for path in args: deleteWhenDone.pop() continue - track = gpod.Track(from_file=path, podcast=options.ispodcast) + try: + track = gpod.Track(from_file=path, podcast=options.ispodcast) + except gpod.TrackException, e: + print "Exception handling %s: %s" % (path, e) + continue db.add(track) if options.ispodcast: - playlists = [db.Podcasts] + playlists = [db.Podcasts, playlist] print "Adding Podcast %s (%s)" % (path,track) else: - playlists = [db.Master] + playlists = [db.Master, playlist] print "Adding Song %s (%s)" % (path,track) - for playlist in playlists: - print " adding to playlist %s" % playlist - playlist.add(track) - print " added to playlist %s" % playlist - - print " added Song %s (%s)" % (path,track) + for pl in playlists: + if pl: + print " adding to playlist %s" % pl + pl.add(track) track.copy_to_ipod() -- cgit