Esempio n. 1
0
File: mpd.c Progetto: 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);
}
Esempio n. 2
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');
}
Esempio n. 3
0
int mpd_put_state(char *buffer, int *current_song_id, unsigned *queue_version)
{
    struct mpd_status *status;
    int len;

    status = mpd_run_status(mpd.conn);
    if (!status) {
        fprintf(stderr, "MPD mpd_run_status: %s\n", mpd_connection_get_error_message(mpd.conn));
        mpd.conn_state = MPD_FAILURE;
        return 0;
    }

    len = snprintf(buffer, MAX_SIZE,
        "{\"type\":\"state\", \"data\":{"
        " \"state\":%d, \"volume\":%d, \"repeat\":%d,"
        " \"single\":%d, \"consume\":%d, \"random\":%d, "
        " \"songpos\": %d, \"elapsedTime\": %d, \"totalTime\":%d, "
        " \"currentsongid\": %d"
        "}}", 
        mpd_status_get_state(status),
        mpd_status_get_volume(status), 
        mpd_status_get_repeat(status),
        mpd_status_get_single(status),
        mpd_status_get_consume(status),
        mpd_status_get_random(status),
        mpd_status_get_song_pos(status),
        mpd_status_get_elapsed_time(status),
        mpd_status_get_total_time(status),
        mpd_status_get_song_id(status));

    *current_song_id = mpd_status_get_song_id(status);
    *queue_version = mpd_status_get_queue_version(status);
    mpd_status_free(status);
    return len;
}
Esempio n. 4
0
void
songlist_simple_bar(void)
{
  int crt_time, crt_time_perc, total_time,
	fill_len, rest_len, i;
  struct mpd_status *status;

  WINDOW *win = specific_win(SIMPLE_PROC_BAR);
  const int bar_length = win->_maxx + 1;
  
  status = getStatus(conn);
  crt_time = mpd_status_get_elapsed_time(status);
  total_time = mpd_status_get_total_time(status);
  mpd_status_free(status);

  crt_time_perc = (total_time == 0 ? 0 : 100 * crt_time / total_time);    
  fill_len = crt_time_perc * bar_length / 100;
  rest_len = bar_length - fill_len;

  wattron(win, my_color_pairs[2]);  
  for(i = 0; i < fill_len; wprintw(win, "*"), i++);
  wattroff(win, my_color_pairs[2]);  

  for(i = 0; i < rest_len; wprintw(win, "*"), i++);
}
Esempio n. 5
0
void mpd_put_state(void)
{
    struct mpd_status *status;
    int len;
    unsigned queue_len;
    int song_pos, next_song_pos;

    status = mpd_run_status(mpd.conn);
    
    if (!status) {
        syslog(LOG_ERR, "%s mpd_run_status: %s\n", __func__, mpd_connection_get_error_message(mpd.conn));
        mpd.conn_state = MPD_FAILURE;
        return;
    }

    mpd.song_pos = mpd_status_get_song_pos(status);
    mpd.next_song_pos = song_pos+1; //TODO: mpd_status_get_next_song_pos(status);
    mpd.queue_len = mpd_status_get_queue_length(status);
    mpd.volume = mpd_status_get_volume(status);
    mpd.state = mpd_status_get_state(status);
    mpd.repeat = mpd_status_get_repeat(status);
    mpd.single = mpd_status_get_single(status);
    mpd.consume = mpd_status_get_consume(status);
    mpd.random = mpd_status_get_random(status);
    mpd.elapsed_time = mpd_status_get_elapsed_time(status);
    mpd.total_time = mpd_status_get_total_time(status);
    mpd.song_id = mpd_status_get_song_id(status);

//    printf("%d\n", mpd.song_id);

    mpd_status_free(status);
}
Esempio n. 6
0
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;
}
Esempio n. 7
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;
}
Esempio n. 8
0
char* getElapsedTime(Config* config, int status) {

	if (!config->mpd_status) {
		return strdup("");
	}

	unsigned time = mpd_status_get_elapsed_time(config->mpd_status);

	return timeToString(config, time);
}
Esempio n. 9
0
File: status.c Progetto: GGbaba/mpc
static unsigned
elapsed_percent(const struct mpd_status *status)
{
	unsigned total = mpd_status_get_total_time(status);
	if (total == 0)
		return 0;

	unsigned elapsed = mpd_status_get_elapsed_time(status);
	if (elapsed >= total)
		return 100;

	return (elapsed * 100) / total;
}
Esempio n. 10
0
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;
}
Esempio n. 11
0
static bool
setup_seek(struct mpdclient *c)
{
	if (!mpdclient_is_playing(c))
		return false;

	if (seek_id != (int)mpd_status_get_song_id(c->status)) {
		seek_id = mpd_status_get_song_id(c->status);
		seek_target_time = mpd_status_get_elapsed_time(c->status);
	}

	schedule_seek_timer(c);

	return true;
}
Esempio n. 12
0
File: command.c Progetto: daaang/mpc
int
cmd_cdprev(gcc_unused int argc, gcc_unused char **argv,
	   struct mpd_connection *conn)
{
	struct mpd_status *status = getStatus(conn);

