Beispiel #1
0
/**
 * @param mi A #MpdObj
 * @param path an Path to a file
 *
 * Grabs the song info for a single file. Make sure you pass an url to a song
 * and not a directory, that might result in strange behauviour.
 *
 * @returns a #mpd_Song
 */
mpd_Song * mpd_database_get_fileinfo(MpdObj *mi,const char *path)
{
	mpd_Song *song = NULL;
	mpd_InfoEntity *ent = NULL;
	/*
	 * Check path for availibility and length
	 */
	if(path == NULL || path[0] == '\0')
	{
		debug_printf(DEBUG_ERROR, "path == NULL || strlen(path) == 0");
		return NULL;
	}
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_ERROR, "Not Connected\n");
		return NULL;
	}
	/* lock, so we can work on mi->connection */
	if(mpd_lock_conn(mi) != MPD_OK)
	{
		debug_printf(DEBUG_ERROR, "Failed to lock connection");
		return NULL;
	}
	/* send the request */
	mpd_sendListallInfoCommand(mi->connection, path);
	/* get the first (and only) result */
	ent = mpd_getNextInfoEntity(mi->connection);
	/* finish and clean up libmpdclient */
	mpd_finishCommand(mi->connection);
	/* unlock again */
	if(mpd_unlock_conn(mi))
	{
		if(ent) mpd_freeInfoEntity(ent);
		debug_printf(DEBUG_ERROR, "Failed to unlock");
		return NULL;
	}

	if(ent == NULL)
	{
		debug_printf(DEBUG_ERROR, "Failed to grab song from mpd\n");
		return NULL;
	}

	if(ent->type != MPD_INFO_ENTITY_TYPE_SONG)
	{
		mpd_freeInfoEntity(ent);
		debug_printf(DEBUG_ERROR, "Failed to grab correct song type from mpd, path might not be a file\n");
		return NULL;
	}
	/* get the song */
	song = ent->info.song;
	/* remove reference to song from the entity */
	ent->info.song = NULL;
	/* free the entity */
	mpd_freeInfoEntity(ent);

	return song;
}
Beispiel #2
0
/******************** Song ingo retrival ************************************/
static int  getSong(void) {
	mpd_Status *status;
	mpd_InfoEntity *info;

	/* Get status */
	mpd_sendStatusCommand(D.conn);
	if (error()) return 0;
	status = mpd_getStatus(D.conn);
	if (error()) return 0;
	pdie_on(!status, "get status");

	mpd_nextListOkCommand(D.conn);
	if (error()) {
		mpd_freeStatus(status);
		return 0;
	}

	/* Copy status */
	D.cur.state  = status->state;
	D.cur.songid = status->songid;
	D.cur.pos    = status->elapsedTime;
	D.cur.len    = status->totalTime;
	mpd_freeStatus(status);

	/* Same song, return */
	if (D.cur.songid == D.old.songid) {
		return 1;
	}

	if (D.info) {
		mpd_freeInfoEntity(D.info);
		D.info = 0;
	}

	/* Get song */
	mpd_sendCurrentSongCommand(D.conn);
	if (error()) {
		return 0;
	}
	info = mpd_getNextInfoEntity(D.conn);
	if (error()) {
		return 0;
	}

	if (!info) {
		return
			D.cur.state == MPD_STATUS_STATE_PLAY ||
			D.cur.state == MPD_STATUS_STATE_PAUSE;
	}

	if (info->type != MPD_INFO_ENTITY_TYPE_SONG) {
		mpd_freeInfoEntity(info);
		return 0;
	}

	D.info = info;
	return 1;
}
Beispiel #3
0
/*
=================
MPD_Status - show info about currently playing song
=================
*/
void MPD_Status(void)
{
	mpd_Status		*status;
	mpd_InfoEntity	*entity = NULL;
	mpd_Song		*song = 0;
	char			title[MP3_MAXSONGTITLE];


	if(!MP3_Status())
		return;

	mpd_sendStatusCommand(conn);

	if( (status = mpd_getStatus(conn)) == NULL)
	{
		Com_Printf("MPD: %s\n", conn->errorStr);
		mpd_finishCommand(conn);
		return;
	}
	mpd_finishCommand(conn);

	if( status->state == MPD_STATUS_STATE_STOP) {
		/* Playback stopped */
		Com_Printf("MPD: not playing\n");
		mpd_freeStatus(status);
		return;
	}

	if( status->state == MPD_STATUS_STATE_PLAY || MPD_STATUS_STATE_PAUSE )
	{
		mpd_sendCurrentSongCommand(conn);
		while((entity = mpd_getNextInfoEntity(conn)))
		{
			if(entity->type != MPD_INFO_ENTITY_TYPE_SONG)
			{
				mpd_freeInfoEntity(entity);
				continue;
			}

			song = entity->info.song;
			if(song->title == NULL || song->artist == NULL)
				Com_sprintf(title, sizeof(title), "%s [%i:%02i]", (song->title) ? song->title : song->file, status->totalTime / 60, status->totalTime % 60);
			else
				Com_sprintf(title, sizeof(title), "%s - %s [%i:%02i]", song->artist, song->title, status->totalTime / 60, status->totalTime % 60);

			COM_MakePrintable(title);
			Com_Printf("%s\n", title);

			mpd_freeInfoEntity(entity);
			break;
		}
		mpd_finishCommand(conn);
	}

	mpd_freeStatus(status);
}
Beispiel #4
0
void mpdGetSongTitle()
{
	mpd_InfoEntity * entity;

	mpd_sendCommandListOkBegin(conn);
	mpd_sendStatusCommand(conn);
	mpd_sendCurrentSongCommand(conn);
	mpd_sendCommandListEnd(conn);

		if((status = mpd_getStatus(conn))==NULL) {
			fprintf(stderr,"%s\n",conn->errorStr);
			mpd_closeConnection(conn);
		}
	songname = (char *)malloc(100);
	
		mpd_nextListOkCommand(conn);

		while((entity = mpd_getNextInfoEntity(conn))) {
			mpd_Song * song = entity->info.song;

			if(entity->type!=MPD_INFO_ENTITY_TYPE_SONG) {
				mpd_freeInfoEntity(entity);
				continue;
			}

			if(song->artist) {
				strcpy(songname, " [");
				strcat(songname, song->artist);
				strcat(songname, " - ");
			}
			if(song->album) {
				strcat(songname, song->album);
				strcat(songname, " - ");
			}
			if(song->title) {
				songname = strcat(songname, song->title);
				songname = strcat(songname, "] ");
			}
			mpd_freeInfoEntity(entity);
		}

		if(conn->error) {
			fprintf(stderr,"%s\n",conn->errorStr);
			mpd_closeConnection(conn);
		}

		mpd_finishCommand(conn);
		if(conn->error) {
			fprintf(stderr,"%s\n",conn->errorStr);
			mpd_closeConnection(conn);
		}
	
}
Beispiel #5
0
static int mpdclient_playlist_update(void *data) {
	mpd_Status * status;
	mpd_InfoEntity *entity;
	int i;

	mpd_sendCommandListOkBegin(conn);
	mpd_sendStatusCommand(conn);
	mpd_sendPlChangesCommand(conn, cur_playlist);
	mpd_sendCommandListEnd(conn);

	if((status = mpd_getStatus(conn))==NULL) {
		fprintf(stderr,"%s\n",conn->errorStr);
		mpd_closeConnection(conn);
		return 1;
	}

	cur_playlist = status->playlist;
	cur_song = status->songid;

	mpd_nextListOkCommand(conn);

	evas_event_freeze(evas);

	while((entity = mpd_getNextInfoEntity(conn))) {
		if(entity->type!=MPD_INFO_ENTITY_TYPE_SONG) {
			mpd_freeInfoEntity(entity);
			continue;
		}

		music_song_insert(entity->info.song);

		mpd_freeInfoEntity(entity);
	}

	for (i = status->playlistLength; i < music_song_count(); i++) {
		music_song_remove(i);
	}

	if (status->state == MPD_STATUS_STATE_PLAY ||
			status->state == MPD_STATUS_STATE_PAUSE) {
		music_song_update(status->song, status->totalTime);
	} else {
		music_song_update(-1, 0);
	}

	layout_update(status->state == MPD_STATUS_STATE_PLAY, status->volume);
	evas_event_thaw(evas);

	mpd_finishCommand(conn);
	mpd_freeStatus(status);
	return 1;
}
Beispiel #6
0
static char *MPD_SongTitle ( void )
{
	mpd_Status		*status;
	mpd_InfoEntity	*entity = NULL;
	mpd_Song		*song = 0;
	static char title[MP3_MAXSONGTITLE]; 

	title[0] = 0;

	if(!MP3_Status())
		return title;

	mpd_sendCommandListOkBegin(conn);
	mpd_sendStatusCommand(conn);
	mpd_sendCurrentSongCommand(conn);
	mpd_sendCommandListEnd(conn);

	if( (status = mpd_getStatus(conn)) == NULL)
	{
		return title;
	}

	mpd_nextListOkCommand(conn);

	while((entity = mpd_getNextInfoEntity(conn)))
	{
		if(entity->type != MPD_INFO_ENTITY_TYPE_SONG)
		{
			mpd_freeInfoEntity(entity);
			continue;
		}

		song = entity->info.song;
		if(song->title == NULL || song->artist == NULL)
			Com_sprintf(title, sizeof(title), "%s [%i:%02i]", song->file, status->totalTime / 60, status->totalTime % 60);
		else
			Com_sprintf(title, sizeof(title), "%s - %s [%i:%02i]", song->artist, song->title, status->totalTime / 60, status->totalTime % 60);

		COM_MakePrintable(title);

		mpd_freeInfoEntity(entity);
		break;
	}

	mpd_freeStatus(status);
	mpd_finishCommand(conn);

	return title;
}
Beispiel #7
0
/*******************************************************************************
 * PLAYLIST
 */
