Example #1
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);
	}
}
Example #2
0
static bool
song_repeated(const struct mpd_song *song, int elapsed, int prev_elapsed)
{
	return elapsed < 60 && prev_elapsed > elapsed &&
		played_long_enough(prev_elapsed - elapsed,
				mpd_song_get_duration(song));
}
Example #3
0
static void
song_ended(const struct mpd_song *song)
{
	int elapsed;

	g_assert(song != NULL);

	elapsed = g_timer_elapsed(timer, NULL);

	if (mpd_song_get_tag(song, MPD_TAG_ARTIST, 0) == NULL ||
			mpd_song_get_tag(song, MPD_TAG_TITLE, 0) == NULL) {
		g_message("Song (%s) has missing tags, skipping",
				mpd_song_get_uri(song));
		return;
	}
	else if (!played_long_enough(elapsed, mpd_song_get_duration(song))) {
		g_message("Song (%s - %s), id: %u, pos: %u not played long enough, skipping",
				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));
		return;
	}

	g_debug("Submitting 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));

	/* FIXME: libmpdclient doesn't have any way to fetch the musicbrainz id.
	 */
	as_songchange(mpd_song_get_uri(song),
			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) > 0
			? mpd_song_get_duration(song)
			: g_timer_elapsed(timer, NULL),
			NULL);
}
Example #4
0
/**
 * MPD stopped playing this song.
 */
void
song_ended(const struct mpd_song *song, bool love)
{
    int elapsed = g_timer_elapsed(timer, NULL);

    if (!played_long_enough(elapsed, mpd_song_get_duration(song)))
        return;

    /* FIXME:
       libmpdclient doesn't have any way to fetch the musicbrainz id. */
    as_songchange(mpd_song_get_uri(song),
                  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_TRACK, 0),
                  mpd_song_get_tag(song, MPD_TAG_MUSICBRAINZ_TRACKID, 0),
                  mpd_song_get_duration(song) > 0
                  ? mpd_song_get_duration(song)
                  : g_timer_elapsed(timer, NULL),
                  love,
                  NULL);
}