	/* go to previous track if mpd is playing first 3 seconds of
	   current track otherwise seek to beginning of current
	   track */
	if (mpd_status_get_elapsed_time(status) < 3) {
		cmd_prev(0, NULL, conn);
	} else {
		if (!mpd_run_seek_id(conn, mpd_status_get_song_id(status), 0))
			printErrorAndExit(conn);
	}

	return 1;
}
Esempio n. 13
0
char* getTimeBar(Config* config, int status) {

	if (config->timebar < 3) {
		return strdup("");
	}

	char* timeBar = calloc(config->timebar + 1, sizeof(char));
	unsigned duration;
	if (config->curr_song) {
		duration = mpd_song_get_duration(config->curr_song);
	} else {
		duration = 0;
	}
	unsigned elapsed = mpd_status_get_elapsed_time(config->mpd_status);
	unsigned blockSize = duration / (config->timebar - 2);

	unsigned block = 0;

	if (blockSize) {
		block = elapsed / blockSize;
	}

	timeBar[0] = '[';
	unsigned i;
	for (i = 1; i < block; i++) {
		timeBar[i] = '=';
	}
	if (i > config->timebar - 2) {
		i = config->timebar - 2;
	}

	timeBar[i] = '>';
	i++;
	for (; i < config->timebar; i++) {
		timeBar[i] = '-';
	}

	timeBar[config->timebar - 1] = ']';
	timeBar[config->timebar] = 0;

	return timeBar;
}
Esempio n. 14
0
static void
update_progress_window(struct mpdclient *c, bool repaint)
{
	unsigned elapsed, duration;

	if (c->status == NULL)
		elapsed = 0;
	else if (seek_id >= 0 && seek_id == mpd_status_get_song_id(c->status))
		elapsed = seek_target_time;
	else
		elapsed = mpd_status_get_elapsed_time(c->status);

	duration = mpdclient_is_playing(c)
		? mpd_status_get_total_time(c->status)
		: 0;

	if (progress_bar_set(&screen.progress_bar, elapsed, duration) ||
	    repaint)
		progress_bar_paint(&screen.progress_bar);
}
Esempio n. 15
0
File: lib.c Progetto: qsn/mpdfs
void do_status(struct mpd_connection *con, int *current, unsigned int *current_elapsed, unsigned int *current_total, unsigned int *length, unsigned int *version)
{
	struct mpd_status *st = mpd_run_status(con);

	if (!st)
		return;
	if (check_error(con, NULL, false))
		goto out;

	switch (mpd_status_get_state(st)) {
	case MPD_STATE_UNKNOWN:
	case MPD_STATE_STOP:
		if (current)
			*current = -1;
		if (current_elapsed)
			*current_elapsed = 0;
		if (current_total)
			*current_total = 0;
		break;
	case MPD_STATE_PLAY:
	case MPD_STATE_PAUSE:
		if (current)
			*current = mpd_status_get_song_pos(st);
		if (current_elapsed)
			*current_elapsed = mpd_status_get_elapsed_time(st);
		if (current_total)
			*current_total = mpd_status_get_total_time(st);
		break;
	}
	if (length)
		*length = mpd_status_get_queue_length(st);
	if (version)
		*version = mpd_status_get_queue_version(st);

out:
	mpd_status_free(st);
}
Esempio n. 16
0
void
updatempdstatus(void) {
    char statustext[STEXTSIZE];
    struct mpd_status *s = NULL;
    struct mpd_song *so = NULL;
    int s_volume,
        s_flagmask,
        s_queuelength,
        s_songpos,
        s_state,
        s_songlen,
        s_songtime;
    int s_time_r, s_time_min, s_time_sec;
    const char *artist, *title;

    if(mpdcmd_connect() != 0)
        return;

    s = mpd_run_status(mpdc);
    if(s == NULL)
        return;

    // retrieve status information

    if((s_state = mpd_status_get_state(s)) == MPD_STATE_STOP ||
        (so = mpd_run_current_song(mpdc)) == NULL)
        goto EXIT;

    s_volume = mpd_status_get_volume(s);
    s_queuelength = mpd_status_get_queue_length(s);
    s_songpos = mpd_status_get_song_pos(s);
    s_songlen = mpd_status_get_total_time(s);
    s_songtime = mpd_status_get_elapsed_time(s);
    s_time_r = s_songlen - s_songtime;
    s_time_sec = s_time_r % 60;
    s_time_min = (s_time_r - s_time_sec) / 60;
    if(mpd_status_get_consume(s) == 1)
        s_flagmask |= MpdFlag_Consume;
    if(mpd_status_get_single(s) == 1)
        s_flagmask |= MpdFlag_Single;
    if(mpd_status_get_random(s) == 1)
        s_flagmask |= MpdFlag_Random;
    if(mpd_status_get_repeat(s) == 1)
        s_flagmask |= MpdFlag_Repeat;
    artist = mpd_song_get_tag(so, MPD_TAG_ARTIST, 0);
    title = mpd_song_get_tag(so, MPD_TAG_TITLE, 0);


    //%artist - %title (-%total-%elapsed) [$flags] [#%pos/%queuelength]

    snprintf(statustext, STEXTSIZE,
            "%s - %s  (-%d:%02d)",
            artist != NULL ? artist : "名無し",
            title != NULL ? title : "曲名無し",
            s_time_min,
            s_time_sec);
    strncpy(stext, statustext, STEXTSIZE);

EXIT:;
    mpd_song_free(so);
    mpd_status_free(s);
    return;
}
Esempio n. 17
0
void mpd_query_status(struct mpd_connection *conn)
{
    struct mpd_status *status;
    struct mpd_song *song;
    const struct mpd_audio_format *audio;

    if (!conn)
	return;

    if (!mpd_command_list_begin(conn, true) ||
	!mpd_send_status(conn) || !mpd_send_current_song(conn) || !mpd_command_list_end(conn)) {
	mpd_printerror("queue_commands");
	return;
    }

    status = mpd_recv_status(conn);
    if (status == NULL) {
	mpd_printerror("recv_status");
	return;
    }
    if (currentSong != NULL) {
	mpd_song_free(currentSong);
	currentSong = NULL;
    }

    if (!mpd_response_next(conn)) {
	mpd_printerror("response_next");
	return;
    }

    song = mpd_recv_song(conn);
    if (song != NULL) {
	currentSong = mpd_song_dup(song);
	mpd_song_free(song);

	l_elapsedTimeSec = mpd_status_get_elapsed_time(status);
	l_totalTimeSec = mpd_status_get_total_time(status);
	l_bitRate = mpd_status_get_kbit_rate(status);
    } else {
	l_elapsedTimeSec = 0;
	l_totalTimeSec = 0;
	l_bitRate = 0;
    }
    l_state = mpd_status_get_state(status);

    l_repeatEnabled = mpd_status_get_repeat(status);
    l_randomEnabled = mpd_status_get_random(status);
    l_singleEnabled = mpd_status_get_single(status);
    l_consumeEnabled = mpd_status_get_consume(status);

    l_volume = mpd_status_get_volume(status);

    l_currentSongPos = mpd_status_get_song_pos(status) + 1;
    l_playlistLength = mpd_status_get_queue_length(status);


    audio = mpd_status_get_audio_format(status);
    if (audio) {
	l_sampleRate = audio->sample_rate;
	l_channels = audio->channels;
    } else {
	l_sampleRate = 0;
	l_channels = 0;
    }

    if (mpd_status_get_error(status) != NULL)
	error("[MPD] query status : %s", charset_from_utf8(mpd_status_get_error(status)));

    mpd_status_free(status);

    if (!mpd_response_finish(conn)) {
	mpd_printerror("response_finish");
	return;
    }
}
Esempio n. 18
0
/* This function update the internal status tracking
 * the MPD status. At then end, if the status has changed, a signal is emmited.
 */
