Created
April 27, 2010 00:06
-
-
Save Cam1337/380121 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
################################# | |
#Created by Cam irc://irc.freenode.net/#botters | |
################################# | |
import commands; | |
import os; | |
import random; | |
import sys; | |
args=sys.argv[1] | |
artist=commands.getoutput("osascript -e 'tell application \"iTunes\" to artist of current track as string'"); | |
track=commands.getoutput("osascript -e 'tell application \"iTunes\" to name of current track as string'"); | |
state=commands.getoutput("osascript -e 'tell application \"iTunes\" to player state as string'"); | |
currentvolume=commands.getoutput("osascript -e 'tell application \"iTunes\" to sound volume as integer'") | |
def showHelp(): | |
print "------------------------------"; | |
print "iTunes Python[shell] Interface"; | |
print "------------------------------"; | |
print "Options:"; | |
print " status = Shows iTunes' status, current artist and track."; | |
print " play = Start playing iTunes."; | |
print " pause = Pause iTunes."; | |
print " next = Go to the next track."; | |
print " prev = Go to the previous track."; | |
print " mute = Mute iTunes' volume."; | |
print " unmute = Unmute iTunes' volume."; | |
print " up = Increase iTunes' volume by 10%"; | |
print " down = Increase iTunes' volume by 10%"; | |
print " vol # = Set iTunes' volume to # [0-100]"; | |
print " quit = Quit iTunes."; | |
def status(): | |
if (state=="playing"): | |
print "Itunes is: %s" % state | |
print "Currently playing: '%s' by '%s'" % (track, artist) | |
else:print "Itunes it not playing, type 'itunes play' to start playing music" | |
def play(): | |
if(state=="paused"): | |
print "Playing iTunes" | |
commands.getoutput("osascript -e 'tell application \"iTunes\" to play'") | |
print "Currently playing: '%s' by '%s'" % (track, artist) | |
else:print "Itunes is currently playing" | |
def pause(): | |
if(state=="playing"): | |
print "Pausing iTunes" | |
commands.getoutput("osascript -e 'tell application \"iTunes\" to pause'") | |
print "iTunes paused" | |
else:print "iTunes is currently paused" | |
def nsong(): | |
print"Skipping to next song" | |
commands.getoutput("osascript -e 'tell application \"iTunes\" to next track'") | |
print "Currently playing: '%s' by '%s'" % (track, artist) | |
def psong(): | |
print"Rewinding to previous song" | |
commands.getoutput("osascript -e 'tell application \"iTunes\" to previous track'") | |
status() | |
#Jesse, we need to fix that shit... it runs to quickly | |
def iquit(): | |
print "Quitting iTunes" | |
commands.getoutput("osascript -e 'tell application \"iTunes\" to quit'") | |
def mute(): | |
print "Muting iTunes" | |
commands.getoutput("osascript -e 'tell application \"iTunes\" to set mute to true'") | |
def unmute(): | |
print "Unmuting iTunes" | |
commands.getoutput("osascript -e 'tell application \"iTunes\" to set mute to false'") | |
def volup(): | |
increaseby=10 | |
if (currentvolume=="100"):increaseby=0; | |
elif(currentvolume>"90"):increaseby=100-int(currentvolume); | |
elif(currentvolume<"90"):increaseby=10; | |
newvolume=int(currentvolume)+increaseby | |
commands.getoutput("osascript -e 'tell application \"iTunes\" to set sound volume to "+str(newvolume)+"'"); | |
print "Your current volume is: %d" % (int(commands.getoutput("osascript -e 'tell application \"iTunes\" to sound volume as integer'"))) | |
def voldown(): | |
decreaseby=10 | |
if (currentvolume=="0"):decreaseby=0; | |
elif(currentvolume<"10"):decreaseby=int(currentvolume) | |
elif(currentvolume>"10"):decreaseby=10; | |
newvolume=int(currentvolume)-decreaseby | |
commands.getoutput("osascript -e 'tell application \"iTunes\" to set sound volume to "+str(newvolume)+"'"); | |
print "Your current volume is: %d" % (int(commands.getoutput("osascript -e 'tell application \"iTunes\" to sound volume as integer'"))) | |
def volexact(): | |
newvolume=sys.argv[2] | |
commands.getoutput("osascript -e 'tell application \"iTunes\" to set sound volume to "+str(newvolume)+"'"); | |
print "Your current volume is: %d" % (int(commands.getoutput("osascript -e 'tell application \"iTunes\" to sound volume as integer'"))) | |
#PARSE ARGS | |
if (args=="status"):status(); | |
elif (args=="play"):play(); | |
elif (args=="pause"):pause(); | |
elif (args=="next"):nsong(); | |
elif (args=="quit"):iquit(); | |
elif (args=="prev"):psong(); | |
elif (args=="mute"):mute(); | |
elif (args=="unmute"):unmute(); | |
if (args=="vol"):volexact(); | |
#I just realized I should have only looked for "up" or "down" .... too late I did all of the below code :\ | |
#voldu = sys.argv[1:len(sys.argv)-1][0]+" "+sys.argv[1:len(sys.argv)-1][1] | |
elif(sys.argv[1]=="up"):volup(); | |
elif(sys.argv[1]=="down"):voldown(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you post command.py it's being called in the program but not showing here on the gist. It's also not a repo available on your GitHub.
Great looking code.
So it looks like 'commands' has been deprecated and subprocess takes its place.