Ejemplo n.º 1
0
std::string Playback::getCurrentSongInfo(Playback::song_property property)
{
	printf("in Playback::getCurrentSongInfo\n");
	int error = mpd_connection_get_error(Connection::getConnection());
	printf("Error: %d\n", error);
	this->currentSong = mpd_run_current_song(Connection::getConnection());
	error = mpd_connection_get_error(Connection::getConnection());
	printf("Error: %d\n", error);

	std::string retVal;

	if (this->currentSong == nullptr)
		retVal = "ERROR";

	else
	{
		switch (property)
		{
		case Playback::ALBUM: retVal = mpd_song_get_tag(this->currentSong, MPD_TAG_ALBUM, 0); printf("%s\n", retVal.c_str()); break;
		case Playback::ARTIST: retVal = mpd_song_get_tag(this->currentSong, MPD_TAG_ARTIST, 0); printf("%s\n", retVal.c_str()); break;
		case Playback::TITLE: retVal = mpd_song_get_tag(this->currentSong, MPD_TAG_TITLE, 0); printf("%s\n", retVal.c_str()); break;
		case Playback::YEAR: retVal = mpd_song_get_tag(this->currentSong, MPD_TAG_DATE, 0); printf("%s\n", retVal.c_str()); break;
		case Playback::TRACKNR: retVal = mpd_song_get_tag(this->currentSong, MPD_TAG_TRACK, 0); printf("%s\n", retVal.c_str()); break;
		default: retVal = ""; printf("%s\n", retVal.c_str()); break;
		}
	}
	return retVal;
}
Ejemplo n.º 2
0
static void
song_ended(const struct mpd_song *song)
{
	bool long_enough;
	int elapsed, song_duration, percent_played;
	GError *error;

	g_assert(song != NULL);

	elapsed = g_timer_elapsed(timer, NULL);
	song_duration = mpd_song_get_duration(song);
	long_enough = played_long_enough(elapsed, song_duration);
	percent_played = elapsed * 100 / song_duration;

	g_debug("Saving old song (%s - %s), id: %u, pos: %u",
			mpd_song_get_tag(song, MPD_TAG_ARTIST, 0),
			mpd_song_get_tag(song, MPD_TAG_TITLE, 0),
			mpd_song_get_id(song), mpd_song_get_pos(song));

	error = NULL;
	if (!db_process(song, long_enough, percent_played, &error)) {
		g_warning("Saving old song failed: %s", error->message);
		g_error_free(error);
	}
	else if (error != NULL) {
		g_warning("Skipped saving old song: %s", error->message);
		g_error_free(error);
	}
}
Ejemplo n.º 3
0
Archivo: mpd.cpp Proyecto: 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;
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
Archivo: mpd.c Proyecto: cmende/mpd2irc
void mpd_announce_song(void)
{
	const gchar *artist, *song, *album;

	artist = mpd_song_get_tag(mpd.song, MPD_TAG_ARTIST, 0);
	song = mpd_song_get_tag(mpd.song, MPD_TAG_TITLE, 0);
	album = mpd_song_get_tag(mpd.song, MPD_TAG_ALBUM, 0);

	irc_say("Now playing: %s - %s (%s)", artist, song, album);
}
Ejemplo n.º 7
0
Archivo: mpd.c Proyecto: cmende/mpd2irc
void mpd_say_status(void)
{
	gchar *state;
	gchar *artist, *title;

	if (!mpd.conn) {
		irc_say("Not connected to MPD");
		return;
	}

	if (mpd.status)
		mpd_status_free(mpd.status);

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

	switch (mpd_status_get_state(mpd.status)) {
		case MPD_STATE_STOP:
			state = g_strdup("stopped"); break;
		case MPD_STATE_PLAY:
			state = g_strdup("playing"); break;
		case MPD_STATE_PAUSE:
			state = g_strdup("paused"); break;
		default:
			state = g_strdup("unknown"); break;
	}

	if (mpd.song) {
		artist = g_strdup(mpd_song_get_tag(mpd.song, MPD_TAG_ARTIST,
					0));
		title = g_strdup(mpd_song_get_tag(mpd.song, MPD_TAG_TITLE, 0));
	} else {
		artist = g_strdup("");
		title = g_strdup("");
	}

	irc_say("[%s] %s - %s (%i:%02i/%i:%02i) | repeat: %sabled | "
			"random: %sabled | announce: %sabled",
			state, artist, title,
			mpd_status_get_elapsed_time(mpd.status) / 60,
			mpd_status_get_elapsed_time(mpd.status) % 60,
			mpd_status_get_total_time(mpd.status) / 60,
			mpd_status_get_total_time(mpd.status) % 60,
			(mpd_status_get_repeat(mpd.status) ? "en" : "dis"),
			(mpd_status_get_random(mpd.status) ? "en" : "dis"),
			(prefs.announce ? "en" : "dis"));
	g_free(state);
	g_free(artist);
	g_free(title);
}
Ejemplo n.º 8
0
static void
song_changed(const struct mpd_song *song)
{
	g_assert(song != NULL);

	g_timer_start(timer);

	g_debug("New song detected (%s - %s), id: %u, pos: %u",
			mpd_song_get_tag(song, MPD_TAG_ARTIST, 0),
			mpd_song_get_tag(song, MPD_TAG_TITLE, 0),
			mpd_song_get_id(song), mpd_song_get_pos(song));
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
static void
song_changed(const struct mpd_song *song)
{
	g_assert(song != NULL);

	if (mpd_song_get_tag(song, MPD_TAG_ARTIST, 0) == NULL ||
			mpd_song_get_tag(song, MPD_TAG_TITLE, 0) == NULL) {
		g_message("New song detected with tags missing (%s)",
				mpd_song_get_uri(song));
		g_timer_start(timer);
		return;
	}
	g_timer_start(timer);

	g_debug("New song detected (%s - %s), id: %u, pos: %u",
			mpd_song_get_tag(song, MPD_TAG_ARTIST, 0),
			mpd_song_get_tag(song, MPD_TAG_TITLE, 0),
			mpd_song_get_id(song), mpd_song_get_pos(song));

	as_now_playing(mpd_song_get_tag(song, MPD_TAG_ARTIST, 0),
			mpd_song_get_tag(song, MPD_TAG_TITLE, 0),
			mpd_song_get_tag(song, MPD_TAG_ALBUM, 0),
			mpd_song_get_tag(song, MPD_TAG_MUSICBRAINZ_TRACKID, 0),
			mpd_song_get_duration(song));
}
Ejemplo n.º 12
0
void queue_add_current_song(void)
{
	const gchar *trackstr = mpd_song_get_tag(mpd.song, MPD_TAG_TRACK, 0);
	guint track = 0;

	if (trackstr)
		track = strtol(trackstr, NULL, 10);

	queue_add(mpd_song_get_tag(mpd.song, MPD_TAG_ARTIST, 0),
			mpd_song_get_tag(mpd.song, MPD_TAG_TITLE, 0),
			mpd_song_get_tag(mpd.song, MPD_TAG_ALBUM, 0),
			mpd_song_get_duration(mpd.song),
			track, mpd.song_date);
	mpd.song_state = SONG_SUBMITTED;
}
Ejemplo n.º 13
0
Song::Song(struct mpd_song *song)
{
    const char* temp;

    temp = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
    artist = temp ? temp : "";

    temp = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
    title = temp ? temp : "";

    temp = mpd_song_get_tag(song, MPD_TAG_ALBUM, 0);
    album = temp ? temp : "";

    duration = mpd_song_get_duration(song);
}
Ejemplo n.º 14
0
void print_info(const char fmt[])
{


    int t;
    for (int i = 0; i < strlen(fmt); ++i) {
        if (fmt[i] == '%') {
            switch(fmt[i+1]) {
            case 'n':
                if (song)
                    fputs(mpd_song_get_tag(song, MPD_TAG_TITLE, 0), stdout);
                break;
            case 'a':
                if (song)
                    fputs(mpd_song_get_tag(song, MPD_TAG_ARTIST, 0), stdout);
                break;
            case 'l':
                if (song)
                    fputs(mpd_song_get_tag(song, MPD_TAG_ALBUM, 0), stdout);
                break;
            case 'c':
                t = mpd_status_get_elapsed_time(stat);
                printf("%u:%02u", t / 60, t % 60);
                break;
            case 'r':
                t = mpd_status_get_total_time(stat) -
                    mpd_status_get_elapsed_time(stat);
                printf("%u:%02u", t / 60, t % 60);
                break;
            case 't':
                t = mpd_status_get_total_time(stat);
                printf("%u:%02u", t / 60, t % 60);
                break;
            case '%':
                putchar('%');
                break;
            default:
                putchar('%');
                putchar(fmt[i+1]);
                break;
            }
        ++i;
        } else {
            putchar(fmt[i]);
        }
    }
    putchar('\n');
}
Ejemplo n.º 15
0
/**
 * Checks if a mpd_song might be an FM4 stream
 *
 * @return true if it looks like an FM4 stream, false otherwise
 */
bool
fm4_is_fm4_stream(struct mpd_song *song)
{
	int rank = 0;
	const char *title = NULL;
	const char *uri = NULL;
	const char *title_prefix_fm4 = "FM4";

	if (song == NULL)
		return false;

	/* Information is contained in the title tag */
	title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
	uri = mpd_song_get_uri(song);

	if (title == NULL)
		return false;

	if (strcmp("http://mp3stream1.apasf.apa.at:8000/", uri) == 0)
		rank += 10;

	if (strncmp(title_prefix_fm4, title, sizeof(title_prefix_fm4)))
		rank += 5;

	if (rank >= FM4_THRESHOLD)
		return true;

	return false;
}
Ejemplo n.º 16
0
static char *
song_tag_locale(const struct mpd_song *song, enum mpd_tag_type tag)
{
	const char *value = mpd_song_get_tag(song, tag, 0);
	char *result;
#ifndef NCMPC_MINI
	char *all;
#endif /* !NCMPC_MINI */

	if (value == NULL)
		return NULL;

#ifndef NCMPC_MINI
	all = song_more_tag_values(song, tag, value);
	if (all != NULL)
		value = all;
#endif /* !NCMPC_MINI */

	result = utf8_to_locale(value);

#ifndef NCMPC_MINI
	g_free(all);
#endif /* !NCMPC_MINI */

	return result;
}
Ejemplo n.º 17
0
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;
}
Ejemplo n.º 18
0
std::string Song::get(mpd_tag_type type, unsigned idx) const
{
	std::string result;
	const char *tag = mpd_song_get_tag(m_song.get(), type, idx);
	if (tag)
		result = tag;
	return result;
}
Ejemplo n.º 19
0
/* if no tag is availabe, use filename */
static void getArtist(RESULT * result)
{
    const char *value = NULL;
    mpd_update();
    if (currentSong != NULL) {
	value = mpd_song_get_tag(currentSong, MPD_TAG_ARTIST, 0);
	if (!value) {
	    value = mpd_song_get_tag(currentSong, MPD_TAG_ALBUM_ARTIST, 0);
	}
	if (!value) {
	    value = mpd_song_get_uri(currentSong);
	}
    }
    if (value)
	SetResult(&result, R_STRING, charset_from_utf8(value));
    else
	SetResult(&result, R_STRING, "");
}
Ejemplo n.º 20
0
char* mpd_get_album(struct mpd_song const *song)
{
    char *str;
    str = (char *)mpd_song_get_tag(song, MPD_TAG_ALBUM, 0);
    if(str == NULL)
        str = nullstr; //TODO: get album from db

    return str;
}
Ejemplo n.º 21
0
static void
print_tag(const struct mpd_song *song, enum mpd_tag_type type,
	  const char *label)
{
	unsigned i = 0;
	const char *value;

	while ((value = mpd_song_get_tag(song, type, i++)) != NULL)
		printf("%s: %s\n", label, value);
}
Ejemplo n.º 22
0
char* mpd_get_title(struct mpd_song const *song)
{
    char *str;

    str = (char *)mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
    if(str == NULL){
        str = basename((char *)mpd_song_get_uri(song));
    }

    return str;
}
Ejemplo n.º 23
0
static char *
song_more_tag_values(const struct mpd_song *song, enum mpd_tag_type tag,
		     const char *first)
{
	const char *p = mpd_song_get_tag(song, tag, 1);
	char *buffer, *prev;

	if (p == NULL)
		return NULL;

	buffer = concat_tag_values(first, p);
	for (unsigned i = 2; (p = mpd_song_get_tag(song, tag, i)) != NULL;
	     ++i) {
		prev = buffer;
		buffer = concat_tag_values(buffer, p);
		g_free(prev);
	}

	return buffer;
}
Ejemplo n.º 24
0
char* mpd_get_year(struct mpd_song const *song)
{
    char *str;

    str = (char *)mpd_song_get_tag(song, MPD_TAG_DATE, 0);
    if(str == NULL){
        str = "-";
    }

    return str;
}
Ejemplo n.º 25
0
char* mpd_get_artist(struct mpd_song const *song)
{
    char *str;

    str = (char *)mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
    if(str == NULL){
        str = "-";
    }

    return str;
}
Ejemplo n.º 26
0
char* mpd_get_album(struct mpd_song const *song)
{
    char *str;

    str = (char *)mpd_song_get_tag(song, MPD_TAG_ALBUM, 0);
    if(str == NULL){
        str = "-";
    }

    return str;
}
Ejemplo n.º 27
0
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;
}
Ejemplo n.º 28
0
static void getTitle(RESULT * result)
{
    const char *value = NULL;
    mpd_update();
    if (currentSong != NULL) {
	value = mpd_song_get_tag(currentSong, MPD_TAG_TITLE, 0);
    }
    if (value)
	SetResult(&result, R_STRING, charset_from_utf8(value));
    else
	SetResult(&result, R_STRING, "");
}
Ejemplo n.º 29
0
char* mpd_get_artist(struct mpd_song const *song)
{
    char *str;
    str = (char *)mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
    if(str == NULL) {
        str = basename((char *)mpd_song_get_uri(song));
        if  (str == NULL)
            str = nullstr;
    }

    return str;
}
Ejemplo n.º 30
0
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;
}