import gobject import sys import thread from song import Song from cline import CLine from duration import Duration from library import Library #import cmnds class main: def __init__(self,argv): if len(argv) == 0: print "python ocarina.py /path/to/song/" return self.commands = CLine() self.registerCmnds() self.song = Song(argv[0],self.quit,self.commands.printLines) self.song.play() self.library = Library(self.commands.printLines) # 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,()) # 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") self.commands.register("lib",self.scanLib,"Create a library based on the directory passed in") # Quit program def quit(self,unused): self.commands.quit() self.library.dump() print "Quitting..." sys.exit(0) # Begin playback def play(self,unused): self.song.play() # Pause music def pause(self,unused): self.song.pause() # Show running time info def time(self,unused): cur = self.song.curTime() tot = self.song.length self.commands.printLine(cur.toStr()+" / "+tot.toStr()) # Show detailed song info def info(self,unused): # 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,unused): # 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])) def scanLib(self,dir): if dir == "": self.commands.printLine("Please include a library directory") return self.library.scan(dir) if __name__=='__main__':main(sys.argv[1:])