mpd_Song * mpd_playlist_get_song(MpdObj *mi, int songid)
{
	mpd_Song *song = NULL;
	mpd_InfoEntity *ent = NULL;
	if(songid < 0){
		debug_printf(DEBUG_ERROR, "songid < 0 Failed");
		return NULL;
	}
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_ERROR, "Not Connected\n");
		return NULL;
	}

	if(mpd_lock_conn(mi))
	{
		return NULL;
	}
	debug_printf(DEBUG_INFO, "Trying to grab song with id: %i\n", songid);
	mpd_sendPlaylistIdCommand(mi->connection, songid);
	ent = mpd_getNextInfoEntity(mi->connection);
	mpd_finishCommand(mi->connection);

	if(mpd_unlock_conn(mi))
	{
		if(ent) mpd_freeInfoEntity(ent);
		return NULL;
	}

	if(ent == NULL)
	{
		debug_printf(DEBUG_ERROR, "Failed to grab song from mpd\n");
		return NULL;
	}

	if(ent->type != MPD_INFO_ENTITY_TYPE_SONG)
	{
		mpd_freeInfoEntity(ent);
		debug_printf(DEBUG_ERROR, "Failed to grab correct song type from mpd\n");
		return NULL;
	}
	song = ent->info.song;
	ent->info.song = NULL;

	mpd_freeInfoEntity(ent);

	return song;
}
int
cmd_playlist(mpd_unused int argc, mpd_unused char **argv, mpd_Connection *conn)
{
	mpd_InfoEntity * entity;
	mpd_Status * status;
	int count = 0;

	mpd_sendStatusCommand(conn);
	printErrorAndExit(conn);
	status = mpd_getStatus(conn);
	printErrorAndExit(conn);
	mpd_finishCommand(conn);
	mpd_sendPlaylistInfoCommand(conn,-1);
	printErrorAndExit(conn);

	while((entity = mpd_getNextInfoEntity(conn))) {
		if(entity->type==MPD_INFO_ENTITY_TYPE_SONG) {
			struct mpd_song *song = entity->info.song;

			printf("%s%i) ", (status->song == count)?">":" ", 1+count);
			pretty_print_song(song);
			printf("\n");

			count++;
		}
		mpd_freeInfoEntity(entity);
	}

	my_finishCommand(conn);
	mpd_freeStatus(status);

	return 0;
}
int cmd_tab ( int argc, char ** argv, mpd_Connection * conn )
{
	mpd_InfoEntity * entity;
	struct mpd_song *song;

	mpd_sendListallCommand(conn,"");
	printErrorAndExit(conn);

	while((entity = mpd_getNextInfoEntity(conn))) {
		if(entity->type==MPD_INFO_ENTITY_TYPE_SONG) {
			song = entity->info.song;
			if(argc==1) {
				if(strncmp(song->file,argv[0],
							strlen(argv[0]))==0) {
					printf("%s\n",
					       charset_from_utf8(song->file));
				}
			} else
				printf("%s\n", charset_from_utf8(song->file));
		}
		mpd_freeInfoEntity(entity);
	}

	my_finishCommand(conn);
	return 0;
}
int cmd_ls ( int argc, char ** argv, mpd_Connection * conn )
{
	mpd_InfoEntity * entity;
	const char *ls;
	int i = 0;

	if (argc > 0)
		ls = charset_to_utf8(argv[i]);
	else
		ls = strdup("");

	do {
		mpd_sendLsInfoCommand(conn,ls);
		printErrorAndExit(conn);

		while((entity = mpd_getNextInfoEntity(conn))) {
			if(entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY) {
				mpd_Directory * dir = entity->info.directory;
				printf("%s\n", charset_from_utf8(dir->path));
			}
			else if(entity->type==MPD_INFO_ENTITY_TYPE_SONG) {
				struct mpd_song *song = entity->info.song;
				printf("%s\n", charset_from_utf8(song->file));
			}
			mpd_freeInfoEntity(entity);
		}

		my_finishCommand(conn);

	} while (++i < argc && (ls = charset_to_utf8(argv[i])) != NULL);

	return 0;
}
int cmd_lsplaylists ( int argc, char ** argv, mpd_Connection * conn )
{
	mpd_InfoEntity * entity;
	const char * ls = "";
	int i = 0;

	if(argc>0) ls = charset_to_utf8(argv[i]);

	do {
		mpd_sendLsInfoCommand(conn,ls);
		printErrorAndExit(conn);

		while((entity = mpd_getNextInfoEntity(conn))) {
			if(entity->type==
					MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) {
				mpd_PlaylistFile * pl = entity->info.playlistFile;
				printf("%s\n", charset_from_utf8(pl->path));
			}
			mpd_freeInfoEntity(entity);
		}

		my_finishCommand(conn);

	} while (++i < argc && (ls = charset_to_utf8(argv[i])) != NULL);
	return 0;
}
int cmd_lstab ( int argc, char ** argv, mpd_Connection * conn )
{
	mpd_InfoEntity * entity;
	mpd_Directory * dir;

	mpd_sendListallCommand(conn,"");
	printErrorAndExit(conn);

	while((entity = mpd_getNextInfoEntity(conn))) {
		if(entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY) {
			dir = entity->info.directory;
			if(argc==1) {
				if(strncmp(dir->path,argv[0],
							strlen(argv[0]))==0) {
					printf("%s\n",
					       charset_from_utf8(dir->path));
				}
			}
		}
		mpd_freeInfoEntity(entity);
	}

	my_finishCommand(conn);

	return 0;
}
int cmd_loadtab ( int argc, char ** argv, mpd_Connection * conn )
{
	mpd_InfoEntity * entity;
	char * sp;
	mpd_PlaylistFile * pl;

	mpd_sendLsInfoCommand(conn,"");
	printErrorAndExit(conn);

	while((entity = mpd_getNextInfoEntity(conn))) {
		if(entity->type==MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) {
			pl = entity->info.playlistFile;
			sp = pl->path;
			while((sp = strchr(sp,' '))) *sp = '_';
			if(argc==1) {
				if(strncmp(pl->path,argv[0],
							strlen(argv[0]))==0) {
					printf("%s\n",
					       charset_from_utf8(pl->path));
				}
			}
		}
		mpd_freeInfoEntity(entity);
	}

	my_finishCommand(conn);
	return 0;
}
int cmd_current(mpd_unused int argc, mpd_unused char ** argv, mpd_Connection *conn)
{
	mpd_Status * status;
	mpd_InfoEntity * entity;

	mpd_sendCommandListOkBegin(conn);
	printErrorAndExit(conn);
	mpd_sendStatusCommand(conn);
	printErrorAndExit(conn);
	mpd_sendCurrentSongCommand(conn);
	printErrorAndExit(conn);
	mpd_sendCommandListEnd(conn);
	printErrorAndExit(conn);

	status = mpd_getStatus(conn);
	printErrorAndExit(conn);

	if (status->state == MPD_STATUS_STATE_PLAY ||
	    status->state == MPD_STATUS_STATE_PAUSE) {
		mpd_nextListOkCommand(conn);
		printErrorAndExit(conn);

		while((entity = mpd_getNextInfoEntity(conn))) {
			struct mpd_song *song = entity->info.song;

			if(entity->type!=MPD_INFO_ENTITY_TYPE_SONG) {
				mpd_freeInfoEntity(entity);
				continue;
			}

			pretty_print_song(song);
			printf("\n");

			mpd_freeInfoEntity(entity);

			break;
		}

		printErrorAndExit(conn);

		mpd_finishCommand(conn);
		printErrorAndExit(conn);
	}
	mpd_freeStatus(status);

	return 0;
}
Beispiel #15
0
MpdData *mpd_database_get_playlist_content(MpdObj *mi,char *playlist)
{
	MpdData *data = NULL;
	mpd_InfoEntity *ent = NULL;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return NULL;
	}
	if(!mpd_server_check_version(mi, 0,12,0))
	{
		debug_printf(DEBUG_WARNING, "only works with mpd higher then 0.12.0");
		return NULL;
	}
	if(mpd_server_check_command_allowed(mi, "listplaylistinfo") != MPD_SERVER_COMMAND_ALLOWED)
	{
		debug_printf(DEBUG_WARNING, "Listing playlist content not supported or allowed");
		return NULL;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_WARNING,"lock failed\n");
		return NULL;
	}
	mpd_sendListPlaylistInfoCommand(mi->connection, playlist);
	while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
	{
		data = mpd_new_data_struct_append( data );
		if(ent->type == MPD_INFO_ENTITY_TYPE_DIRECTORY)
		{
			data->type = MPD_DATA_TYPE_DIRECTORY;
			data->directory = ent->info.directory->path;
			ent->info.directory->path = NULL;
		}
		else if (ent->type == MPD_INFO_ENTITY_TYPE_SONG)
		{
			data->type = MPD_DATA_TYPE_SONG;
			data->song = ent->info.song;
			ent->info.song = NULL;
		}
		else if (ent->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE)
		{
			data->type = MPD_DATA_TYPE_PLAYLIST;
			data->playlist = ent->info.playlistFile->path;
			ent->info.playlistFile->path = NULL;
		}

		mpd_freeInfoEntity(ent);
	}
	mpd_finishCommand(mi->connection);

	/* unlock */
	mpd_unlock_conn(mi);
	if(data == NULL)
	{
		return NULL;
	}
	return mpd_data_get_first(data);
}
Beispiel #16
0
MpdData * mpd_database_get_directory(MpdObj *mi,char *path)
{
	MpdData *data = NULL;
	mpd_InfoEntity *ent = NULL;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return NULL;
	}
	if(path == NULL)
	{
		path = "/";
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_WARNING,"lock failed\n");
		return NULL;
	}

	mpd_sendLsInfoCommand(mi->connection,path);
	while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
	{
		data = mpd_new_data_struct_append(data);
		if(ent->type == MPD_INFO_ENTITY_TYPE_DIRECTORY)
		{
			data->type = MPD_DATA_TYPE_DIRECTORY;
			data->directory = ent->info.directory->path;
			ent->info.directory->path = NULL;
		}
		else if (ent->type == MPD_INFO_ENTITY_TYPE_SONG)
		{
			data->type = MPD_DATA_TYPE_SONG;
			data->song = ent->info.song;
			ent->info.song = NULL;
		}
		else if (ent->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE)
		{
			data->type = MPD_DATA_TYPE_PLAYLIST;
			data->playlist = ent->info.playlistFile->path;
			ent->info.playlistFile->path = NULL;
		}

		mpd_freeInfoEntity(ent);
	}
	mpd_finishCommand(mi->connection);

	/* unlock */
	mpd_unlock_conn(mi);
	if(data == NULL)
	{
		return NULL;
	}
	return mpd_data_get_first(data);
}
Beispiel #17
0
MpdData * mpd_playlist_get_changes_posid(MpdObj *mi,int old_playlist_id)
{
	MpdData *data = NULL;
	mpd_InfoEntity *ent = NULL;
	debug_printf(DEBUG_INFO, "Fetching using new plchangesposid command");
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return NULL;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_WARNING,"lock failed\n");
		return NULL;
	}

	if(old_playlist_id == -1)
	{
		debug_printf(DEBUG_INFO,"get fresh playlist\n");
		mpd_sendPlChangesPosIdCommand (mi->connection, 0);
/*		mpd_sendPlaylistIdCommand(mi->connection, -1); */
	}
	else
	{
		mpd_sendPlChangesPosIdCommand (mi->connection, old_playlist_id);
	}

	while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
	{
		if(ent->type == MPD_INFO_ENTITY_TYPE_SONG)
		{
			data = mpd_new_data_struct_append(data);
			data->type = MPD_DATA_TYPE_SONG;
			data->song = ent->info.song;
			ent->info.song = NULL;
		}
		mpd_freeInfoEntity(ent);
	}
	mpd_finishCommand(mi->connection);

	/* unlock */
	if(mpd_unlock_conn(mi))
	{
		debug_printf(DEBUG_WARNING,"mpd_playlist_get_changes: unlock failed.\n");
		mpd_data_free(data);
		return NULL;
	}
	if(data == NULL)
	{
		return NULL;
	}
	return mpd_data_get_first(data);
}
Beispiel #18
0
static void disconnectFromMPD(void) {
	if (D.conn) {
		mpd_closeConnection(D.conn);
		D.conn = 0;
	}
	if (D.info) {
		mpd_freeInfoEntity(D.info);
		D.info = 0;
	}
	D.cur.songid = -1;
	D.old.songid = -1;
}
Beispiel #19
0
MpdData * mpd_playlist_search_commit(MpdObj *mi)
{
	mpd_InfoEntity *ent = NULL;
	MpdData *data = NULL;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return NULL;
	}
	if(mi->search_type < MPD_SEARCH_TYPE_PLAYLIST_FIND )
	{
		debug_printf(DEBUG_ERROR, "no or wrong search in progress to commit");
		return NULL;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"lock failed\n");
		return NULL;
	}
	mpd_commitSearch(mi->connection);
	while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
	{
		if(ent->type == MPD_INFO_ENTITY_TYPE_SONG)
		{
			data = mpd_new_data_struct_append(data);
			data->type = MPD_DATA_TYPE_SONG;
			data->song = ent->info.song;
			ent->info.song = NULL;
		}
		mpd_freeInfoEntity(ent);
	}
	mpd_finishCommand(mi->connection);
	/*
	 * reset search type
	 */
	mi->search_type = MPD_SEARCH_TYPE_NONE;
	mi->search_field = MPD_TAG_ITEM_ARTIST;
	/* unlock */
	if(mpd_unlock_conn(mi))
	{
		debug_printf(DEBUG_ERROR, "Failed to unlock connection");
		if(data)mpd_data_free(data);
		return NULL;
	}
	if(data == NULL)
	{
		return NULL;
	}
	return mpd_data_get_first(data);
}
Beispiel #20
0
MpdData * mpd_playlist_get_song_from_pos_range(MpdObj *mi, int start, int stop)
{
    MpdData *data = NULL;
    int i;
	mpd_InfoEntity *ent = NULL;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_ERROR, "Not Connected\n");
		return NULL;
	}
	if(mpd_status_check(mi) != MPD_OK)
	{
		debug_printf(DEBUG_ERROR,"Failed grabbing status\n");
		return NULL;
	}

	if(mpd_lock_conn(mi))
	{
		return NULL;
	}
    /* Don't check outside playlist length */
    if(!(stop < mi->status->playlistLength)) {
        stop = mi->status->playlistLength -1;
    }
    mpd_sendCommandListBegin(mi->connection);
    for(i=start; i <= stop; i++){
        mpd_sendPlaylistInfoCommand(mi->connection, i);
    }
	mpd_sendCommandListEnd(mi->connection);
	while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
	{
		if(ent->type == MPD_INFO_ENTITY_TYPE_SONG)
		{
			data = mpd_new_data_struct_append(data);
			data->type = MPD_DATA_TYPE_SONG;
			data->song = ent->info.song;
			ent->info.song = NULL;
		}
		mpd_freeInfoEntity(ent);
	}
	mpd_finishCommand(mi->connection);

	if(mpd_unlock_conn(mi))
	{
		/*TODO free entity. for now this can never happen */
		return NULL;
	}
    return data;
}
Beispiel #21
0
int main(int argc, char ** argv) {
	char *string;
	mpd_Connection * conn;
	conn = mpd_newConnection("192.150.0.108",6600,10);

	if(conn->error) {
		fprintf(stderr,"%s\n",conn->errorStr);
		mpd_closeConnection(conn);
		return -1;
	}
	int i=0;
//	for(i=0;i<1000;i++)
//	{
/*/	
	mpd_sendCommandsCommand(conn);
	while (( string = mpd_getNextCommand(conn)) != NULL)
	{
		//printf("%s\n", string);
		free(string);
	}
	mpd_finishCommand(conn);
    */
//	}
//
//
//
//



    
    for(i=0;i<100;i++)
    {
        mpd_sendPlChangesCommand(conn,0); 
        mpd_InfoEntity *ent = NULL;
        while((ent = mpd_getNextInfoEntity(conn)) != NULL){
//            		printf("%s\n", ent->info.song->artist);
            mpd_freeInfoEntity(ent);
        }
    }
	mpd_closeConnection(conn);

	return 0;
}
MPDEntities MPDConnection::entities() const {
	ASSERT;
	MPDEntities ret;

	for (mpd_InfoEntity *entity; (entity = mpd_getNextInfoEntity(d->connection)) != NULL; ) {
		if (entity->type == MPD_INFO_ENTITY_TYPE_SONG) {
			ret.appendSong(MPDSong(entity));
		} else if (entity->type == MPD_INFO_ENTITY_TYPE_DIRECTORY) {
			ret.appendDirectory(QString::fromUtf8(entity->info.directory->path));
		} else if (entity->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) {
			ret.appendPlaylist(MPDSong(entity));
		} else {
			qWarning("MPDConnection::availableEntities() Unknown entity type: %d", entity->type);
		}
		mpd_freeInfoEntity(entity);
	}

	return ret;
}
int cmd_load ( int argc, char ** argv, mpd_Connection * conn )
{
	int i;
	char * sp;
	char * dp;
	mpd_InfoEntity * entity;
	mpd_PlaylistFile * pl;

	for(i=0;i<argc;i++) {
		sp = argv[i];
		while((sp = strchr(sp,' '))) *sp = '_';
	}

	mpd_sendLsInfoCommand(conn,"");
	printErrorAndExit(conn);
	while((entity = mpd_getNextInfoEntity(conn))) {
		if(entity->type==MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) {
			pl = entity->info.playlistFile;
			dp = sp = strdup(charset_from_utf8(pl->path));
			while((sp = strchr(sp,' '))) *sp = '_';
			for(i=0;i<argc;i++) {
				if(strcmp(dp,argv[i])==0)
					strcpy(argv[i], charset_from_utf8(pl->path));
			}
			free(dp);
			mpd_freeInfoEntity(entity);
		}
	}
	my_finishCommand(conn);

	mpd_sendCommandListBegin(conn);
	printErrorAndExit(conn);
	for(i=0;i<argc;i++) {
		printf("loading: %s\n",argv[i]);
		mpd_sendLoadCommand(conn,charset_to_utf8(argv[i]));
		printErrorAndExit(conn);
	}
	mpd_sendCommandListEnd(conn);
	my_finishCommand(conn);

	return 0;
}
Beispiel #24
0
MpdData * mpd_database_get_directory_recursive(MpdObj *mi, const char *path)
{
	MpdData *data = NULL;
	mpd_InfoEntity *ent = NULL;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return NULL;
	}
	if(path == '\0' || path[0] == '\0')
	{
		debug_printf(DEBUG_ERROR, "argumant invalid\n");
		return NULL;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"lock failed\n");
		return NULL;
	}
	mpd_sendListallInfoCommand(mi->connection,path); 
	while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
	{

		if (ent->type == MPD_INFO_ENTITY_TYPE_SONG)
		{
			data = mpd_new_data_struct_append(data);
			data->type = MPD_DATA_TYPE_SONG;
			data->song = ent->info.song;
			ent->info.song = NULL;
		}
		mpd_freeInfoEntity(ent);
	}
	mpd_finishCommand(mi->connection);

	/* unlock */
	mpd_unlock_conn(mi);
	if(data == NULL)
	{
		return NULL;
	}
	return mpd_data_get_first(data);
}
Beispiel #25
0
void MpdClient::updatePlaylist(long long version)
{
	if (version < 0)
		mpd_sendPlChangesCommand(conn, version);
	else
		mpd_sendPlaylistInfoCommand(conn, -1);

	mpd_InfoEntity *entity;
	while ((entity = mpd_getNextInfoEntity(conn))) {
		assert(entity->type == MPD_INFO_ENTITY_TYPE_SONG);

		mpd_Song *song = mpd_songDup(entity->info.song);
		mpd_freeInfoEntity(entity);

		assert(song->pos <= playlist.size());

		if (song->pos == playlist.size())
			playlist += song;
		else {
			mpd_freeSong(playlist[song->pos]);
			playlist[song->pos] = song;
		}

		emit(changedSong(song));
	}

	mpd_finishCommand(conn);

	/* remove extra songs if the playlist was shortened */
	for (int i = playlist.size() - 1; i >= status->playlistLength; i--) {
		mpd_freeSong(playlist[i]);
		playlist.removeAt(i);
		emit(changedSong(NULL));
	}

}
Beispiel #26
0
static void *update_mpd_thread(void *arg)
{
	static mpd_Connection *conn = NULL;
	mpd_Status *status;
	mpd_InfoEntity *entity;
	timed_thread *me = *(timed_thread **)arg;
	const char *emptystr = "";

	while (1) {
		if (!conn)
			conn = mpd_newConnection(mpd_host, mpd_port, 10);

		if (*mpd_password) {
			mpd_sendPasswordCommand(conn, mpd_password);
			mpd_finishCommand(conn);
		}

		timed_thread_lock(me);

		if (conn->error || conn == NULL) {
			NORM_ERR("MPD error: %s\n", conn->errorStr);
			mpd_closeConnection(conn);
			conn = 0;
			clear_mpd();

			mpd_info.status = "MPD not responding";
			timed_thread_unlock(me);
			if (timed_thread_test(me, 0)) {
				timed_thread_exit(me);
			}
			continue;
		}

		mpd_sendStatusCommand(conn);
		if ((status = mpd_getStatus(conn)) == NULL) {
			NORM_ERR("MPD error: %s\n", conn->errorStr);
			mpd_closeConnection(conn);
			conn = 0;
			clear_mpd();

			mpd_info.status = "MPD not responding";
			timed_thread_unlock(me);
			if (timed_thread_test(me, 0)) {
				timed_thread_exit(me);
			}
			continue;
		}
		mpd_finishCommand(conn);
		if (conn->error) {
			// fprintf(stderr, "%s\n", conn->errorStr);
			mpd_closeConnection(conn);
			conn = 0;
			timed_thread_unlock(me);
			if (timed_thread_test(me, 0)) {
				timed_thread_exit(me);
			}
			continue;
		}

		mpd_info.vol = status->volume;
		if (status->random == 0) {
			mpd_info.random = "Off";
		} else if (status->random == 1) {
			mpd_info.random = "On";
		} else {
			mpd_info.random = "";
		}
		if (status->repeat == 0) {
			mpd_info.repeat = "Off";
		} else if (status->repeat == 1) {
			mpd_info.repeat = "On";
		} else {
			mpd_info.repeat = "";
		}
		/* if (status->error) {
			printf("error: %s\n", status->error);
		} */

		switch (status->state) {
			case MPD_STATUS_STATE_PLAY:
				mpd_info.status = "Playing";
				break;
			case MPD_STATUS_STATE_STOP:
				mpd_info.status = "Stopped";
				break;
			case MPD_STATUS_STATE_PAUSE:
				mpd_info.status = "Paused";
				break;
			default:
				mpd_info.status = "";
				clear_mpd();
				break;
		}

		if (status->state == MPD_STATUS_STATE_PLAY ||
		    status->state == MPD_STATUS_STATE_PAUSE) {
			mpd_info.is_playing = 1;
			mpd_info.bitrate = status->bitRate;
			mpd_info.progress = (float) status->elapsedTime /
				status->totalTime;
			mpd_info.elapsed = status->elapsedTime;
			mpd_info.length = status->totalTime;
		} else {
			mpd_info.progress = 0;
			mpd_info.is_playing = 0;
			mpd_info.elapsed = 0;
		}

		if (conn->error) {
			// fprintf(stderr, "%s\n", conn->errorStr);
			mpd_closeConnection(conn);
			conn = 0;
			timed_thread_unlock(me);
			if (timed_thread_test(me, 0)) {
				timed_thread_exit(me);
			}
			continue;
		}

		mpd_sendCurrentSongCommand(conn);
		while ((entity = mpd_getNextInfoEntity(conn))) {
			mpd_Song *song = entity->info.song;

			if (entity->type != MPD_INFO_ENTITY_TYPE_SONG) {
				mpd_freeInfoEntity(entity);
				continue;
			}
#define SONGSET(x) {                            \
	free(mpd_info.x);                       \
	if(song->x)                             \
		mpd_info.x = strmdup(song->x);  \
	else                                    \
		mpd_info.x = strmdup(emptystr); \
}
			SONGSET(artist);
			SONGSET(albumartist);
			SONGSET(album);
			SONGSET(title);
			SONGSET(date);
			SONGSET(track);
			SONGSET(name);
			SONGSET(file);
#undef SONGSET
			if (entity != NULL) {
				mpd_freeInfoEntity(entity);
				entity = NULL;
			}
		}
		mpd_finishCommand(conn);
		if (conn->error) {
			// fprintf(stderr, "%s\n", conn->errorStr);
			mpd_closeConnection(conn);
			conn = 0;
			timed_thread_unlock(me);
			if (timed_thread_test(me, 0)) {
				timed_thread_exit(me);
			}
			continue;
		}

		timed_thread_unlock(me);
		if (conn->error) {
			// fprintf(stderr, "%s\n", conn->errorStr);
			mpd_closeConnection(conn);
			conn = 0;
			if (timed_thread_test(me, 0)) {
				timed_thread_exit(me);
			}
			continue;
		}

		mpd_freeStatus(status);
		/* if (conn) {
			mpd_closeConnection(conn);
			conn = 0;
		} */
		if (timed_thread_test(me, 0)) {
			timed_thread_exit(me);
		}
		continue;
	}
	/* never reached */
}
Beispiel #27
0
/* should be called mpd_database_find */
MpdData * mpd_database_find(MpdObj *mi, int table, char *string, int exact)
{
	MpdData *data = NULL;
/*	MpdData *artist = NULL;
	MpdData *album = NULL;
*/	mpd_InfoEntity *ent = NULL;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return NULL;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_WARNING,"lock failed\n");
		return NULL;
	}
	if(exact)
	{
		mpd_sendFindCommand(mi->connection,table,string);
	}
	else
	{
		mpd_sendSearchCommand(mi->connection, table,string);
	}
	while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
	{
		data = mpd_new_data_struct_append(data);
		/* mpd_sendSearch|Find only returns songs */
		/*
		if(ent->type == MPD_INFO_ENTITY_TYPE_DIRECTORY)
		{
			data->type = MPD_DATA_TYPE_DIRECTORY;
			data->directory = ent->info.directory->path;
			ent->info.directory->path = NULL;
		}
		else*/ if (ent->type == MPD_INFO_ENTITY_TYPE_SONG)
		{
			data->type = MPD_DATA_TYPE_SONG;
			data->song = ent->info.song;
			ent->info.song = NULL;
			/* This is something the client can and should do */
/*			if(data->song->artist != NULL)
			{
				int found = FALSE;
				if(artist != NULL)
				{
					MpdData *fartist = mpd_data_get_first(artist);
					do{
						if( (fartist->type == MPD_DATA_TYPE_TAG) && (fartist->tag_type == MPD_TAG_ITEM_ARTIST))
						{
							if(fartist->tag == NULL)
							{
								printf("crap this should'nt be \n");
							}
							if(!strcmp(fartist->tag, data->song->artist))
							{
								found = TRUE;
							}
						}
						fartist = mpd_data_get_next_real(fartist, FALSE);
					}while(fartist && !found);
				}
				if(!found)
				{
					artist= mpd_new_data_struct_append(artist);
					artist->type = MPD_DATA_TYPE_TAG;
					artist->tag_type = MPD_TAG_ITEM_ARTIST;
					artist->tag = strdup(data->song->artist);
				}
			}
			if(data->song->album != NULL)
			{
				int found = FALSE;
				if(album != NULL)
				{
					MpdData *falbum = mpd_data_get_first(album);
					do{
						if( (falbum->type == MPD_DATA_TYPE_TAG) && (falbum->tag_type == MPD_TAG_ITEM_ALBUM))
						{
							if(falbum->tag == NULL)
							{
								printf("crap this should'nt be \n");
							}
							if(!strcmp(falbum->tag, data->song->album))
							{
								found = TRUE;
							}
						}
						falbum = mpd_data_get_next_real(falbum, FALSE);
					}while(falbum && !found);
				}
				if(!found)
				{
					album = mpd_new_data_struct_append(album);
					album->type = MPD_DATA_TYPE_TAG;
					album->tag_type = MPD_TAG_ITEM_ALBUM;
					album->tag = strdup(data->song->album);
				}
			}
*/
		}
		/*
		else if (ent->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE)
		{
			data->type = MPD_DATA_TYPE_PLAYLIST;
			data->playlist = ent->info.playlistFile->path;
			ent->info.playlistFile->path = NULL;
		}
		*/

		mpd_freeInfoEntity(ent);
	}
	mpd_finishCommand(mi->connection);

	/* unlock */
	mpd_unlock_conn(mi);
	if(data == NULL)
	{
		return NULL;
	}
	data = mpd_data_get_first(data);
	/* prepend the album then artists*/
