2 import sys
, os
, os
.path
3 from shuffle
import Track
, ShuffleDB
7 "dirs" : ("Podcasts",),
10 "dirs" : ("Yoga","Podcasts"),
15 print "Usage: update_shuffle.py PROFILE"
18 if not profiles
.has_key(sys
.argv
[1]):
19 print "Unknown profile: " + sys
.argv
[1]
22 profile
= profiles
[sys
.argv
[1]]
25 root
= os
.path
.dirname(sys
.argv
[0])
30 control
= os
.path
.join(root
, "iPod_Control", "iTunes")
34 root
= os
.path
.abspath(root
)
35 control
= os
.path
.abspath(control
)
37 print "Loading old database"
40 tracks
, pstate
= db
.read_all()
41 Track
.set_old_tracks( tracks
)
42 for i
in xrange(len(tracks
)):
46 print "Searching for new files"
49 for profile_dir
in profile
['dirs']:
50 for root
, dirs
, files
in os
.walk( profile_dir
):
52 if f
.endswith(Track
.supported_file_types
):
53 ipod_path
= u
"/" + os
.path
.join(root
,f
).replace("\\","/")
54 t
= Track
.new( ipod_path
)
55 if ipod_path
.lower().startswith((u
"/book/", u
"/podcasts/")):
60 old_current
= Track
.old_tracks
[ pstate
.trackno
]
61 print "old current:", old_current
63 for i
in xrange( len(tracks
) ):
64 if tracks
[i
] == old_current
:
68 # if we set these to correct numbers we might override existing bookmark
74 print "Writing new database"
76 for i
in xrange(len(tracks
)):
79 db
.write_all(tracks
, pstate
)
80 if os
.path
.exists("iTunesShuffle"):
81 os
.remove("iTunesShuffle") # let the player recreate it