Esempio n. 1
0
struct mpd_song *
mpd_song_begin(const struct mpd_pair *pair)
{
	assert(pair != NULL);
	assert(pair->name != NULL);
	assert(pair->value != NULL);

	if (strcmp(pair->name, "file") != 0 || !mpd_verify_uri(pair->value)) {
		errno = EINVAL;
		return NULL;
	}

	return mpd_song_new(pair->value);
}
Esempio n. 2
0
/* -------------------------------------------------------------------------- */
static struct song *mpd_get_current_song(struct lcd_stuff_mpd *mpd)
{
    mpd_Song        *current;
    gchar           **strings;
    struct song     *ret;

    current = mpd_playlist_get_current_song(mpd->mpd);
    if (!current || mpd->current_state != MPD_PLAYER_PLAY) {
        ret = mpd_song_new("", "");
    } else if (!current->title) {
        ret = mpd_song_new("(unknown)", "");
    } else {
        strings = g_strsplit(current->title, " - ", 2);
        if (g_strv_length(strings) == 2) {
            ret = mpd_song_new(strings[0], strings[1]);
        } else {
            ret = mpd_song_new(current->artist ? current->artist : "",
                    current->title ? current->title : "");
        }
        g_strfreev(strings);
    }

    return ret;
}
Esempio n. 3
0
struct mpd_song *
mpd_song_dup(const struct mpd_song *song)
{
	struct mpd_song *ret;
	bool success;

	assert(song != NULL);

	ret = mpd_song_new(song->uri);
	if (ret == NULL)
		/* out of memory */
		return NULL;

	for (unsigned i = 0; i < MPD_TAG_COUNT; ++i) {
		const struct mpd_tag_value *src_tag = &song->tags[i];

		if (src_tag->value == NULL)
			continue;

		do {
			success = mpd_song_add_tag(ret, i, src_tag->value);
			if (!success) {
				mpd_song_free(ret);
				return NULL;
			}

			src_tag = src_tag->next;
		} while (src_tag != NULL);
	}

	ret->duration = song->duration;
	ret->start = song->start;
	ret->end = song->end;
	ret->last_modified = song->last_modified;
	ret->pos = song->pos;
	ret->id = song->id;

#ifndef NDEBUG
	ret->finished = true;
#endif

	return ret;
}
Esempio n. 4
0
/* -------------------------------------------------------------------------- */
static bool mpd_start_connection(struct lcd_stuff_mpd *mpd)
{
    int     err;

    mpd->error = false;

    /* create the current song */
    mpd_song_delete(mpd->current_song);
    mpd->current_song = mpd_song_new("", "");

    /* create the object */
    if (mpd->mpd) {
        mpd_free(mpd->mpd);
        mpd->mpd = NULL;
    }
    mpd->mpd = mpd_new(mpd->connection->host, mpd->connection->port, mpd->connection->password);

    /* connect signal handlers */
    mpd_signal_connect_error(mpd->mpd, mpd_error_handler, mpd);
    mpd_signal_connect_status_changed(mpd->mpd, mpd_state_changed_handler, mpd);
    mpd_signal_connect_connection_changed(mpd->mpd, mpd_connection_changed_handler, mpd);

    /* set timeout */
    mpd_set_connection_timeout(mpd->mpd, mpd->timeout);
    if (mpd->error) {
        mpd_disconnect(mpd->mpd);
        return false;
    }

    /* connect */
    err = mpd_connect(mpd->mpd);
    if (err != MPD_OK || mpd->error) {
        report(RPT_ERR, "Failed to connect: %d", err);
        return false;
    }

    return true;
}