コード例 #1
0
ファイル: command.cpp プロジェクト: reynhout/pms
/*
 * Retrieves the currently playing song from MPD, and caches it locally.
 *
 * Returns true on success, false on failure.
 */
bool
Control::get_current_song()
{
	bool status_ok;
	struct mpd_song * song;

	EXIT_IDLE;

	song = mpd_run_current_song(conn->h());
	status_ok = get_error_bool();

	if (!status_ok) {
		return status_ok;
	}

	if (_song != NULL) {
		delete _song;
		_song = NULL;
	}

	if (song) {
		_song = new Song(song);
		mpd_song_free(song);
	}

	return get_error_bool();
}
コード例 #2
0
ファイル: song.c プロジェクト: Fyzick/capstone
struct mpd_song *
mpd_recv_song(struct mpd_connection *connection)
{
	struct mpd_pair *pair;
	struct mpd_song *song;

	pair = mpd_recv_pair_named(connection, "file");
	if (pair == NULL)
		return NULL;

	song = mpd_song_begin(pair);
	mpd_return_pair(connection, pair);
	if (song == NULL) {
		mpd_error_entity(&connection->error);
		return NULL;
	}

	while ((pair = mpd_recv_pair(connection)) != NULL &&
	       mpd_song_feed(song, pair))
		mpd_return_pair(connection, pair);

	if (mpd_error_is_defined(&connection->error)) {
		mpd_song_free(song);
		return NULL;
	}

	/* unread this pair for the next mpd_recv_song() call */
	mpd_enqueue_pair(connection, pair);

	return song;
}
コード例 #3
0
ファイル: mpdinfo.c プロジェクト: jepugs/mpdinfo
int main(int argc, const char* const argv[])
{
    if (argc > 2 || (argc == 2 && strncmp(argv[1], "-h", 2) == 0)) {
        usage();
        return 0;
    }

    conn = mpd_connection_new(NULL, 0, 0);
    if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {
        mpd_connection_free(conn);
        fputs("Could not connect to MPD.\n", stderr);
        return 0;
    }
    stat = mpd_run_status(conn);
    if (!(song = mpd_run_current_song(conn))) {
        fputs("No song playing.\n", stderr);
        return 0;
    }

    if (argc == 1)
        print_info(DEFAULT_FMT);
    else
        print_info(argv[1]);

    if (song)
        mpd_song_free(song);
    mpd_status_free(stat);
    mpd_connection_free(conn);

    return 0;
}
コード例 #4
0
ファイル: command.c プロジェクト: somecommand/mpc
int cmd_tab ( int argc, char ** argv, struct mpd_connection *conn )
{
	struct mpd_song *song;
	char empty[] = "";
	char *dir = empty;
	char *tmp = NULL;

	if (argc == 1) {
		if (strrchr(argv[0], '/')) {
			dir = strdup(argv[0]);
			if (!dir) return 0;
			tmp = strrchr(dir, '/');
			if (tmp) *tmp = '\0'; // XXX: It's unpossible for tmp to be NULL.
		}
	}

	if (!mpd_send_list_all(conn, dir))
		printErrorAndExit(conn);

	if (*dir) free(dir);

	while ((song = mpd_recv_song(conn)) != NULL) {
		if (argc != 1 ||
		    strncmp(mpd_song_get_uri(song), argv[0],
			    strlen(argv[0])) == 0)
			printf("%s\n",
			       charset_from_utf8(mpd_song_get_uri(song)));

		mpd_song_free(song);
	}

	my_finishCommand(conn);
	return 0;
}
コード例 #5
0
ファイル: songs.c プロジェクト: viibridges/mpc_d
void
songlist_update(void)
{
  struct mpd_song *song;
  
  if (!mpd_send_list_queue_meta(conn))
	printErrorAndExit(conn);

  int i = 0;
  while ((song = mpd_recv_song(conn)) != NULL
		 && i < MAX_SONGLIST_STORE_LENGTH)
	{
	  pretty_copy(songlist->meta[i].title,
					get_song_tag(song, MPD_TAG_TITLE),
					512, -1);
	  pretty_copy(songlist->meta[i].pretty_title,
					get_song_tag(song, MPD_TAG_TITLE),
					128, 26);
	  pretty_copy(songlist->meta[i].artist,
					get_song_tag(song, MPD_TAG_ARTIST),
					128, 14);	  
	  pretty_copy(songlist->meta[i].album,
					get_song_tag(song, MPD_TAG_ALBUM),
					128, -1);
	  songlist->meta[i].id = i + 1;
	  ++i;
	  mpd_song_free(song);
	}

  songlist->length = i;

  my_finishCommand(conn);
}
コード例 #6
0
ファイル: mpd.c プロジェクト: cmende/mpd2irc
static void mpd_update(void)
{
	enum mpd_state prev = MPD_STATE_UNKNOWN;

	if (mpd.status) {
		prev = mpd_status_get_state(mpd.status);
		mpd_status_free(mpd.status);
	}

	mpd.status = mpd_run_status(mpd.conn);
	if (!mpd_response_finish(mpd.conn)) {
		mpd_report_error();
		return;
	}

	if (mpd_status_get_state(mpd.status) == MPD_STATE_PLAY &&
			prev != MPD_STATE_PAUSE) {
		if (mpd.song)
			mpd_song_free(mpd.song);
		mpd.song = mpd_run_current_song(mpd.conn);
		if (!mpd_response_finish(mpd.conn)) {
			mpd_report_error();
			return;
		}

		if (prefs.announce)
			mpd_announce_song();
	}
}
コード例 #7
0
ファイル: mpd_client.c プロジェクト: rain0r/ympd
int mpd_put_current_song(char *buffer)
{
    char *cur = buffer;
    const char *end = buffer + MAX_SIZE;
    struct mpd_song *song;

    song = mpd_run_current_song(mpd.conn);
    if(song == NULL)
        return 0;

    cur += json_emit_raw_str(cur, end - cur, "{\"type\": \"song_change\", \"data\":{\"pos\":");
    cur += json_emit_int(cur, end - cur, mpd_song_get_pos(song));
    cur += json_emit_raw_str(cur, end - cur, ",\"title\":");
    cur += json_emit_quoted_str(cur, end - cur, mpd_get_title(song));

    if(mpd_song_get_tag(song, MPD_TAG_ARTIST, 0) != NULL)
    {
        cur += json_emit_raw_str(cur, end - cur, ",\"artist\":");
        cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_tag(song, MPD_TAG_ARTIST, 0));
    }

    if(mpd_song_get_tag(song, MPD_TAG_ALBUM, 0) != NULL)
    {
        cur += json_emit_raw_str(cur, end - cur, ",\"album\":");
        cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_tag(song, MPD_TAG_ALBUM, 0));
    }

    cur += json_emit_raw_str(cur, end - cur, "}}");
    mpd_song_free(song);
    mpd_response_finish(mpd.conn);

    return cur - buffer;
}
コード例 #8
0
ファイル: mpd.cpp プロジェクト: kpence/kpmpc
std::string Mpd::getTag(const char *_album, mpd_tag_type type) {
    std::string tagRet = "";
    mpd_song *song;
    if (!mpd_search_db_songs(conn, false)) { err(); return NULL; }

    if (!mpd_search_add_tag_constraint(conn, MPD_OPERATOR_DEFAULT, MPD_TAG_ALBUM, _album)) { err(); return NULL; }

    if (!mpd_search_commit(conn)) { err(); return NULL; }

    if (type == MPD_TAG_UNKNOWN) {
        if ((song = mpd_recv_song(conn)) != NULL) {
            if (mpd_song_get_uri(song) != NULL)
                tagRet = mpd_song_get_uri(song);
            else
                tagRet = "";
        }
    } else if ((song = mpd_recv_song(conn)) != NULL) {
        if (mpd_song_get_tag(song, type, 0) != NULL)
            tagRet = mpd_song_get_tag(song, type, 0);
        else
            tagRet = "";
    }

    mpd_song_free(song);

    if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { err(); return NULL; }

    if (!mpd_response_finish(conn)) { err(); return NULL; }

    return tagRet;
}
コード例 #9
0
ファイル: eugene-rmtag.c プロジェクト: kaivalagi/mpdcron
static int
rmtag_song(struct mpdcron_connection *conn, const char *tag, const char *expr)
{
	int changes;

	if (expr != NULL) {
		if (!mpdcron_rmtag_expr(conn, expr, tag, &changes)) {
			eulog(LOG_ERR, "Failed to remove tag from song: %s",
					conn->error->message);
			return 1;
		}
	}
	else {
		char *esc_uri, *myexpr;
		struct mpd_song *song;

		if ((song = load_current_song()) == NULL)
			return 1;

		esc_uri = quote(mpd_song_get_uri(song));
		myexpr = g_strdup_printf("uri=%s", esc_uri);
		g_free(esc_uri);
		mpd_song_free(song);

		if (!mpdcron_rmtag_expr(conn, myexpr, tag, &changes)) {
			eulog(LOG_ERR, "Failed to remove tag from current playing song: %s",
					conn->error->message);
			g_free(myexpr);
			return 1;
		}
		g_free(myexpr);
	}
	printf("Modified %d entries\n", changes);
	return 0;
}
コード例 #10
0
ファイル: eugene-rmtag.c プロジェクト: kaivalagi/mpdcron
static int
rmtag_album(struct mpdcron_connection *conn, const char *tag, const char *expr)
{
	int changes;

	if (expr != NULL) {
		if (!mpdcron_rmtag_album_expr(conn, expr, tag, &changes)) {
			eulog(LOG_ERR, "Failed to remove tag from album: %s",
					conn->error->message);
			return 1;
		}
	}
	else {
		char *esc_album, *esc_artist, *myexpr;
		struct mpd_song *song;

		if ((song = load_current_song()) == NULL)
			return 1;
		else if (mpd_song_get_tag(song, MPD_TAG_ARTIST, 0) == NULL) {
			eulog(LOG_ERR, "Current playing song has no artist tag!");
			mpd_song_free(song);
			return 1;
		}
		else if (mpd_song_get_tag(song, MPD_TAG_ALBUM, 0) == NULL) {
			eulog(LOG_ERR, "Current playing song has no album tag!");
			mpd_song_free(song);
			return 1;
		}

		esc_album = quote(mpd_song_get_tag(song, MPD_TAG_ALBUM, 0));
		esc_artist = quote(mpd_song_get_tag(song, MPD_TAG_ARTIST, 0));
		myexpr = g_strdup_printf("name=%s and artist=%s", esc_album, esc_artist);
		g_free(esc_album);
		g_free(esc_artist);
		mpd_song_free(song);

		if (!mpdcron_rmtag_album_expr(conn, myexpr, tag, &changes)) {
			eulog(LOG_ERR, "Failed to remove tag from current playing album: %s",
					conn->error->message);
			g_free(myexpr);
			return 1;
		}
		g_free(myexpr);
	}
	printf("Modified %d entries\n", changes);
	return 0;
}
コード例 #11
0
ファイル: lmc.c プロジェクト: L0op/RuneAudioNext
static enum mpd_state
lmc_current(struct mpd_song **song_r, unsigned *elapsed_r)
{
	struct mpd_status *status;
	enum mpd_state state;
	struct mpd_song *song;

	assert(g_mpd != NULL);

	mpd_command_list_begin(g_mpd, true);
	mpd_send_status(g_mpd);
	mpd_send_current_song(g_mpd);
	mpd_command_list_end(g_mpd);

	status = mpd_recv_status(g_mpd);
	if (!status) {
		lmc_failure();
		return MPD_STATE_UNKNOWN;
	}

	state = mpd_status_get_state(status);
	*elapsed_r = mpd_status_get_elapsed_time(status);

	mpd_status_free(status);

	if (state != MPD_STATE_PLAY) {
		if (!mpd_response_finish(g_mpd)) {
			lmc_failure();
			return MPD_STATE_UNKNOWN;
		}

		return state;
	}

	if (!mpd_response_next(g_mpd)) {
		lmc_failure();
		return MPD_STATE_UNKNOWN;
	}

	song = mpd_recv_song(g_mpd);
	if (song == NULL) {
		if (!mpd_response_finish(g_mpd)) {
			lmc_failure();
			return MPD_STATE_UNKNOWN;
		}

		return MPD_STATE_UNKNOWN;
	}

	if (!mpd_response_finish(g_mpd)) {
		mpd_song_free(song);
		lmc_failure();
		return MPD_STATE_UNKNOWN;
	}

	*song_r = song;
	return MPD_STATE_PLAY;
}
コード例 #12
0
ファイル: dwmstatus.c プロジェクト: iambetmen/dotfiles
char *
getmpdstat() {
    struct mpd_song * song = NULL;
	const char * title = NULL;
	const char * artist = NULL;
	const char * uri = NULL;
	const char * titletag = NULL;
	const char * artisttag = NULL;
	char * retstr = NULL;
	int elapsed = 0, total = 0;
    struct mpd_connection * conn ;
    if (!(conn = mpd_connection_new("localhost", 0, 30000)) ||
        mpd_connection_get_error(conn)){
            return smprintf("");
    }

    mpd_command_list_begin(conn, true);
    mpd_send_status(conn);
    mpd_send_current_song(conn);
    mpd_command_list_end(conn);

    struct mpd_status* theStatus = mpd_recv_status(conn);
        if ((theStatus) && (mpd_status_get_state(theStatus) == MPD_STATE_PLAY)) {
                mpd_response_next(conn);
                song = mpd_recv_song(conn);
		titletag = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
		artisttag = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
                title = smprintf("%s",titletag);
                artist = smprintf("%s",artisttag);
		uri = smprintf("%s",mpd_song_get_uri(song));

                elapsed = mpd_status_get_elapsed_time(theStatus);
                total = mpd_status_get_total_time(theStatus);
                mpd_song_free(song);

		/* If the song isn't tagged, then just use the filename */
		if(artisttag == NULL && titletag == NULL) {
			retstr = smprintf("%s[%s%s%s | %s%.2d:%.2d%s/%.2d:%.2d%s]",
					colcyan, colyellow, uri, colcyan,
					colbyellow, elapsed/60, elapsed%60,
					colyellow, total/60,   total%60, colcyan);
		} else {
			retstr = smprintf("%s[%s%s%s | %s%s%s | %s%.2d:%.2d%s/%.2d:%.2d%s]",
					colcyan, colyellow, artist, colcyan, colred, title, colcyan,
					colbyellow, elapsed/60, elapsed%60,
					colyellow, total/60,   total%60, colcyan);
		}
                free((char*)title);
                free((char*)artist);
		free((char*)uri);
        }
        else retstr = smprintf("");
		mpd_response_finish(conn);
		mpd_connection_free(conn);
		return retstr;
}
コード例 #13
0
ファイル: stats-module.c プロジェクト: hariskar/mpdcron
static void
destroy(void)
{
	g_message("Exiting");
	if (prev != NULL)
		mpd_song_free(prev);
	g_timer_destroy(timer);
	server_close();
	db_close();
	file_cleanup();
}
コード例 #14
0
ファイル: plugin_mpd.c プロジェクト: KCFTech/lcd4linux
void plugin_exit_mpd(void)
{
    if (plugin_enabled == 1) {
	debug("[MPD] disconnect from mpd");
	if (currentSong != NULL)
	    mpd_song_free(currentSong);
    }
    if (conn != NULL)
	mpd_connection_free(conn);
    charset_close();
}
コード例 #15
0
ファイル: client.c プロジェクト: cykerway/ncmpcr
int del_client(CLIENT_OBJECT *cli) {

    mpd_stats_free(cli->stats);
    if (cli->song)
        mpd_song_free(cli->song);
    mpd_status_free(cli->status);
    mpd_connection_free(cli->conn);

    free(cli);
    return 0;
}
コード例 #16
0
ファイル: eugene-love.c プロジェクト: alip/mpdcron
static int
love_album(struct mpdcron_connection *conn, bool love, const char *expr)
{
	int changes;
	char *esc_album, *myexpr;
	struct mpd_song *song;

	if (expr != NULL) {
		if (!mpdcron_love_album_expr(conn, love, expr, &changes)) {
			eulog(LOG_ERR, "Failed to %s album: %s",
					love ? "love" : "hate",
					conn->error->message);
			return 1;
		}
	}
	else {
		if ((song = load_current_song()) == NULL)
			return 1;
		else if (mpd_song_get_tag(song, MPD_TAG_ALBUM, 0) == NULL) {
			eulog(LOG_ERR, "Current playing song has no album tag!");
			mpd_song_free(song);
			return 1;
		}

		esc_album = quote(mpd_song_get_tag(song, MPD_TAG_ALBUM, 0));
		myexpr = g_strdup_printf("name=%s", esc_album);
		g_free(esc_album);
		mpd_song_free(song);

		if (!mpdcron_love_album_expr(conn, love, myexpr, &changes)) {
			eulog(LOG_ERR, "Failed to %s current playing album: %s",
					love ? "love" : "hate",
					conn->error->message);
			g_free(myexpr);
			return 1;
		}
		g_free(myexpr);
	}
	printf("Modified %d entries\n", changes);
	return 0;
}
コード例 #17
0
ファイル: dwmst.c プロジェクト: Theta91/dwmst
char *
get_mpd(void) {
	struct mpd_connection *con;
	struct mpd_status *status;
	struct mpd_song *song;
	int status_type;
	char *res;
	const char *artist = NULL, *title = NULL;

	con = mpd_connection_new(NULL, 0, 30000);
	if(mpd_connection_get_error(con)) {
		mpd_connection_free(con);
		return NO_MPD;
	}

	mpd_command_list_begin(con, true);
	mpd_send_status(con);
	mpd_send_current_song(con);
	mpd_command_list_end(con);

	status = mpd_recv_status(con);
	if(!status) {
		mpd_connection_free(con);
		return NO_MPD;
	}
	mpd_response_next(con);
	song = mpd_recv_song(con);
	title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
	if(!title)
		title = mpd_song_get_uri(song);
	artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);

	status_type = mpd_status_get_state(status);
	switch(status_type) {
		case(MPD_STATE_PLAY):
			res = smprintf(MPD, "Playing", artist, title);
			break;
		case(MPD_STATE_PAUSE):
			res = smprintf(MPD, "Paused", artist, title);
			break;
		case(MPD_STATE_STOP):
			res = smprintf(MPD, "Stopped", artist, title);
			break;
		default:
			res = NO_MPD;
			break;
	}
	mpd_song_free(song);
	mpd_response_finish(con);
	mpd_status_free(status);
	mpd_connection_free(con);
	return res;
}
コード例 #18
0
ファイル: mpdnotify.c プロジェクト: at0m5k/mpdnotify
int main() {
	char fullpath[100], text[100];
	char *buf = NULL, *sub = NULL, *state = NULL;
	
	conn = mpd_connection_new(NULL, 0, 10000);
	notify = notify_notification_new(NULL, NULL, NULL);
	notify_init("mpdnotify");

	while(mpd_run_idle_mask(conn, MPD_IDLE_PLAYER)) {
		mpd_command_list_begin(conn, true);
		mpd_send_status(conn);
		mpd_send_current_song(conn);
		mpd_command_list_end(conn);

		status = mpd_recv_status(conn);
		if(mpd_status_get_state(status) == MPD_STATE_PLAY)
			state = "Playing:";
		else if(mpd_status_get_state(status) == MPD_STATE_PAUSE)
			state = "Paused:";
		else
			state = "Stopped:";
		mpd_response_next(conn);
		song = mpd_recv_song(conn);

		if(song) {
			artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
			title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
			path = mpd_song_get_uri(song);

			sprintf(text, "%s - %s", artist, title);

			buf = fullpath;
			sub = strrchr(path, '/');
			buf = strcpy(buf, mpdroot);
			buf = strncat(buf, path, strlen(path) - strlen(sub) + 1);
			buf = strcat(buf, albumart);
			icon = gdk_pixbuf_new_from_file(fullpath, NULL);

			if(icon)
				notify_notification_update(notify, state, text, NULL);
			else
				notify_notification_update(notify, state, text, "sound");
			notify_notification_set_icon_from_pixbuf(notify, icon);
			notify_notification_show(notify, &gerror);

			mpd_song_free(song);
		}
		mpd_response_finish(conn);
	}
	mpd_connection_free(conn);
	notify_uninit();
	return 0;
}
コード例 #19
0
ファイル: eugene-count.c プロジェクト: alip/mpdcron
static int
count_artist(struct mpdcron_connection *conn, const char *expr,
		const char *count)
{
	int changes;
	char *esc_artist, *myexpr;
	struct mpd_song *song;

	if (expr != NULL) {
		if (!mpdcron_count_artist_expr(conn, expr, count, &changes)) {
			eulog(LOG_ERR, "Failed to change play count of artist: %s",
					conn->error->message);
			return 1;
		}
	}
	else {
		if ((song = load_current_song()) == NULL)
			return 1;
		else if (mpd_song_get_tag(song, MPD_TAG_ARTIST, 0) == NULL) {
			eulog(LOG_ERR, "Current playing song has no artist tag!");
			mpd_song_free(song);
			return 1;
		}

		esc_artist = quote(mpd_song_get_tag(song, MPD_TAG_ARTIST, 0));
		myexpr = g_strdup_printf("name=%s", esc_artist);
		g_free(esc_artist);
		mpd_song_free(song);

		if (!mpdcron_count_artist_expr(conn, myexpr, count, &changes)) {
			eulog(LOG_ERR, "Failed to change play count of current playing artist: %s",
					conn->error->message);
			g_free(myexpr);
			return 1;
		}
		g_free(myexpr);
	}
	printf("Modified %d entries\n", changes);
	return 0;
}
コード例 #20
0
ファイル: eugene-rmtag.c プロジェクト: kaivalagi/mpdcron
static int
rmtag_genre(struct mpdcron_connection *conn, const char *tag, const char *expr)
{
	int changes;

	if (expr != NULL) {
		if (!mpdcron_rmtag_genre_expr(conn, expr, tag, &changes)) {
			eulog(LOG_ERR, "Failed to remove tag from genre: %s",
					conn->error->message);
			return 1;
		}
	}
	else {
		char *esc_genre, *myexpr;
		struct mpd_song *song;

		if ((song = load_current_song()) == NULL)
			return 1;
		else if (mpd_song_get_tag(song, MPD_TAG_GENRE, 0) == NULL) {
			eulog(LOG_ERR, "Current playing song has no genre tag!");
			mpd_song_free(song);
			return 1;
		}

		esc_genre = quote(mpd_song_get_tag(song, MPD_TAG_GENRE, 0));
		myexpr = g_strdup_printf("name=%s", esc_genre);
		g_free(esc_genre);
		mpd_song_free(song);

		if (!mpdcron_rmtag_genre_expr(conn, myexpr, tag, &changes)) {
			eulog(LOG_ERR, "Failed to remove tag from current playing genre: %s",
					conn->error->message);
			g_free(myexpr);
			return 1;
		}
		g_free(myexpr);
	}
	printf("Modified %d entries\n", changes);
	return 0;
}
コード例 #21
0
ファイル: scrobbler-module.c プロジェクト: sdelafond/mpdcron
static void
destroy(void)
{
	g_message("Exiting");
	as_save_cache();
	as_cleanup();
	http_client_finish();
	file_cleanup();
	g_timer_destroy(timer);
	g_source_remove(save_source_id);
	if (prev != NULL)
		mpd_song_free(prev);
}
コード例 #22
0
ファイル: stats-module.c プロジェクト: hariskar/mpdcron
static int
event_player(G_GNUC_UNUSED const struct mpd_connection *conn,
		const struct mpd_song *song, const struct mpd_status *status)
{
	enum mpd_state state;

	g_assert(status != NULL);

	state = mpd_status_get_state(status);

	if (state == MPD_STATE_PAUSE) {
		song_paused();
		return MPDCRON_EVENT_SUCCESS;
	}
	else if (state != MPD_STATE_PLAY)
		song_stopped();

	if (was_paused) {
		if (song != NULL && mpd_song_get_id(song) == last_id)
			song_continued();
		was_paused = false;
	}

	/* Submit the previous song */
	if (prev != NULL && (song == NULL || mpd_song_get_id(prev) != mpd_song_get_id(song)))
		song_ended(prev);

	if (song != NULL) {
		if (mpd_song_get_id(song) != last_id) {
			/* New song. */
			song_started(song);
			last_id = mpd_song_get_id(song);
		}
		else {
			/* still playing the previous song */
			song_playing(song, mpd_status_get_elapsed_time(status));
		}
	}

	if (prev != NULL) {
		mpd_song_free(prev);
		prev = NULL;
	}
	if (song != NULL) {
		if ((prev = mpd_song_dup(song)) == NULL) {
			g_critical("mpd_song_dup failed: out of memory");
			return MPDCRON_EVENT_UNLOAD;
		}
	}
	return MPDCRON_EVENT_SUCCESS;
}
コード例 #23
0
ファイル: mpd_utils.c プロジェクト: rborisov/streamripperd
int get_current_song_rating()
{
    int rating;
    struct mpd_song *song;

    song = mpd_run_current_song(mpd.conn);
    if(song == NULL)
        return 0;

    rating = db_get_song_rating(mpd_get_title(song), mpd_get_artist(song));

    mpd_song_free(song);
    return rating;
}
コード例 #24
0
ファイル: client.c プロジェクト: cykerway/ncmpcr
int update_client(CLIENT_OBJECT *cli) {

    mpd_status_free(cli->status);
    cli->status = mpd_run_status(cli->conn);

    if (cli->song)
        mpd_song_free(cli->song);
    cli->song = mpd_run_current_song(cli->conn);

    mpd_stats_free(cli->stats);
    cli->stats = mpd_run_stats(cli->conn);

    return 0;
}
コード例 #25
0
ファイル: search.c プロジェクト: cykerway/ncmpcr
static int fetch_items(MENU_SEARCH *menu,char *str,CLIENT_OBJECT *cli,DB_OBJECT *db)
{
    if (!(str && strlen(str)))
        return 1;

    /* send query */
    if (!mpd_search_db_songs(cli->conn,false))
        clear_or_exit_on_error(cli->conn);
    if (!mpd_search_add_tag_constraint(cli->conn,MPD_OPERATOR_DEFAULT,MPD_TAG_TITLE,str))
        clear_or_exit_on_error(cli->conn);
    if (!mpd_search_commit(cli->conn))
        clear_or_exit_on_error(cli->conn);

    /* process response */
    int block = 1024;
    menu->items = (MENU_SEARCH_ITEM*)calloc(block,sizeof(MENU_SEARCH_ITEM));

    struct mpd_song *song;
    int i = 0;
	while ((song = mpd_recv_song(cli->conn))) {

        /* realloc if memory not enough */
        if (i >= block) {
            block *= 2;
            menu->items = (MENU_SEARCH_ITEM*)realloc(menu->items,block*sizeof(MENU_SEARCH_ITEM));
        }

        unsigned id = mpd_song_get_id(song);
        const char *uri = mpd_song_get_uri(song);
        const char *title = mpd_song_get_tag(song,MPD_TAG_TITLE,0);

        menu->items[i].id = id;
        menu->items[i].title = (char *)malloc((strlen(title)+1)*sizeof(char));
        strcpy(menu->items[i].title,title);
        menu->items[i++].node = get_node_by_uri(db,uri);

		mpd_song_free(song);

	}

    if (mpd_connection_get_error(cli->conn) == MPD_ERROR_SUCCESS)
        mpd_response_finish(cli->conn);
    else
        clear_or_exit_on_error(cli->conn);

    menu->num = i;

    return 0;
}
コード例 #26
0
ファイル: mpd_utils.c プロジェクト: rborisov/streamripperd
char* mpd_get_current_artist()
{   
    struct mpd_song *song;

    if (mpd.conn_state == MPD_CONNECTED) {
        song = mpd_run_current_song(mpd.conn);
        if(song == NULL) {
            printf("song == NULL\n");
            return NULL;
        }
        sprintf(artistbuf, "%s", mpd_get_artist(song));
        mpd_song_free(song);
    }

    return artistbuf;
}
コード例 #27
0
ファイル: mpd_client.c プロジェクト: kvbx/ympd
int mpd_search(char *buffer, char *searchstr)
{
    int i = 0;
    char *cur = buffer;
    const char *end = buffer + MAX_SIZE;
    struct mpd_song *song;

    if(mpd_search_db_songs(mpd.conn, false) == false)
        RETURN_ERROR_AND_RECOVER("mpd_search_db_songs");
    else if(mpd_search_add_any_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, searchstr) == false)
        RETURN_ERROR_AND_RECOVER("mpd_search_add_any_tag_constraint");
    else if(mpd_search_commit(mpd.conn) == false)
        RETURN_ERROR_AND_RECOVER("mpd_search_commit");
    else {
        cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"search\",\"data\":[ ");

        while((song = mpd_recv_song(mpd.conn)) != NULL) {
            cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\",\"uri\":");
            cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(song));
            cur += json_emit_raw_str(cur, end - cur, ",\"album\":");
            cur += json_emit_quoted_str(cur, end - cur, mpd_get_album(song));
            cur += json_emit_raw_str(cur, end - cur, ",\"artist\":");
            cur += json_emit_quoted_str(cur, end - cur, mpd_get_artist(song));
            cur += json_emit_raw_str(cur, end - cur, ",\"duration\":");
            cur += json_emit_int(cur, end - cur, mpd_song_get_duration(song));
            cur += json_emit_raw_str(cur, end - cur, ",\"title\":");
            cur += json_emit_quoted_str(cur, end - cur, mpd_get_title(song));
            cur += json_emit_raw_str(cur, end - cur, "},");
            mpd_song_free(song);

            /* Maximum results */
            if(i++ >= 300)
            {
                cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"wrap\"},");
                break;
            }
        }

        /* remove last ',' */
        cur--;

        cur += json_emit_raw_str(cur, end - cur, "]}");
    }
    return cur - buffer;
}
コード例 #28
0
ファイル: mpd_utils.c プロジェクト: rborisov/ca-st-ro
char* mpd_get_current_album()
{
    struct mpd_song *song;

    if (mpd.conn_state == MPD_CONNECTED) {
        song = mpd_run_current_song(mpd.conn);
        if(song == NULL) {
            printf("song == NULL\n");
            return NULL;
        }
        sprintf(albumbuf, "%s", mpd_get_album(song));
        mpd_song_free(song);
    }

    mpd_response_finish(mpd.conn);

    return albumbuf;
}
コード例 #29
0
ファイル: queue.c プロジェクト: Fyzick/capstone
struct mpd_song *
mpd_run_get_queue_song_id(struct mpd_connection *connection, unsigned id)
{
	struct mpd_song *song;

	if (!mpd_run_check(connection) ||
	    !mpd_send_get_queue_song_id(connection, id))
		return NULL;

	song = mpd_recv_song(connection);
	if (!mpd_response_finish(connection) && song != NULL) {
		mpd_song_free(song);
		return NULL;
	}

	return song;

}
コード例 #30
0
ファイル: command.c プロジェクト: somecommand/mpc
int
cmd_playlist(mpd_unused int argc, mpd_unused char **argv, struct mpd_connection *conn)
{
	struct mpd_song *song;

	if (!mpd_send_list_queue_meta(conn))
		printErrorAndExit(conn);

	while ((song = mpd_recv_song(conn)) != NULL) {
		pretty_print_song(song);
		mpd_song_free(song);
		printf("\n");
	}

	my_finishCommand(conn);

	return 0;
}