def play(request): with CustMPDClient.GetClient() as mpd: if mpd.status().get('state', None) == 'play': mpd.pause() else: mpd.play() return HttpResponse("OK")
def playlist_info(request): with CustMPDClient.GetClient() as mpd: data = {} data['info'] = mpd.playlistinfo() data['playlist'] = mpd.playlist() return data
def status(request): with CustMPDClient.GetClient() as mpd: data = mpd.status() data.update(mpd.currentsong()) data.update(mpd.stats()) return data
def remove_songs(request): post = request.POST with CustMPDClient.GetClient() as mpd: for song in json.loads(post['songs']): song = int(song) mpd.deleteid(song) return HttpResponse("OK")
def save_playlist(request): name = request.POST['name'] with CustMPDClient.GetClient() as mpd: try: mpd.rm(name) except: pass mpd.save(name) return HttpResponse("OK")
def add_songs(request): post = request.POST with CustMPDClient.GetClient() as mpd: for song in json.loads(post['songs']): mpd.add(song) return HttpResponse("OK")
def volume(request, volume): with CustMPDClient.GetClient() as mpd: mpd.setvol(volume) volume = mpd.status()['volume'] return HttpResponse("Volume: %s" % volume)
def random(request): with CustMPDClient.GetClient() as mpd: random = int(mpd.status()['random']) mpd.random(0 if random == 1 else 1) return HttpResponse("Random: %s" % random)
def repeat(request): with CustMPDClient.GetClient() as mpd: repeat = int(mpd.status()['repeat']) mpd.repeat(0 if repeat == 1 else 1) return HttpResponse("Repeat: %s" % repeat)
def play_song(request, song_id): with CustMPDClient.GetClient() as mpd: mpd.playid(song_id) return HttpResponse("Playing Song %s." % song_id)
def stop(request): with CustMPDClient.GetClient() as mpd: mpd.stop() return HttpResponse("OK")
def next(request): with CustMPDClient.GetClient() as mpd: mpd.next() return HttpResponse("OK")
def prev(request): with CustMPDClient.GetClient() as mpd: mpd.previous() return HttpResponse("OK")
def all_songs(request, page=0): with CustMPDClient.GetClient() as mpd: mpd.iterate = True data = [x for x in mpd.listallinfo('/')[10 * page:10 * (page + 1) - 1]] return data
def update_library(request): with CustMPDClient.GetClient() as mpd: mpd.update() return HttpResponse("OK")
def clear_songs(request): with CustMPDClient.GetClient() as mpd: mpd.clear() return HttpResponse("OK")