cuiTunes
WindowsからMacに入って作業していると、Mac側のiTunesをCUIで制御したくなります。無性に。
Pythonでappscriptを利用して、iTunesをCUIで制御できるほんのちょっとだけ便利なツールを作りました。
$ cuitunes -c play # 再生 $ cuitunes -c info # 情報表示 $ cuitunes -c next # 次の曲へ $ cuitunes -h # 詳しくはヘルプを
以下はソースです。
#! /usr/bin/env python """ iTunes CUI Wrapper tool. - pause - play - next_track(next) - back_track(back) - previous_track(previous) - album - artist - played_count(count) - info - random """ __author__ = "Hideo Hattori" __version__ = "0.0.2" import sys def main(*argv): from optparse import OptionParser import appscript itunes = appscript.app('iTunes') parser = OptionParser() parser.add_option("-c", "--command", action="store", type="string", dest="command", help="ex. -c pause : stop music.") (opts, args) = parser.parse_args() if opts.command: if opts.command in ["next", "back", "previous"]: command = opts.command + "_track" exec("itunes.%s()" % command) elif opts.command in ["artist", "album"]: exec("print itunes.current_track.%s.get()" % opts.command) elif opts.command in ["count", "played_count"]: print itunes.current_track.played_count.get() elif opts.command == "info": print "Artist : %s" % itunes.current_track.artist.get() print "Album : %s" % itunes.current_track.album.get() print "Play Count : %s" % itunes.current_track.played_count.get() elif opts.command == "random": ## shuffling of Album. itunes.current_playlist.shuffle.set(True) command = "next_track" tnumber = int(itunes.current_track.track_number.get()) tcount = int(itunes.current_track.track_count.get()) for i in range(tcount - tnumber + 1): exec("itunes.%s()" % command) itunes.current_playlist.shuffle.set(False) else: command = opts.command exec("itunes.%s()" % command) return 0 if __name__ == '__main__': print __doc__ sys.exit(main(*sys.argv))
wikiにも載せてます。
http://f59.aaa.livedoor.jp/~ookini/pukiwiki.php?cuiTunes