Exemple #1
0
SongIterator Connection::GetPlaylistContent(const std::string &path)
{
	prechecksNoCommandsList();
	mpd_send_list_playlist_meta(m_connection.get(), path.c_str());
	SongIterator result(m_connection.get(), defaultFetcher<Song>(mpd_recv_song));
	checkErrors();
	return result;
}
Exemple #2
0
/*
 * Retrieve the contents of a stored playlist. Will synchronize local playlists
 * with the MPD server, overwriting the local versions.
 *
 * Returns true on success, false on failure.
 */
bool
Control::update_playlist(Playlist * playlist)
{
	Song *			song;
	mpd_entity *		ent;
	const mpd_song *	ent_song;

	EXIT_IDLE;

	pms->log(MSG_DEBUG, 0, "Retrieving playlist %s from MPD server.\n", playlist->filename.c_str());

	if (!mpd_send_list_playlist_meta(conn->h(), playlist->filename.c_str())) {
		return false;
	}

	playlist->clear();

	while ((ent = mpd_recv_entity(conn->h())) != NULL)
	{
		switch(mpd_entity_get_type(ent))
		{
			case MPD_ENTITY_TYPE_SONG:
				ent_song = mpd_entity_get_song(ent);
				song = new Song(ent_song);
				song->id = MPD_SONG_NO_ID;
				song->pos = MPD_SONG_NO_NUM;
				playlist->add_local(song);
				break;
			case MPD_ENTITY_TYPE_UNKNOWN:
				pms->log(MSG_DEBUG, 0, "BUG in retrieve_lists(): entity type not implemented by libmpdclient\n");
				break;
			default:
				pms->log(MSG_DEBUG, 0, "BUG in retrieve_lists(): entity type not implemented by PMS\n");
				break;
		}
		mpd_entity_free(ent);
	}

	playlist->set_column_size();

	return get_error_bool();
}
Exemple #3
0
/*
 * pgmpc_playlist
 * List all songs in given playlist. If not playlist is specified list
 * songs of current playlist.
 */
Datum
pgmpc_playlist(PG_FUNCTION_ARGS)
{
	TupleDesc   tupdesc;
	Tuplestorestate *tupstore;
	char *playlist = NULL;
	bool ret;

	if (PG_NARGS() == 1 && !PG_ARGISNULL(0))
		playlist = text_to_cstring(PG_GETARG_TEXT_PP(0));

	/* Initialize function context */
	pgmpc_init_setof_single(fcinfo, TEXTOID, "playlist", &tupdesc, &tupstore);

	/*
	 * Run the command to get all the songs.
	 */
	pgmpc_init();
	ret = playlist ?
		mpd_send_list_playlist_meta(mpd_conn, playlist) :
		mpd_send_list_queue_meta(mpd_conn);
	if (!ret)
		pgmpc_print_error();

	/* Now get all the songs and send them back to caller */
	while (true)
	{
		Datum       values[1];
		bool		nulls[1];
		struct mpd_song *song = mpd_recv_song(mpd_conn);

		/* Leave if done */
		if (song == NULL)
			break;

		/* Assign song name */
		nulls[0] = false;
		values[0] = CStringGetTextDatum(mpd_song_get_uri(song));

		/* Save values */
		tuplestore_putvalues(tupstore, tupdesc, values, nulls);

		/* Clean up for the next one */
		mpd_song_free(song);
	}

	/* We may be in error state, so check for it */
	if (mpd_connection_get_error(mpd_conn) != MPD_ERROR_SUCCESS)
	{
		const char *message = mpd_connection_get_error_message(mpd_conn);
		pgmpc_reset();
		ereport(ERROR,
				(errcode(ERRCODE_SYSTEM_ERROR),
				 errmsg("mpd command failed: %s",
						message)));
	}

	/* Clean up */
	pgmpc_reset();

	/* clean up and return the tuplestore */
	tuplestore_donestoring(tupstore);

	return (Datum) 0;
}