File: play_with_smart_playlists.py

package info (click to toggle)
libgpod 0.8.2-7
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,532 kB
  • sloc: ansic: 26,876; sh: 11,215; cs: 1,399; python: 1,251; makefile: 472; cpp: 296; xml: 100
file content (55 lines) | stat: -rwxr-xr-x 2,374 bytes parent folder | download | duplicates (10)
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
#!/usr/bin/python

##  Copyright (C) 2006 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


import gpod
import time
from optparse import OptionParser

parser = OptionParser()
parser.add_option("-m", "--mountpoint", dest="mountpoint",
                  default="/mnt/ipod",
                  help="use iPod at MOUNTPOINT", metavar="MOUNTPOINT")
(options, args) = parser.parse_args()


itdb = gpod.itdb_parse(options.mountpoint, None)
if not itdb:
    print "Failed to read iPod at %s" % options.mountpoint
    sys.exit(2)
itdb.mountpoint = options.mountpoint

for playlist in gpod.sw_get_playlists(itdb):
  if playlist.is_spl:
      n = gpod.sw_get_list_len(playlist.splrules.rules)
      splrules = [gpod.sw_get_rule(playlist.splrules.rules,i) for i in xrange(n)]
      print "Playlist: %s" % playlist.name
      for i in xrange(gpod.sw_get_list_len(playlist.splrules.rules)):
          rule = gpod.sw_get_rule(playlist.splrules.rules, i)
          print "|  field: %4d          action: %4d    |"  % (rule.field,rule.action)
          print "|  string: %25s    |"                     % rule.string
          print "|  fromvalue: %4d    fromdate: %4d    |"  % (rule.fromvalue,rule.fromdate)
          print "|  fromunits: %4d                      |" % rule.fromunits
      print "Contains:"
      for track in gpod.sw_get_playlist_tracks(playlist):
          print track.title, track.artist, time.strftime("%c",
                                                         time.localtime(track.time_added - 2082844800))