]>
code.delx.au - notipod/blob - syncitunes.py
16c64bfb6c136e4855e65ce022d6f92393d6c6a6
14 parser
= optparse
.OptionParser(version
="%prog " + VERSION
,
15 description
= "Synchronise an iTunes playlist with a directory",
16 usage
= "%prog destination playlist [playlist ...]"
18 parser
.add_option("-q", "--quiet",
19 action
="store_true", dest
="quiet", default
=False)
20 parser
.add_option("-v", "--verbose",
21 action
="store_true", dest
="verbose", default
=False)
22 parser
.add_option("-n", "--dry-run",
23 action
="store_true", dest
="dry_run", default
=False)
24 parser
.add_option("--itunes-library",
25 action
="store", dest
="itunes_library", default
=None)
26 parser
.add_option("--path-prefix",
27 action
="store", dest
="path_prefix", default
="E:")
29 opts
, args
= parser
.parse_args(sys
.argv
[1:])
34 opts
.playlists
= args
[1:]
39 opts
= parse_options()
42 logging
.basicConfig(format
="%(levelname)s: %(message)s")
44 logging
.getLogger().setLevel(logging
.CRITICAL
)
46 logging
.getLogger().setLevel(logging
.DEBUG
)
48 logging
.getLogger().setLevel(logging
.INFO
)
50 if not os
.path
.isdir(opts
.dest
):
51 logging
.fatal("Destination must be specified as an absolute path.")
54 logging
.info("Loading library")
55 library
= libsyncitunes
.ITunesLibrary
.alloc()
56 if opts
.itunes_library
:
57 library
= library
.initWithFilename_(opts
.itunes_library
)
59 library
= library
.init()
61 for playlist
in opts
.playlists
:
62 if not library
.has_playlist_name(playlist
):
63 logging
.fatal("Could not find playlist: " + playlist
)
66 logging
.info("Loading playlists")
68 for playlist
in opts
.playlists
:
69 tracks
= library
.get_playlist_name(playlist
).tracks
70 all_tracks
.extend(tracks
)
71 libsyncitunes
.export_m3u(opts
.dry_run
, opts
.dest
, opts
.path_prefix
,
74 logging
.info("Synchronising")
75 libsyncitunes
.sync(opts
.dry_run
, library
.folder
, opts
.dest
, all_tracks
)
78 if __name__
== "__main__":