1 # console interface to jamaui/jamaendo
3 # debugging hack - add . to path
5 local_module_dir = os.path.join(os.path.dirname(sys.argv[0]), '..')
6 if os.path.isdir(local_module_dir):
7 sys.path.append(local_module_dir)
9 from jamaendo.api import LocalDB, Query, Queries, refresh_dump
10 from jamaui.player import Player, Playlist
14 gobject.threads_init()
16 class Refresher(object):
20 print "Preparing local database..."
21 def complete(self, status):
23 def progress(self, percent):
24 if percent - self.last_percent >= 5:
25 print "\r%d%%" % (percent),
26 self.last_percent = percent
29 refresh_dump(self.complete, self.progress, force=False)
36 print simplejson.dumps(x, sort_keys=True, indent=4)
38 class Console(object):
51 getattr(self, "query_"+query)()
53 print "Valid queries: " + ", ".join(queries)
55 def query_today(self):
56 result = Queries.albums_today()
59 def query_tracks_this_month(self):
60 result = Queries.tracks_this_month()
63 def query_artist(self):
67 for artist in db.search_artists(q):
70 def query_album(self):
74 for album in db.search_albums(q):
75 print "%s: %s - %s" % (album['id'], album['artist'], album['name'])
77 def query_play_track(self):
78 trackid = int(sys.argv[2])
79 uri = Query.track_mp3(trackid)
80 playlist = Playlist([uri])
84 while player.playing():
87 def query_play_album(self):
88 albumid = int(sys.argv[2])
92 for a in db.get_albums([albumid]):
97 print "%s - %s" % (album['artist'], album['name'])
99 playlist = Playlist(album['tracks'])
101 player.play(playlist)
103 while player.playing():
106 except KeyboardInterrupt:
109 if __name__=="__main__":