toe
the book about my idle plot on a vague anxiety
- アーティスト: toe
- 出版社/メーカー: CATUNE
- 発売日: 2005/08/31
- メディア: CD
- 購入: 7人 クリック: 119回
- この商品を含むブログ (210件) を見る
早く次の音を聴いてみたい。
cuiTunesをもうちょっと引っ張る。ボリュームをいじれるようにしました。
にしても、optparseのヘルプはあまりいけてない。help="..."で指定できる文字列に改行を入れることができない。
なんかいい方法はあるのかな?
#! /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 <syobosyobo@gmail.com>" __version__ = "0.0.4" import os import sys def main(): from optparse import OptionParser import appscript itunes = appscript.app('iTunes') parser = OptionParser(version=__version__) parser.add_option("-c", "--command", action="store", type="string", dest="command", help="ex. -c pause : stop music.") parser.add_option("-o", "--open", action="store_true", dest="apl_start", help="active iTunes.") parser.add_option("-e", "--end", action="store_true", dest="apl_end", help="deactive iTunes.") parser.add_option("-s", "--search", action="store", type="string", dest="searchword", help="ex. -s toe") parser.add_option("-v", "--volume", action="store", type="string", dest="volume", help="volume change. [ex. \"+10\"->now:10,aft:20;" \ " \"-10\"->now:20,aft:10; \"10\"->now:30,aft:10;") (opts, args) = parser.parse_args() if opts.apl_start: os.system('open -a itunes') return 0 if opts.apl_end: comstr = "ps aux | grep iTunes | grep -v grep | grep -v Helper |" + \ "awk '{ print \"kill \",$2 }' | sh" os.system(comstr) return 0 if opts.searchword: pass if opts.volume: now_volume = itunes.sound_volume() print "before volume : %d" % now_volume print opts.volume[0] try: volume = int(opts.volume) except ValueError: print "Not Support value." return 1 if opts.volume[0] == '+': if now_volume + volume >= 100: set_volume = 100 else: set_volume = now_volume + volume elif opts.volume[0] == '-': if now_volume <= volume: set_volume = 0 else: set_volume = now_volume + volume else: set_volume = volume itunes.sound_volume.set(set_volume) now_volume = itunes.sound_volume() print "now volume : %d" % now_volume now_volume = itunes.sound_volume() 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__': if sys.platform != 'darwin': print "Sorry, This tool is used in MacOSX." sys.exit(1) print __doc__ sys.exit(main())