]>
code.delx.au - notipod/blob - notipod_cli.py
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:])
33 opts
.dest
= args
[0].decode("utf-8")
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
= libnotipod
.ITunesLibrary
.alloc().init()
56 gen
= library
.load_(opts
.itunes_library
)
60 for playlist
in opts
.playlists
:
61 if not library
.has_playlist_name(playlist
):
62 logging
.fatal("Could not find playlist: " + playlist
)
65 logging
.info("Loading playlists")
67 for playlist
in opts
.playlists
:
68 tracks
= library
.get_playlist_name(playlist
).tracks
69 all_tracks
.extend(tracks
)
70 libnotipod
.export_m3u(opts
.dry_run
, opts
.dest
,
71 opts
.path_prefix
, playlist
, tracks
)
73 logging
.info("Synchronising")
74 gen
= libnotipod
.sync(opts
.dry_run
, library
.folder
, opts
.dest
, all_tracks
)
79 if __name__
== "__main__":