void Player::updateStatus()
{
    struct mpd_status *statusMpd;
    EMSPlayerStatus statusEMS;

    /* Get the status structure from MPD */
    mpd_send_status(conn);
    statusMpd = mpd_recv_status(conn);
    if (statusMpd == NULL)
    {
        qCritical() << "Error while trying to get MPD status";
        qCritical() << "Reconnecting...";
        connectToMpd(); /* Reconnect */
        return;
    }

    if (mpd_status_get_error(statusMpd) != NULL)
    {
        qCritical() << "MPD error: " << QString::fromUtf8(mpd_status_get_error(statusMpd));
    }

    if (!mpd_response_finish(conn))
    {
        qCritical() << "Error while trying to get MPD status" ;
        qCritical() << "Reconnecting...";
        connectToMpd();
        return;
    }

    /* Fill the internal state from the answer */
    switch (mpd_status_get_state(statusMpd))
    {
        case MPD_STATE_PAUSE:
            statusEMS.state = STATUS_PAUSE;
            break;
        case MPD_STATE_PLAY:
            statusEMS.state = STATUS_PLAY;
            break;
        case MPD_STATE_STOP:
            statusEMS.state = STATUS_STOP;
            break;
        default:
            statusEMS.state = STATUS_UNKNOWN;
            break;
    }

    statusEMS.repeat = mpd_status_get_repeat(statusMpd);
    statusEMS.random = mpd_status_get_random(statusMpd);

    if (statusEMS.state == STATUS_PLAY || statusEMS.state == STATUS_PAUSE)
    {
        if (mpd_status_get_queue_length(statusMpd) != (unsigned int)playlist.tracks.size())
        {
            qCritical() << "Error: the playlist does not have the same size as the one used by MPD!";
            /* We should not do this... */
            removeAllTracks();
        }

        statusEMS.posInPlaylist = mpd_status_get_song_pos(statusMpd);
        statusEMS.progress = mpd_status_get_elapsed_time(statusMpd);
    }

    mpd_status_free(statusMpd);

    if (statusEMS.posInPlaylist != status.posInPlaylist ||
        statusEMS.progress != status.progress ||
        statusEMS.random != status.random ||
        statusEMS.repeat != status.repeat ||
        statusEMS.state != status.state )
    {
        mutex.lock();
        status = statusEMS;
        mutex.unlock();
        emit statusChanged(statusEMS);
    }
}
Esempio n. 19
0
static void
env_export_status(struct mpd_status *status)
{
	char *envstr;
	const struct mpd_audio_format *fmt;

	envstr = g_strdup_printf("%d", mpd_status_get_volume(status));
	g_setenv("MPD_STATUS_VOLUME", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_repeat(status));
	g_setenv("MPD_STATUS_REPEAT", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_random(status));
	g_setenv("MPD_STATUS_RANDOM", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_single(status));
	g_setenv("MPD_STATUS_SINGLE", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_consume(status));
	g_setenv("MPD_STATUS_CONSUME", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_queue_length(status));
	g_setenv("MPD_STATUS_QUEUE_LENGTH", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_queue_version(status));
	g_setenv("MPD_STATUS_QUEUE_VERSION", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_crossfade(status));
	g_setenv("MPD_STATUS_CROSSFADE", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_song_pos(status));
	g_setenv("MPD_STATUS_SONG_POS", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%d", mpd_status_get_song_id(status));
	g_setenv("MPD_STATUS_SONG_ID", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%u", mpd_status_get_elapsed_time(status));
	g_setenv("MPD_STATUS_ELAPSED_TIME", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%u", mpd_status_get_elapsed_ms(status));
	g_setenv("MPD_STATUS_ELAPSED_MS", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%u", mpd_status_get_total_time(status));
	g_setenv("MPD_STATUS_TOTAL_TIME", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%u", mpd_status_get_kbit_rate(status));
	g_setenv("MPD_STATUS_KBIT_RATE", envstr, 1);
	g_free(envstr);

	envstr = g_strdup_printf("%u", mpd_status_get_update_id(status));
	g_setenv("MPD_STATUS_UPDATE_ID", envstr, 1);
	g_free(envstr);

	g_setenv("MPD_STATUS_STATE", env_strstate(mpd_status_get_state(status)), 1);

	if ((fmt = mpd_status_get_audio_format(status)) == NULL)
		g_setenv("MPD_STATUS_AUDIO_FORMAT", "0", 1);
	else {
		g_setenv("MPD_STATUS_AUDIO_FORMAT", "1", 1);

		envstr = g_strdup_printf("%u", fmt->sample_rate);
		g_setenv("MPD_STATUS_AUDIO_FORMAT_SAMPLE_RATE", envstr, 1);
		g_free(envstr);

		envstr = g_strdup_printf("%u", fmt->bits);
		g_setenv("MPD_STATUS_AUDIO_FORMAT_BITS", envstr, 1);
		g_free(envstr);

		envstr = g_strdup_printf("%u", fmt->channels);
		g_setenv("MPD_STATUS_AUDIO_FORMAT_CHANNELS", envstr, 1);
		g_free(envstr);
	}
}
Esempio n. 20
0
void
CMPD::Update()
{
	if(!_connected) {
        iprintf("Reconnecting in 10 seconds.");
        sleep(10);
		if(Connect())
            iprintf("%s", "Reconnected!");
        else {
            eprintf("%s", "Could not reconnect.");
            return;
        }
	}

    mpd_status *status = mpd_run_status(_conn);
    mpd_stats *stats = mpd_run_stats(_conn);

    if(status && stats) {
        int newsongid = mpd_status_get_song_id(status);
        int newsongpos = mpd_status_get_elapsed_time(status);
        int curplaytime = mpd_stats_get_play_time(stats);

        // new song
        if(newsongid != _songid) {
            _songid = newsongid;
            _songpos = newsongpos;
            _start = curplaytime;

            mpd_song *song = mpd_run_current_song(_conn);
            if(song) {
                GotNewSong(song);
                mpd_song_free(song);
            }
        }

        // song playing
        if(newsongpos != _songpos) {
            _songpos = newsongpos;
            CheckSubmit(curplaytime);
        }

        // check for client-to-client messages
        if(mpd_send_read_messages(_conn)) {
            mpd_message *msg;
            while((msg = mpd_recv_message(_conn)) != NULL) {
                const char *text = mpd_message_get_text(msg);
                if(_gotsong && text && !strncmp(text, "love", 4))
                    AudioScrobbler->LoveTrack(_song);
                mpd_message_free(msg);
            }
            mpd_response_finish(_conn);
        }

        mpd_status_free(status);
        mpd_stats_free(stats);
    }
    else { // we have most likely lost our connection
        eprintf("Could not query MPD server: %s", mpd_connection_get_error_message(_conn));
        _connected = false;
    }
}
Esempio n. 21
0
void
basic_state_checking(void)
{
  int rep, ran, sgl, len, crt, vol, ply, btr;
  struct mpd_status *status;

  status = getStatus(conn);

  rep = mpd_status_get_repeat(status);
  ran = mpd_status_get_random(status);
  sgl = mpd_status_get_single(status);
  len = mpd_status_get_queue_length(status);
  crt = mpd_status_get_song_id(status);
  vol = mpd_status_get_volume(status);
  ply = mpd_status_get_state(status);
  btr = mpd_status_get_kbit_rate(status);

  basic_info->crt_time = mpd_status_get_elapsed_time(status);
  basic_info->total_time = mpd_status_get_total_time(status);
  
  mpd_status_free(status);

  if(rep != basic_info->repeat || ran != basic_info->random
	 || sgl != basic_info->single || len != basic_info->total
	 || crt != basic_info->current || vol != basic_info->volume
	 || ply != basic_info->state)
	{
	  basic_info->repeat = rep;
	  basic_info->random = ran;
	  basic_info->single = sgl;
	  basic_info->total = len;
	  basic_info->current = crt;
	  basic_info->volume = vol;
	  basic_info->state = ply;

	  signal_all_wins();
	}

  /* as many songs's bit rate varies while playing
	 we refresh the bit rate display only when the 
	 relevant change greater than 0.2 */
  if(abs(basic_info->bit_rate - btr) / (float)(btr + 1) > 0.2)
	{
	  basic_info->bit_rate = btr;
	  signal_win(BASIC_INFO);
	}

  
  /* get current song's name */
  status = init_mpd_status(conn);

  strncpy(basic_info->format, "null", 16);
  *basic_info->crt_name = '\0';
	
  if (basic_info->state == MPD_STATE_PLAY ||
	  basic_info->state == MPD_STATE_PAUSE) {
	struct mpd_song *song;

	if (!mpd_response_next(conn))
	  printErrorAndExit(conn);

	song = mpd_recv_song(conn);
	if (song != NULL) {
	  strncpy(basic_info->crt_name, get_song_tag(song, MPD_TAG_TITLE), 512);
	  strncpy(basic_info->format, get_song_format(song), 16);
	}

	mpd_song_free(song);
  }

  mpd_status_free(status);
  my_finishCommand(conn);	
}
Esempio n. 22
0
File: status.c Progetto: GGbaba/mpc
void
print_status(struct mpd_connection *conn)
{
	if (!mpd_command_list_begin(conn, true) ||
	    !mpd_send_status(conn) ||
	    !mpd_send_current_song(conn) ||
	    !mpd_command_list_end(conn))
		printErrorAndExit(conn);

	struct mpd_status *status = mpd_recv_status(conn);
	if (status == NULL)
		printErrorAndExit(conn);

	if (mpd_status_get_state(status) == MPD_STATE_PLAY ||
	    mpd_status_get_state(status) == MPD_STATE_PAUSE) {
		if (!mpd_response_next(conn))
			printErrorAndExit(conn);

		struct mpd_song *song = mpd_recv_song(conn);
		if (song != NULL) {
			pretty_print_song(song);
			printf("\n");

			mpd_song_free(song);
		}

		if (mpd_status_get_state(status) == MPD_STATE_PLAY)
			printf("[playing]");
		else
			printf("[paused] ");

		printf(" #%i/%u %3i:%02i/%i:%02i (%u%%)\n",
		       mpd_status_get_song_pos(status) + 1,
		       mpd_status_get_queue_length(status),
		       mpd_status_get_elapsed_time(status) / 60,
		       mpd_status_get_elapsed_time(status) % 60,
		       mpd_status_get_total_time(status) / 60,
		       mpd_status_get_total_time(status) % 60,
		       elapsed_percent(status));
	}

	if (mpd_status_get_update_id(status) > 0)
		printf("Updating DB (#%u) ...\n",
		       mpd_status_get_update_id(status));

	if (mpd_status_get_volume(status) >= 0)
		printf("volume:%3i%c   ", mpd_status_get_volume(status), '%');
	else {
		printf("volume: n/a   ");
	}

	printf("repeat: ");
	if (mpd_status_get_repeat(status))
		printf("on    ");
	else printf("off   ");

	printf("random: ");
	if (mpd_status_get_random(status))
		printf("on    ");
	else printf("off   ");

	printf("single: ");
	if (mpd_status_get_single(status))
		printf("on    ");
	else printf("off   ");

	printf("consume: ");
	if (mpd_status_get_consume(status))
		printf("on \n");
	else printf("off\n");

	if (mpd_status_get_error(status) != NULL)
		printf("ERROR: %s\n",
		       charset_from_utf8(mpd_status_get_error(status)));

	mpd_status_free(status);

	if (!mpd_response_finish(conn))
		printErrorAndExit(conn);
}
Esempio n. 23
0
static int lmpdstatus_index(lua_State *L)
{
	const char *key;
	const struct mpd_audio_format *audio_format;
	struct mpd_status **status;

	status = luaL_checkudata(L, 1, MPD_STATUS_T);
	key = luaL_checkstring(L, 2);

	assert(*status != NULL);

	if (strncmp(key, "volume", 7) == 0) {
		lua_pushinteger(L, mpd_status_get_volume(*status));
		return 1;
	}
	else if (strncmp(key, "repeat", 7) == 0) {
		lua_pushinteger(L, mpd_status_get_repeat(*status));
		return 1;
	}
	else if (strncmp(key, "random", 7) == 0) {
		lua_pushinteger(L, mpd_status_get_random(*status));
		return 1;
	}
	else if (strncmp(key, "single", 7) == 0) {
		lua_pushinteger(L, mpd_status_get_single(*status));
		return 1;
	}
	else if (strncmp(key, "consume", 8) == 0) {
		lua_pushinteger(L, mpd_status_get_consume(*status));
		return 1;
	}
	else if (strncmp(key, "queue_length", 16) == 0) {
		lua_pushnumber(L, mpd_status_get_queue_length(*status));
		return 1;
	}
	else if (strncmp(key, "queue_version", 17) == 0) {
		lua_pushnumber(L, mpd_status_get_queue_version(*status));
		return 1;
	}
	else if (strncmp(key, "state", 6) == 0) {
		lua_pushinteger(L, mpd_status_get_state(*status));
		return 1;
	}
	else if (strncmp(key, "crossfade", 10) == 0) {
		lua_pushinteger(L, mpd_status_get_crossfade(*status));
		return 1;
	}
	else if (strncmp(key, "song_pos", 5) == 0) {
		lua_pushinteger(L, mpd_status_get_song_pos(*status));
		return 1;
	}
	else if (strncmp(key, "song_id", 7) == 0) {
		lua_pushinteger(L, mpd_status_get_song_id(*status));
		return 1;
	}
	else if (strncmp(key, "elapsed_time", 13) == 0) {
		lua_pushinteger(L, mpd_status_get_elapsed_time(*status));
		return 1;
	}
	else if (strncmp(key, "total_time", 11) == 0) {
		lua_pushinteger(L, mpd_status_get_total_time(*status));
		return 1;
	}
	else if (strncmp(key, "kbit_rate", 10) == 0) {
		lua_pushinteger(L, mpd_status_get_kbit_rate(*status));
		return 1;
	}
	else if (strncmp(key, "audio_format", 13) == 0) {
		audio_format = mpd_status_get_audio_format(*status);
		lua_newtable(L);

		lua_pushinteger(L, audio_format->sample_rate);
		lua_setfield(L, -2, "sample_rate");

		lua_pushinteger(L, audio_format->bits);
		lua_setfield(L, -2, "bits");

		lua_pushinteger(L, audio_format->channels);
		lua_setfield(L, -2, "channels");

		return 1;
	}
	else if (strncmp(key, "update_id", 11) == 0) {
		lua_pushinteger(L, mpd_status_get_update_id(*status));
		return 1;
	}
	else if (strncmp(key, "error", 6) == 0) {
		lua_pushstring(L, mpd_status_get_error(*status));
		return 1;
	}
	else
		return luaL_error(L, "Invalid key `%s'", key);
}
Esempio n. 24
0
int main(int argc, char ** argv) {
	struct mpd_connection *conn;

	conn = mpd_connection_new(NULL, 0, 30000);

	if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
		return handle_error(conn);

	{
		int i;
		for(i=0;i<3;i++) {
			printf("version[%i]: %i\n",i,
			       mpd_connection_get_server_version(conn)[i]);
		}
	}

	if(argc==1) {
		struct mpd_status * status;
		struct mpd_song *song;
		const struct mpd_audio_format *audio_format;

		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 (status == NULL)
			return handle_error(conn);

		printf("volume: %i\n", mpd_status_get_volume(status));
		printf("repeat: %i\n", mpd_status_get_repeat(status));
		printf("queue version: %u\n", mpd_status_get_queue_version(status));
		printf("queue length: %i\n", mpd_status_get_queue_length(status));
		if (mpd_status_get_error(status) != NULL)
			printf("error: %s\n", mpd_status_get_error(status));

		if (mpd_status_get_state(status) == MPD_STATE_PLAY ||
		    mpd_status_get_state(status) == MPD_STATE_PAUSE) {
			printf("song: %i\n", mpd_status_get_song_pos(status));
			printf("elaspedTime: %i\n",mpd_status_get_elapsed_time(status));
			printf("elasped_ms: %u\n", mpd_status_get_elapsed_ms(status));
			printf("totalTime: %i\n", mpd_status_get_total_time(status));
			printf("bitRate: %i\n", mpd_status_get_kbit_rate(status));
		}

		audio_format = mpd_status_get_audio_format(status);
		if (audio_format != NULL) {
			printf("sampleRate: %i\n", audio_format->sample_rate);
			printf("bits: %i\n", audio_format->bits);
			printf("channels: %i\n", audio_format->channels);
		}

		mpd_status_free(status);

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
			return handle_error(conn);

		mpd_response_next(conn);

		while ((song = mpd_recv_song(conn)) != NULL) {
			printf("uri: %s\n", mpd_song_get_uri(song));
			print_tag(song, MPD_TAG_ARTIST, "artist");
			print_tag(song, MPD_TAG_ALBUM, "album");
			print_tag(song, MPD_TAG_TITLE, "title");
			print_tag(song, MPD_TAG_TRACK, "track");
			print_tag(song, MPD_TAG_NAME, "name");
			print_tag(song, MPD_TAG_DATE, "date");

			if (mpd_song_get_duration(song) > 0) {
				printf("time: %u\n", mpd_song_get_duration(song));
			}

			printf("pos: %u\n", mpd_song_get_pos(song));

			mpd_song_free(song);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	}
	else if(argc==3 && strcmp(argv[1],"lsinfo")==0) {
		struct mpd_entity * entity;

		if (!mpd_send_list_meta(conn, argv[2]))
			return handle_error(conn);

		while ((entity = mpd_recv_entity(conn)) != NULL) {
			const struct mpd_song *song;
			const struct mpd_directory *dir;
			const struct mpd_playlist *pl;

			switch (mpd_entity_get_type(entity)) {
			case MPD_ENTITY_TYPE_UNKNOWN:
				break;

			case MPD_ENTITY_TYPE_SONG:
				song = mpd_entity_get_song(entity);
				printf("uri: %s\n", mpd_song_get_uri(song));
				print_tag(song, MPD_TAG_ARTIST, "artist");
				print_tag(song, MPD_TAG_ALBUM, "album");
				print_tag(song, MPD_TAG_TITLE, "title");
				print_tag(song, MPD_TAG_TRACK, "track");
				break;

			case MPD_ENTITY_TYPE_DIRECTORY:
				dir = mpd_entity_get_directory(entity);
				printf("directory: %s\n", mpd_directory_get_path(dir));
				break;

			case MPD_ENTITY_TYPE_PLAYLIST:
				pl = mpd_entity_get_playlist(entity);
				printf("playlist: %s\n",
				       mpd_playlist_get_path(pl));
				break;
			}

			mpd_entity_free(entity);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	}
	else if(argc==2 && strcmp(argv[1],"artists")==0) {
		struct mpd_pair *pair;

		if (!mpd_search_db_tags(conn, MPD_TAG_ARTIST) ||
		    !mpd_search_commit(conn))
			return handle_error(conn);

		while ((pair = mpd_recv_pair_tag(conn,
						 MPD_TAG_ARTIST)) != NULL) {
			printf("%s\n", pair->value);
			mpd_return_pair(conn, pair);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	} else if (argc == 2 && strcmp(argv[1], "playlists") == 0) {
		if (!mpd_send_list_playlists(conn))
			return handle_error(conn);

		struct mpd_playlist *playlist;
		while ((playlist = mpd_recv_playlist(conn)) != NULL) {
			printf("%s\n",
			       mpd_playlist_get_path(playlist));
			mpd_playlist_free(playlist);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	} else if (argc == 2 && strcmp(argv[1], "idle") == 0) {
		enum mpd_idle idle = mpd_run_idle(conn);
		if (idle == 0 &&
		    mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
			return handle_error(conn);

		for (unsigned j = 0;; ++j) {
			enum mpd_idle i = 1 << j;
			const char *name = mpd_idle_name(i);

			if (name == NULL)
				break;

			if (idle & i)
				printf("%s\n", name);
		}
	} else if (argc == 3 && strcmp(argv[1], "subscribe") == 0) {
		/* subscribe to a channel and print all messages */

		if (!mpd_run_subscribe(conn, argv[2]))
			return handle_error(conn);

		while (mpd_run_idle_mask(conn, MPD_IDLE_MESSAGE) != 0) {
			if (!mpd_send_read_messages(conn))
				return handle_error(conn);

			struct mpd_message *msg;
			while ((msg = mpd_recv_message(conn)) != NULL) {
				printf("%s\n", mpd_message_get_text(msg));
				mpd_message_free(msg);
			}

			if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
			    !mpd_response_finish(conn))
				return handle_error(conn);
		}

		return handle_error(conn);
	} else if (argc == 2 && strcmp(argv[1], "channels") == 0) {
		/* print a list of channels */

		if (!mpd_send_channels(conn))
			return handle_error(conn);

		struct mpd_pair *pair;
		while ((pair = mpd_recv_channel_pair(conn)) != NULL) {
			printf("%s\n", pair->value);
			mpd_return_pair(conn, pair);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	} else if (argc == 4 && strcmp(argv[1], "message") == 0) {
		/* send a message to a channel */

		if (!mpd_run_send_message(conn, argv[2], argv[3]))
			return handle_error(conn);
	}

	mpd_connection_free(conn);

	return 0;
}
Esempio n. 25
0
/*
 * pgmpc_status
 *
 * Show current song and status.
 */
Datum
pgmpc_status(PG_FUNCTION_ARGS)
{
#define PGMPC_STATUS_COLUMNS 7
	Datum		values[PGMPC_STATUS_COLUMNS];
	bool		nulls[PGMPC_STATUS_COLUMNS];
	TupleDesc	tupdesc;
	HeapTuple	tuple;
	Datum		result;

	if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
		elog(ERROR, "return type must be a row type");

	pgmpc_init();

	/* Initialize the values of return tuple */
	MemSet(values, 0, sizeof(values));
	MemSet(nulls, true, sizeof(nulls));

	/*
	 * Send all necessary commands at once to avoid unnecessary round
	 * trips. The following information is obtained in an aync way:
	 * - current status of server
	 * - current song run on server
	 */
	if (!mpd_command_list_begin(mpd_conn, true) ||
		!mpd_send_status(mpd_conn) ||
		!mpd_send_current_song(mpd_conn) ||
		!mpd_command_list_end(mpd_conn))
		pgmpc_print_error();

	/* Obtain status from server and check it */
	mpd_status = mpd_recv_status(mpd_conn);
	if (mpd_status == NULL)
		pgmpc_print_error();

	/* Show current song if any */
	if (mpd_status_get_state(mpd_status) == MPD_STATE_PLAY ||
		mpd_status_get_state(mpd_status) == MPD_STATE_PAUSE)
	{
		struct mpd_song *song;

		/* There should be a next response, in this case a song */
		if (!mpd_response_next(mpd_conn))
			pgmpc_print_error();

		/* And now get it */
		song = mpd_recv_song(mpd_conn);
		if (song != NULL)
		{
			/* Get information about the current song */
			const char *title = mpd_song_get_tag(song, MPD_TAG_TITLE, 0);
			const char *artist = mpd_song_get_tag(song, MPD_TAG_ARTIST, 0);
			const char *album = mpd_song_get_tag(song, MPD_TAG_ALBUM, 0);
			unsigned int elapsed_time = mpd_status_get_elapsed_time(mpd_status);
			unsigned int total_time = mpd_status_get_total_time(mpd_status);
			int song_pos = mpd_status_get_song_pos(mpd_status) + 1;
			int volume = mpd_status_get_volume(mpd_status);

			/* Build tuple using this information */
			if (title)
			{
				nulls[0] = false;
				values[0] =  CStringGetTextDatum(title);
			}
			else
				nulls[0] = true;
			if (artist)
			{
				nulls[1] = false;
				values[1] =  CStringGetTextDatum(artist);
			}
			else
				nulls[1] = true;
			if (album)
			{
				nulls[2] = false;
				values[2] =  CStringGetTextDatum(album);
			}
			else
				nulls[2] = true;
			nulls[3] = false;
			values[3] = UInt32GetDatum(elapsed_time);
			nulls[4] = false;
			values[4] = UInt32GetDatum(total_time);
			nulls[5] = false;
			values[5] = Int32GetDatum(song_pos);
			nulls[6] = false;
			values[6] = Int32GetDatum(volume);

			/* Song data is no more needed */
			mpd_song_free(song);
		}

		if (!mpd_response_finish(mpd_conn))
			pgmpc_print_error();
	}

	/* Cleanup MPD status */
	pgmpc_reset();

	/* Form result and return it */
	tuple = heap_form_tuple(tupdesc, values, nulls);
	result = HeapTupleGetDatum(tuple);

	PG_RETURN_DATUM(result);
}
Esempio n. 26
0
File: command.c Progetto: daaang/mpc
int
cmd_seek(gcc_unused int argc, gcc_unused char **argv,
	 struct mpd_connection *conn)
{
	struct mpd_status *status;
	char * arg = argv[0];

	int seekchange;
	int total_secs;
	int rel = 0;

	status = getStatus(conn);

	if (mpd_status_get_state(status) == MPD_STATE_STOP)
		DIE("not currently playing\n");

	/* Detect +/- if exists point to the next char */
	if (*arg == '+')
		rel = 1;
	else if (*arg == '-')
		rel = -1;

	if (rel != 0)
		++arg;

	/* If seeking by percent */
	if (arg[strlen(arg) - 1] == '%') {
		/* Remove the % */
		arg[strlen(arg) - 1] = '\0';

		/* percent seek, strtod is needed for percent with decimals */
		char *test;
		double perc = strtod(arg,&test);
		if (*test != '\0' || (rel == 0 && (perc < 0 || perc > 100)) ||
		    (rel && perc > abs(100)))
			DIE("\"%s\" is not an number between 0 and 100\n", arg);

		seekchange = perc * mpd_status_get_total_time(status) / 100 + 0.5;

	} else { /* If seeking by absolute seek time */

		if (strchr(arg, ':') != NULL) {
			int hr = 0;
			int min = 0;
			int sec = 0;

			/* Take the seconds off the end of arg */
			char *sec_ptr = strrchr(arg, ':');

			/* Remove ':' and move the pointer one byte up */
			*sec_ptr = '\0';
			++sec_ptr;

			/* If hour is in the argument, else just point to the arg */
			char *min_ptr = strrchr(arg, ':');
			if (min_ptr != NULL) {

				/* Remove ':' and move the pointer one byte up */
				*min_ptr = '\0';
				++min_ptr;

				/* If the argument still exists, it's the hour  */
				if (arg != NULL) {
					char *hr_ptr = arg;
					char *test;
					hr = strtol(hr_ptr, &test, 10);

					if (*test != '\0' ||
					    (rel == 0 && hr < 0))
						DIE("\"%s\" is not a positive number\n", sec_ptr);
				}
			} else {
				min_ptr = arg;
			}

			/* Change the pointers to a integer  */
			char *test;
			sec = strtol(sec_ptr, &test, 10);

			if (*test != '\0' || (rel == 0 && sec < 0))
				DIE("\"%s\" is not a positive number\n", sec_ptr);

			min = strtol( min_ptr, &test, 10 );

			if( *test != '\0' || (rel == 0 && min < 0 ))
				DIE("\"%s\" is not a positive number\n", min_ptr);

			/* If mins exist, check secs. If hrs exist, check mins  */
			if (min && strlen(sec_ptr) != 2)
				DIE("\"%s\" is not two digits\n", sec_ptr);
			else if (hr && strlen(min_ptr) != 2)
				DIE("\"%s\" is not two digits\n", min_ptr);

			/* Finally, make sure they're not above 60 if higher unit exists */
			if (min && sec > 60)
				DIE("\"%s\" is greater than 60\n", sec_ptr);
			else if (hr && min > 60 )
				DIE("\"%s\" is greater than 60\n", min_ptr);

			total_secs = (hr * 3600) + (min * 60) + sec;

		} else {

			/* absolute seek (in seconds) */
			char *test;
			total_secs = strtol(arg, &test, 10); /* get the # of seconds */

			if (*test != '\0' || (rel == 0 && total_secs < 0))
				DIE("\"%s\" is not a positive number\n", arg);
		}

		seekchange = total_secs;
	}

	/* This detects +/- and is necessary due to the parsing of HH:MM:SS numbers*/
	int seekto;
	if (rel == 1)
		seekto = mpd_status_get_elapsed_time(status) + seekchange;
	else if (rel == -1)
		seekto = mpd_status_get_elapsed_time(status) - seekchange;
	else
		seekto = seekchange;

	if (seekto > (int)mpd_status_get_total_time(status))
		DIE("Seek amount would seek past the end of the song\n");

	if (!mpd_run_seek_id(conn, mpd_status_get_song_id(status), seekto))
		printErrorAndExit(conn);

	mpd_status_free(status);
	return 1;
}