def start(host): mpd_client = yield from ampdclient.connect(host, 6600) mpd_client.cb_onchange = onchange print('status') status = yield from mpd_client.status() print('Status {} '.format(status)) print('stats') stats = yield from mpd_client.stats() print('Stats {} '.format(stats)) yield from mpd_client.close()
def start(): mpd_client = yield from ampdclient.connect(MPD_HOST, MPD_PORT) mpd_client.cb_onchange = onchange resp = yield from mpd_client.lsinfo('nas-samba') print('Response {}'.format(resp)) yield from asyncio.sleep(1) resp = yield from mpd_client.lsinfo('nas-samba/testpl') print('Response {}'.format(resp)) yield from asyncio.sleep(1) resp = yield from mpd_client.lsinfo('nas-samba/Albums/Alternative ' 'Rock/Arcade Fire/2004 - ' 'Funeral') print('Response {}'.format(resp)) yield from mpd_client.close()
def start(): mpd_client = yield from ampdclient.connect(MPD_HOST, MPD_PORT) mpd_client.cb_onchange = onchange try: resp = yield from mpd_client.command('foobar') # This will never be displayed: print('No Mpd client Exception : {}'.format(resp)) except ampdclient.MpdCommandException as e: print('Mpd client Exception : {}'.format(e)) # the error should be displayed # but it does not seem to be true for all errors status = yield from mpd_client.status() print('Status: {}'.format(status)) yield from mpd_client.clearerror() status = yield from mpd_client.status() print('Status: {}'.format(status)) yield from mpd_client.close()
def start(): mpd_client = yield from ampdclient.connect('192.168.1.12', 6600) mpd_client.cb_onchange = onchange print('Pausing') yield from mpd_client.pause(ampdclient.PAUSE_ON) resp = yield from mpd_client.status() print('Response {}'.format(resp)) yield from asyncio.sleep(2) print('Resume playing') yield from mpd_client.pause(ampdclient.PAUSE_OFF) resp = yield from mpd_client.status() print('Response {}'.format(resp)) yield from asyncio.sleep(2) print('Stopping') yield from mpd_client.stop() resp = yield from mpd_client.status() print('Response {}'.format(resp)) yield from asyncio.sleep(2) print('Playing') yield from mpd_client.stop() resp = yield from mpd_client.play() print('Response {}'.format(resp)) yield from asyncio.sleep(2) # If you pass anything else than PAUSE_OFF / PAUSE_ON (i.e. 0 or 1) an # exception is raised. try: yield from mpd_client.pause(5) except ampdclient.MpdCommandException as e: print('Exception for wrong pause argument: {}'.format(e)) yield from mpd_client.close()
def start(host, path): mpd_client = yield from ampdclient.connect(host, 6600) mpd_client.cb_onchange = onchange print('lsinfo') dirs, files, playlists = yield from mpd_client.lsinfo(path) print('content:\n\tdirs: {} \n\tfiles: {} \n\tplaylists: {}' .format(dirs, files, playlists)) # Add playlists in the play queue for p in playlists: try: yield from mpd_client.load(p[0]) print('loaded playlist {} '.format(p[0])) except ampdclient.MpdCommandException as e: # Make sure print('Could not load playlist {} \n\t {}'.format(p[0], e)) # Add files in the play queue for f in files: try: f_id = yield from mpd_client.addid(f[0]) print('loaded {} - id: {}'.format(f[0], f_id)) except ampdclient.MpdCommandException as e: print('Could not enqueue file {} \n\t {}'.format(f[0], e)) # Add (recursive) directories in the play queue for d in dirs: try: yield from mpd_client.add(d[0]) print('Dir added {} '.format(d[0])) except ampdclient.MpdCommandException as e: print('Could add directory {} \n\t {}'.format(d[0], e)) playqueue_content = yield from mpd_client.playlistid() print_pl(playqueue_content) # Removes first track in the play queue yield from mpd_client.delete_pos(0) playqueue_content = yield from mpd_client.playlistid() print_pl(playqueue_content) # Removes tracks with index 2, 3 and 4 in the play queue yield from mpd_client.delete_range(2, 5) playqueue_content = yield from mpd_client.playlistid() print_pl(playqueue_content) # Removes all tracks from index 5 to the end of the play queue yield from mpd_client.delete_range(5) playqueue_content = yield from mpd_client.playlistid() print_pl(playqueue_content) # Display info for the first track in the play queue track_id = playqueue_content[0][1]['Id'] print('Track id: {}'.format(track_id)) playqueue_content = yield from mpd_client.playlistid(track_id) print_pl(playqueue_content) # same thing, but with the playlistinfo command, which takes a position # instead of an id. track_info = yield from mpd_client.playlistinfo(0) print("Track info : {}".format(track_info)) # Remove the first track in the play queue, by id yield from mpd_client.deleteid(track_id) try: playqueue_content = yield from mpd_client.playlistid(track_id) except ampdclient.MpdCommandException as e: if e.command == 'playlistid': print("OK, track {} was removed from the play queue". format(track_id)) playqueue_content = yield from mpd_client.playlistid() print_pl(playqueue_content) print('Listing play queue with playlistinfo ') playqueue_content = yield from mpd_client.playlistinfo() for item in playqueue_content: print('item {} - {}'.format(item[1]['Id'], item[0])) print('Listing play queue with playlistinfo range 0 - 3') playqueue_content = yield from mpd_client.playlistinfo_range(0, 3) for item in playqueue_content: print('item {} - {}'.format(item[1]['Id'], item[0])) print('Listing play queue with playlistinfo range 3 -> end') playqueue_content = yield from mpd_client.playlistinfo_range(3) for item in playqueue_content: print('item {} - {}'.format(item[1]['Id'], item[0])) # Clear the play queue yield from mpd_client.clear() yield from mpd_client.close()