summaryrefslogtreecommitdiffstats
path: root/bindings/python/examples/play.py
blob: 352e24340c2362dd54532e6dd2f6574e80a29d8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python

##  Copyright (C) 2005 Nick Piper <nick-gtkpod at nickpiper co uk>
##  Part of the gtkpod project.
 
##  URL: http://www.gtkpod.org/
##  URL: http://gtkpod.sourceforge.net/

##  The code contained in this file is free software; you can redistribute
##  it and/or modify it under the terms of the GNU Lesser General Public
##  License as published by the Free Software Foundation; either version
##  2.1 of the License, or (at your option) any later version.

##  This file is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
##  Lesser General Public License for more details.

##  You should have received a copy of the GNU Lesser General Public
##  License along with this code; if not, write to the Free Software
##  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

##  $Id$


# this file is just a little example I use for testing, it doesn't
# play the music, but plays with the database ;-)

import os, os.path
import gpod
import sys

ipod_mount = '/mnt/ipod'

remove_track = "The Dancer"

dbname = os.path.join(os.environ['HOME'],".gtkpod/iTunesDB")
#dbname = os.path.join(os.environ['HOME'],".gtkpod/local_0.itdb")
#dbname = os.path.join(ipod_mount,"iPod_Control/iTunes/iTunesDB")

itdb = gpod.itdb_parse_file(dbname, None)
if not itdb:
    print "Failed to read %s" % dbname
    sys.exit(2)
itdb.mountpoint = ipod_mount

for playlist in gpod.sw_get_playlists(itdb):
    print playlist.name
    print gpod.itdb_playlist_tracks_number(playlist)
    for track in gpod.sw_get_playlist_tracks(playlist):
        print track.title
    
for track in gpod.sw_get_tracks(itdb):
    lists = []
    for playlist in gpod.sw_get_playlists(itdb):
        if gpod.itdb_playlist_contains_track(playlist, track):
            lists.append(playlist)

    print "%-25s %-20s %-20s %-30s %s" % (track.title,
                                          track.album,
                                          track.artist,
                                          gpod.itdb_filename_on_ipod(track),
                                          repr(",".join([l.name for l in lists])))

    if track.title == remove_track:
        print "Removing track.."
        print "..disk"
        os.unlink(gpod.itdb_filename_on_ipod(track))
        for l in lists:
            print "..playlist %s" % l.name
            gpod.itdb_playlist_remove_track(l, track)
        print "..db"
        gpod.itdb_track_unlink(track)
        print "Track removed."

gpod.itdb_write_file(itdb, dbname, None)