File: example.c

package info (click to toggle)
mpdscribble 0.2.10-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 716 kB
  • ctags: 500
  • sloc: ansic: 3,904; sh: 3,603; makefile: 70
file content (199 lines) | stat: -rw-r--r-- 4,370 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "libmpdclient.h"

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char ** argv) {
	mpd_Connection * conn;

	conn = mpd_newConnection("localhost",6600,10);

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

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

	if(argc==1) {
		mpd_Status * status;
		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);
			return -1;
		}

		printf("volume: %i\n",status->volume);
		printf("repeat: %i\n",status->repeat);
		printf("playlist: %lli\n",status->playlist);
		printf("playlistLength: %i\n",status->playlistLength);
		if(status->error) printf("error: %s\n",status->error);

		if(status->state == MPD_STATUS_STATE_PLAY || 
				status->state == MPD_STATUS_STATE_PAUSE) {
			printf("song: %i\n",status->song);
			printf("elaspedTime: %i\n",status->elapsedTime);
			printf("totalTime: %i\n",status->totalTime);
			printf("bitRate: %i\n",status->bitRate);
		}

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

		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;
			}

			printf("file: %s\n",song->file);
			if(song->artist) {
				printf("artist: %s\n",song->artist);
			}
			if(song->album) {
				printf("album: %s\n",song->album);
			}
			if(song->title) {
				printf("title: %s\n",song->title);
			}
			if(song->track) {
				printf("track: %s\n",song->track);
			}
			if(song->name) {
				printf("name: %s\n",song->name);
			}
			if(song->time!=MPD_SONG_NO_TIME) {
				printf("time: %i\n",song->time);
			}
			if(song->pos!=MPD_SONG_NO_NUM) {
				printf("pos: %i\n",song->pos);
			}

			mpd_freeInfoEntity(entity);
		}

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

		mpd_finishCommand(conn);
		if(conn->error) {
			fprintf(stderr,"%s\n",conn->errorStr);
			mpd_closeConnection(conn);
			return -1;
		}
	
		mpd_freeStatus(status);
	}
	else if(argc==3 && strcmp(argv[1],"lsinfo")==0) {
		mpd_InfoEntity * entity;

		mpd_sendLsInfoCommand(conn,argv[2]);
		if(conn->error) {
			fprintf(stderr,"%s\n",conn->errorStr);
			mpd_closeConnection(conn);
			return -1;
		}

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

				printf("file: %s\n",song->file);
				if(song->artist) {
					printf("artist: %s\n",song->artist);
				}
				if(song->album) {
					printf("album: %s\n",song->album);
				}
				if(song->title) {
					printf("title: %s\n",song->title);
				}
				if(song->track) {
					printf("track: %s\n",song->track);
				}
			}
			else if(entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY) {
				mpd_Directory * dir = entity->info.directory;
				printf("directory: %s\n",dir->path);
			}
			else if(entity->type==
					MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) {
				mpd_PlaylistFile * pl = 
					entity->info.playlistFile;
				printf("playlist: %s\n",pl->path);
			}

			mpd_freeInfoEntity(entity);
		}

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

		mpd_finishCommand(conn);
		if(conn->error) {
			fprintf(stderr,"%s\n",conn->errorStr);
			mpd_closeConnection(conn);
			return -1;
		}
	}
	else if(argc==2 && strcmp(argv[1],"artists")==0) {
		char * artist;
	
		mpd_sendListCommand(conn,MPD_TABLE_ARTIST,NULL);
		if(conn->error) {
			fprintf(stderr,"%s\n",conn->errorStr);
			mpd_closeConnection(conn);
			return -1;
		}

		while((artist = mpd_getNextArtist(conn))) {
			printf("%s\n",artist);
			free(artist);
		}

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

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

	mpd_closeConnection(conn);

	return 0;
}