/*	if(album != NULL)
	{
		if(data){
			data  = mpd_data_concatenate( album, data);
		}else{
			data = album;
		}
	}
	if(artist != NULL)
	{
		if(data) {
			album = mpd_data_concatenate( artist, data );
		}else{
			data = artist;
		}
	}                                                     	
*/
	return mpd_data_get_first(data);
}
static void
_mpdule_update_song (Instance * inst)
{
  mpd_Connection *mpd;
  Evas_Object *mpdule;
  Evas_Object *o_popup;

  if (!inst->mpd)
    return;
  mpd = inst->mpd;
  mpdule = inst->mpdule;
  o_popup = inst->o_popup;
  mpd_sendStatusCommand (mpd);
  if (mpd->error == 0)
    {
      mpd_Status *status = mpd_getStatus (mpd);

      if (status)
	{
	  if (status->state == MPD_STATUS_STATE_UNKNOWN)
	    {
	      edje_object_part_text_set (mpdule, "mpdule.status",
					 D_ ("Unknown"));
	      edje_object_part_text_set (o_popup, "mpdule.status",
					 D_ ("Unknown"));
	    }
	  else if (status->state == MPD_STATUS_STATE_STOP)
	    {
	      edje_object_part_text_set (mpdule, "mpdule.status",
					 D_ ("Stopped"));
	      edje_object_part_text_set (o_popup, "mpdule.status",
					 D_ ("Stopped"));
	    }
	  else if (status->state == MPD_STATUS_STATE_PLAY)
	    {
	      edje_object_part_text_set (mpdule, "mpdule.status",
					 D_ ("Playing"));
	      edje_object_part_text_set (o_popup, "mpdule.status",
					 D_ ("Playing"));
	    }
	  else if (status->state == MPD_STATUS_STATE_PAUSE)
	    {
	      edje_object_part_text_set (mpdule, "mpdule.status",
					 D_ ("Paused"));
	      edje_object_part_text_set (o_popup, "mpdule.status",
					 D_ ("Paused"));
	    }

	  if (status->state > MPD_STATUS_STATE_STOP)
	    {
	      mpd_sendCurrentSongCommand (mpd);
	      mpd_InfoEntity *entity = NULL;

	      while ((entity = mpd_getNextInfoEntity (mpd)))
		{
		  if (entity->type == MPD_INFO_ENTITY_TYPE_SONG &&
		      entity->info.song->id == status->songid)
		    {
		      mpd_Song *song = entity->info.song;

		      if (song->artist)
			{
			  edje_object_part_text_set (mpdule, "mpdule.artist",
						     song->artist);
			  edje_object_part_text_set (o_popup, "mpdule.artist",
						     song->artist);
			}
		      else
			{
			  edje_object_part_text_set (mpdule, "mpdule.artist",
						     "");
			  edje_object_part_text_set (o_popup, "mpdule.artist",
						     "");
			}
		      if (song->title)
			{
			  edje_object_part_text_set (mpdule, "mpdule.title",
						     song->title);
			  edje_object_part_text_set (o_popup, "mpdule.title",
						     song->title);
			}
		      else
			{
			  edje_object_part_text_set (mpdule, "mpdule.title",
						     "");
			  edje_object_part_text_set (o_popup, "mpdule.title",
						     "");
			}
		      if (song->album)
			{
			  edje_object_part_text_set (mpdule, "mpdule.album",
						     song->album);
			  edje_object_part_text_set (o_popup, "mpdule.album",
						     song->album);
			}
		      else
			{
			  edje_object_part_text_set (mpdule, "mpdule.album",
						     "");
			  edje_object_part_text_set (o_popup, "mpdule.album",
						     "");
			}
		      if (song->track)
			{
			  edje_object_part_text_set (mpdule, "mpdule.track",
						     song->track);
			  edje_object_part_text_set (o_popup, "mpdule.track",
						     song->track);
			}
		      else
			{
			  edje_object_part_text_set (mpdule, "mpdule.track",
						     "");
			  edje_object_part_text_set (o_popup, "mpdule.track",
						     "");
			}
		      if (song->date)
			{
			  edje_object_part_text_set (mpdule, "mpdule.date",
						     song->date);
			  edje_object_part_text_set (o_popup, "mpdule.date",
						     song->date);
			}
		      else
			{
			  edje_object_part_text_set (mpdule, "mpdule.date",
						     "");
			  edje_object_part_text_set (o_popup, "mpdule.date",
						     "");
			}
		      if (song->genre)
			{
			  edje_object_part_text_set (mpdule, "mpdule.genre",
						     song->genre);
			  edje_object_part_text_set (o_popup, "mpdule.genre",
						     song->genre);
			}
		      else
			{
			  edje_object_part_text_set (mpdule, "mpdule.genre",
						     "");
			  edje_object_part_text_set (o_popup, "mpdule.genre",
						     "");
			}
		      if (song->composer)
			{
			  edje_object_part_text_set (mpdule,
						     "mpdule.composer",
						     song->composer);
			  edje_object_part_text_set (o_popup,
						     "mpdule.composer",
						     song->composer);
			}
		      else
			{
			  edje_object_part_text_set (mpdule,
						     "mpdule.composer", "");
			  edje_object_part_text_set (o_popup,
						     "mpdule.composer", "");
			}
		      if (song->time)
			{
			  //char * songtime;
			  //sprintf(songtime, "%i", song->time);
			  //edje_object_part_text_set (mpdule, "mpdule.time", songtime);
			  //edje_object_part_text_set (o_popup, "mpdule.time", songtime);
			}
		      else
			{
			  edje_object_part_text_set (mpdule, "mpdule.time",
						     "");
			  edje_object_part_text_set (o_popup, "mpdule.time",
						     "");
			}
		      if (song->file)
			{
			  edje_object_part_text_set (mpdule, "mpdule.file",
						     song->file);
			  edje_object_part_text_set (o_popup, "mpdule.file",
						     song->file);
			}
		      else
			{
			  edje_object_part_text_set (mpdule, "mpdule.file",
						     "");
			  edje_object_part_text_set (o_popup, "mpdule.file",
						     "");
			}
		    }

		  mpd_freeInfoEntity (entity);
		}
	    }

	  mpd_freeStatus (status);
	}
    }
  else
    {
      _mpdule_disconnect (inst);
      _mpdule_connect (inst);
    }
}
Beispiel #29
0
MpdData *mpd_database_token_find(MpdObj *mi , char *string)
{
	MpdData *data = NULL;
	mpd_InfoEntity *ent = NULL;
	regex_t ** strdata = NULL;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_WARNING,"not connected\n");
		return NULL;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"lock failed\n");
		return NULL;
	}

	if(string == NULL || !strlen(string) )
	{
		debug_printf(DEBUG_INFO, "no string found");
		mpd_unlock_conn(mi);
		return NULL;
	}
	else{
		strdata = mpd_misc_tokenize(string);
	}
	if(strdata == NULL)
	{
		mpd_unlock_conn(mi);
		debug_printf(DEBUG_INFO, "no split string found");
		return NULL;
	}

	mpd_sendListallInfoCommand(mi->connection, "/");
	while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL)
	{
		if (ent->type == MPD_INFO_ENTITY_TYPE_SONG)
		{
			int i = 0;
			int match = 0;
			int loop = 1;
			for(i=0; strdata[i] != NULL && loop; i++)
			{
				match = 0;
				if(ent->info.song->file && !regexec(strdata[i],ent->info.song->file, 0, NULL, 0))
				{
					match = 1;
				}
				else if(ent->info.song->artist && !regexec(strdata[i],ent->info.song->artist, 0, NULL, 0))
				{
					match = 1;
				}
				else if(ent->info.song->title && !regexec(strdata[i],ent->info.song->title, 0, NULL, 0)) 
				{
					match = 1;
				}
				else if(ent->info.song->album && !regexec(strdata[i],ent->info.song->album, 0, NULL, 0))
				{
					match = 1;
				}
				if(!match)
				{
					loop = 0;
				}
			}

			if(match)
			{
				data = mpd_new_data_struct_append(data);
				data->type = MPD_DATA_TYPE_SONG;
				/*
				data->song = mpd_songDup(ent->info.song);
				*/
				data->song = ent->info.song;
				ent->info.song = NULL;
			}
		}
		mpd_freeInfoEntity(ent);
	}
	mpd_finishCommand(mi->connection);
	mpd_misc_tokens_free(strdata);




	mpd_unlock_conn(mi);
	if(data == NULL)
	{
		return NULL;
	}
	return mpd_data_get_first(data);
}