import gobject import sys import thread from song import Song from cline import CLine from duration import Duration #import cmnds class main: def __init__(self,argv): if len(argv) == 0: print "python ocarina.py /path/to/song/" self.commands = CLine() self.registerCmnds() lines = ["test","testing","final test"] self.commands.printLines(lines) self.song = Song(argv[0],self.quit,self.commands.printLines) #self.song.play() # Start main loop as a thread so we can get bus calls and use command line gobject.threads_init() mainloop = gobject.MainLoop() thread.start_new_thread(mainloop.run,()) # Quit program def quit(self): self.commands.quit() print "Quitting..." sys.exit(0) # Register commands for use in command line def registerCmnds(self): self.commands.register("quit",self.quit,"Exit ocarina") self.commands.register("exit",self.quit,"Exit ocarina") self.commands.register("play",self.play,"Play current song") self.commands.register("pause",self.pause,"Pause current song") self.commands.register("time",self.time,"Display running time") self.commands.register("info",self.info,"Display detailed info about current song") self.commands.register("this",self.this,"Display basic info about current song") # Begin playback def play(self): self.song.play() # Pause music def pause(self): self.song.pause() # Show running time info def time(self): cur = self.song.curTime() tot = self.song.length self.commands.printLine(cur.toStr()+" / "+tot.toStr()) # Show detailed song info def info(self): # Return if no tags found if self.song.taglist == None: self.commands.printLine("Could not find any tags") return for tag in self.song.taglist.keys(): self.commands.printLine(tag+": "+str(self.song.taglist[tag])) # Show basic song info def this(self): # Return if no tags found if self.song.taglist == None: self.commands.printLine("Could not find any tags") return fields = ["title","artist","track-number","track-count","album"] for field in fields: if (field in self.song.taglist.keys()) == True: self.commands.printLine(field+": "+str(self.song.taglist[field])) if __name__=='__main__':main(sys.argv[1:])