Mercurial > mplayer.hg
annotate libmpdemux/cddb.c @ 7192:f771e685f3b1
Zr documentation updated plus some typos fixed.
Patch by rsnel@cube.dyndns.org.
author | diego |
---|---|
date | Sat, 31 Aug 2002 13:10:29 +0000 |
parents | 4cade272ce2b |
children | a5f1baaf7714 |
rev | line source |
---|---|
6474 | 1 /* |
2 * CDDB HTTP protocol | |
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com> | |
4 * (C) 2002, MPlayer team. | |
5 * | |
6 * Implementation follow the freedb.howto1.06.txt specification | |
7 * from http://freedb.freedb.org | |
8 * | |
9 * discid computation by Jeremy D. Zawodny | |
10 * Copyright (c) 1998-2000 Jeremy D. Zawodny <Jeremy@Zawodny.com> | |
11 * Code release under GPL | |
12 * | |
13 */ | |
14 | |
15 #include "config.h" | |
16 | |
17 #if defined(HAVE_CDDA) && defined(STREAMING) | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <fcntl.h> | |
22 #include <stdarg.h> | |
23 #include <errno.h> | |
24 #include <netdb.h> | |
25 #include <unistd.h> | |
26 #include <string.h> | |
27 #include <sys/ioctl.h> | |
28 #include <sys/types.h> | |
29 #include <sys/stat.h> | |
30 | |
31 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__bsdi__) | |
32 #define SYS_BSD 1 | |
33 #endif | |
34 | |
35 #if defined(__linux__) | |
36 #include <linux/cdrom.h> | |
37 #elif defined(SYS_BSD) | |
38 #include <sys/cdio.h> | |
39 #endif | |
40 | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
41 #include "cdd.h" |
6474 | 42 #include "../version.h" |
43 #include "stream.h" | |
44 #include "network.h" | |
45 | |
46 #define DEFAULT_FREEDB_SERVER "freedb.freedb.org" | |
47 #define DEFAULT_CACHE_DIR "/.cddb/" | |
48 | |
49 stream_t* open_cdda(char *dev, char *track); | |
50 | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
51 static cd_toc_t cdtoc[100]; |
6474 | 52 |
53 #if defined(__linux__) | |
54 int | |
55 read_toc(void) { | |
56 int drive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK); | |
57 struct cdrom_tochdr tochdr; | |
58 struct cdrom_tocentry tocentry; | |
59 int i; | |
60 | |
61 ioctl(drive, CDROMREADTOCHDR, &tochdr); | |
62 for (i = tochdr.cdth_trk0; i <= tochdr.cdth_trk1; i++) { | |
63 tocentry.cdte_track = i; | |
64 tocentry.cdte_format = CDROM_MSF; | |
65 ioctl(drive, CDROMREADTOCENTRY, &tocentry); | |
66 cdtoc[i-1].min = tocentry.cdte_addr.msf.minute; | |
67 cdtoc[i-1].sec = tocentry.cdte_addr.msf.second; | |
68 cdtoc[i-1].frame = tocentry.cdte_addr.msf.frame; | |
69 cdtoc[i-1].frame += cdtoc[i-1].min*60*75; | |
70 cdtoc[i-1].frame += cdtoc[i-1].sec*75; | |
71 } | |
72 tocentry.cdte_track = 0xAA; | |
73 tocentry.cdte_format = CDROM_MSF; | |
74 ioctl(drive, CDROMREADTOCENTRY, &tocentry); | |
75 cdtoc[tochdr.cdth_trk1].min = tocentry.cdte_addr.msf.minute; | |
76 cdtoc[tochdr.cdth_trk1].sec = tocentry.cdte_addr.msf.second; | |
77 cdtoc[tochdr.cdth_trk1].frame = tocentry.cdte_addr.msf.frame; | |
78 cdtoc[tochdr.cdth_trk1].frame += cdtoc[tochdr.cdth_trk1].min*60*75; | |
79 cdtoc[tochdr.cdth_trk1].frame += cdtoc[tochdr.cdth_trk1].sec*75; | |
80 close(drive); | |
81 return tochdr.cdth_trk1; | |
82 } | |
83 | |
84 #elif defined(SYS_BSD) | |
85 int | |
86 read_toc(void) { | |
87 int drive = open("/dev/acd0c", O_RDONLY | O_NONBLOCK); | |
88 struct ioc_toc_header tochdr; | |
89 struct ioc_read_toc_single_entry tocentry; | |
90 int i; | |
91 | |
92 ioctl(drive, CDIOREADTOCHEADER, &tochdr); | |
93 for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) { | |
94 tocentry.track = i; | |
95 tocentry.address_format = CD_MSF_FORMAT; | |
96 ioctl(drive, CDIOREADTOCENTRY, &tocentry); | |
97 cdtoc[i-1].min = tocentry.entry.addr.msf.minute; | |
98 cdtoc[i-1].sec = tocentry.entry.addr.msf.second; | |
99 cdtoc[i-1].frame = tocentry.entry.addr.msf.frame; | |
100 cdtoc[i-1].frame += cdtoc[i-1].min*60*75; | |
101 cdtoc[i-1].frame += cdtoc[i-1].sec*75; | |
102 } | |
103 tocentry.track = 0xAA; | |
104 tocentry.address_format = CD_MSF_FORMAT; | |
105 ioctl(drive, CDIOREADTOCENTRY, &tocentry); | |
106 cdtoc[tochdr.ending_track].min = tocentry.entry.addr.msf.minute; | |
107 cdtoc[tochdr.ending_track].sec = tocentry.entry.addr.msf.second; | |
108 cdtoc[tochdr.ending_track].frame = tocentry.entry.addr.msf.frame; | |
109 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].min*60*75; | |
110 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].sec*75; | |
111 close(drive); | |
112 return tochdr.ending_track; | |
113 } | |
114 #endif | |
115 | |
116 unsigned int | |
117 cddb_sum(int n) { | |
118 unsigned int ret; | |
119 | |
120 ret = 0; | |
121 while (n > 0) { | |
122 ret += (n % 10); | |
123 n /= 10; | |
124 } | |
125 return ret; | |
126 } | |
127 | |
128 unsigned long | |
129 cddb_discid(int tot_trks) { | |
130 unsigned int i, t = 0, n = 0; | |
131 | |
132 i = 0; | |
133 while (i < tot_trks) { | |
134 n = n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec); | |
135 i++; | |
136 } | |
137 t = ((cdtoc[tot_trks].min * 60) + cdtoc[tot_trks].sec) - | |
138 ((cdtoc[0].min * 60) + cdtoc[0].sec); | |
139 return ((n % 0xff) << 24 | t << 8 | tot_trks); | |
140 } | |
141 | |
142 | |
143 | |
144 int | |
145 cddb_http_request(char *command, int (*reply_parser)(HTTP_header_t*,cddb_data_t*), cddb_data_t *cddb_data) { | |
146 char request[4096]; | |
147 int fd, ret = 0; | |
148 URL_t *url; | |
149 HTTP_header_t *http_hdr; | |
150 | |
151 if( reply_parser==NULL || command==NULL || cddb_data==NULL ) return -1; | |
152 | |
153 sprintf( request, "http://%s/~cddb/cddb.cgi?cmd=%s%s&proto=%d", cddb_data->freedb_server, command, cddb_data->cddb_hello, cddb_data->freedb_proto_level ); | |
154 printf("Request[%s]\n", request ); | |
155 | |
156 url = url_new(request); | |
157 if( url==NULL ) { | |
158 printf("Not a valid URL\n"); | |
159 return -1; | |
160 } | |
161 | |
162 fd = http_send_request(url); | |
163 if( fd<0 ) { | |
164 printf("failed to send the http request\n"); | |
165 return -1; | |
166 } | |
167 | |
168 http_hdr = http_read_response( fd ); | |
169 if( http_hdr==NULL ) { | |
170 printf("Failed to read the http response\n"); | |
171 return -1; | |
172 } | |
173 | |
174 http_debug_hdr(http_hdr); | |
175 printf("body=[%s]\n", http_hdr->body ); | |
176 | |
177 switch(http_hdr->status_code) { | |
178 case 200: | |
179 ret = reply_parser(http_hdr, cddb_data); | |
180 break; | |
181 case 400: | |
182 printf("Not Found\n"); | |
183 break; | |
184 default: | |
185 printf("Unknown Error code\n"); | |
186 } | |
187 | |
188 http_free( http_hdr ); | |
189 url_free( url ); | |
190 | |
191 return ret; | |
192 } | |
193 | |
194 int | |
195 cddb_read_cache(cddb_data_t *cddb_data) { | |
196 char file_name[100]; | |
197 struct stat stats; | |
198 int file_fd, ret; | |
199 size_t file_size; | |
200 | |
201 if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1; | |
202 | |
203 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id); | |
204 | |
205 file_fd = open(file_name, O_RDONLY); | |
206 if( file_fd<0 ) { | |
207 printf("No cache found\n"); | |
208 return -1; | |
209 } | |
210 | |
211 ret = fstat( file_fd, &stats ); | |
212 if( ret<0 ) { | |
213 perror("fstat"); | |
214 file_size = 4096; | |
215 } else { | |
216 file_size = stats.st_size; | |
217 } | |
218 | |
219 cddb_data->xmcd_file = (char*)malloc(file_size); | |
220 if( cddb_data->xmcd_file==NULL ) { | |
221 printf("Memory allocation failed\n"); | |
222 close(file_fd); | |
223 return -1; | |
224 } | |
225 cddb_data->xmcd_file_size = read(file_fd, cddb_data->xmcd_file, file_size); | |
226 if( cddb_data->xmcd_file_size!=file_size ) { | |
227 printf("Not all the xmcd file has been read\n"); | |
228 close(file_fd); | |
229 return -1; | |
230 } | |
231 | |
232 close(file_fd); | |
233 | |
234 return 0; | |
235 } | |
236 | |
237 int | |
238 cddb_write_cache(cddb_data_t *cddb_data) { | |
239 // We have the file, save it for cache. | |
240 char file_name[100]; | |
241 int file_fd; | |
242 size_t wrote=0; | |
243 | |
244 if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1; | |
245 | |
246 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id); | |
247 | |
248 file_fd = creat(file_name, S_IREAD|S_IWRITE); | |
249 if( file_fd<0 ) { | |
250 perror("open"); | |
251 return -1; | |
252 } | |
253 | |
254 wrote = write(file_fd, cddb_data->xmcd_file, cddb_data->xmcd_file_size); | |
255 if( wrote<0 ) { | |
256 perror("write"); | |
257 close(file_fd); | |
258 return -1; | |
259 } | |
260 if( wrote!=cddb_data->xmcd_file_size ) { | |
261 printf("Not all the xmcd file has been written\n"); | |
262 close(file_fd); | |
263 return -1; | |
264 } | |
265 | |
266 close(file_fd); | |
267 | |
268 return 0; | |
269 } | |
270 | |
271 int | |
272 cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { | |
273 unsigned long disc_id; | |
274 char category[100]; | |
275 char *ptr=NULL, *ptr2=NULL; | |
276 int ret, status; | |
277 | |
278 if( http_hdr==NULL || cddb_data==NULL ) return -1; | |
279 | |
280 ret = sscanf( http_hdr->body, "%d ", &status); | |
281 if( ret!=1 ) { | |
282 printf("Parse error\n"); | |
283 return -1; | |
284 } | |
285 | |
286 switch(status) { | |
287 case 210: | |
288 ret = sscanf( http_hdr->body, "%d %s %08lx", &status, category, &disc_id); | |
289 if( ret!=3 ) { | |
290 printf("Parse error\n"); | |
291 return -1; | |
292 } | |
293 // Check if it's a xmcd database file | |
294 ptr = strstr(http_hdr->body, "# xmcd"); | |
295 if( ptr==NULL ) { | |
296 printf("Invalid xmcd database file returned\n"); | |
297 return -1; | |
298 } | |
299 // Ok found the beginning of the file | |
300 // look for the end | |
301 ptr2 = strstr(ptr, "\r\n.\r\n"); | |
302 if( ptr2==NULL ) { | |
303 ptr2 = strstr(ptr, "\n.\n"); | |
304 if( ptr2==NULL ) { | |
305 printf("Unable to find '.'\n"); | |
306 return -1; | |
307 } | |
308 } | |
309 // Ok found the end | |
310 // do a sanity check | |
311 if( http_hdr->body_size<(ptr2-ptr) ) { | |
312 printf("Unexpected fix me\n"); | |
313 return -1; | |
314 } | |
315 cddb_data->xmcd_file = ptr; | |
316 cddb_data->xmcd_file_size = ptr2-ptr+2; | |
317 cddb_data->xmcd_file[cddb_data->xmcd_file_size] = '\0'; | |
318 // Avoid the http_free function to free the xmcd file...save a mempcy... | |
319 http_hdr->body = NULL; | |
320 http_hdr->body_size = 0; | |
321 return cddb_write_cache(cddb_data); | |
322 default: | |
323 printf("Unhandled code\n"); | |
324 } | |
325 return 0; | |
326 } | |
327 | |
328 int | |
329 cddb_request_titles(cddb_data_t *cddb_data) { | |
330 char command[1024]; | |
331 sprintf( command, "cddb+read+%s+%08lx", cddb_data->category, cddb_data->disc_id); | |
332 return cddb_http_request(command, cddb_read_parse, cddb_data); | |
333 } | |
334 | |
335 int | |
336 cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { | |
337 char album_title[100]; | |
338 char *ptr = NULL; | |
339 int ret, status; | |
340 | |
341 ret = sscanf( http_hdr->body, "%d ", &status); | |
342 if( ret!=1 ) { | |
343 printf("Parse error\n"); | |
344 return -1; | |
345 } | |
346 | |
347 switch(status) { | |
348 case 200: | |
349 // Found exact match | |
350 ret = sscanf(http_hdr->body, "%d %s %08lx %s", &status, cddb_data->category, &(cddb_data->disc_id), album_title); | |
351 if( ret!=4 ) { | |
352 printf("Parse error\n"); | |
353 return -1; | |
354 } | |
355 ptr = strstr(http_hdr->body, album_title); | |
356 if( ptr!=NULL ) { | |
357 char *ptr2; | |
358 int len; | |
359 ptr2 = strstr(ptr, "\n"); | |
360 if( ptr2==NULL ) { | |
361 len = (http_hdr->body_size)-(ptr-(http_hdr->body)); | |
362 } else { | |
363 len = ptr2-ptr+1; | |
364 } | |
365 strncpy(album_title, ptr, len); | |
366 album_title[len-2]='\0'; | |
367 } | |
368 printf("Parse OK, found: %s\n", album_title); | |
369 return cddb_request_titles(cddb_data); | |
370 case 202: | |
371 // No match found | |
372 printf("Album not found\n"); | |
373 break; | |
374 case 210: | |
375 // Found exact matches, list follows | |
376 ptr = strstr(http_hdr->body, "\n"); | |
377 if( ptr==NULL ) { | |
378 printf("Unable to find end of line\n"); | |
379 return -1; | |
380 } | |
381 ptr++; | |
382 // We have a list of exact matches, so which one do | |
383 // we use? So let's take the first one. | |
384 ret = sscanf(ptr, "%s %08lx %s", cddb_data->category, &(cddb_data->disc_id), album_title); | |
385 if( ret!=3 ) { | |
386 printf("Parse error\n"); | |
387 return -1; | |
388 } | |
389 ptr = strstr(http_hdr->body, album_title); | |
390 if( ptr!=NULL ) { | |
391 char *ptr2; | |
392 int len; | |
393 ptr2 = strstr(ptr, "\n"); | |
394 if( ptr2==NULL ) { | |
395 len = (http_hdr->body_size)-(ptr-(http_hdr->body)); | |
396 } else { | |
397 len = ptr2-ptr+1; | |
398 } | |
399 strncpy(album_title, ptr, len); | |
400 album_title[len-2]='\0'; | |
401 } | |
402 printf("Parse OK, found: %s\n", album_title); | |
403 return cddb_request_titles(cddb_data); | |
404 /* | |
405 body=[210 Found exact matches, list follows (until terminating `.') | |
406 misc c711930d Santana / Supernatural | |
407 rock c711930d Santana / Supernatural | |
408 blues c711930d Santana / Supernatural | |
409 .] | |
410 */ | |
411 case 211: | |
412 // Found inexact matches, list follows | |
413 printf("No exact matches found, list follows\n"); | |
414 break; | |
415 default: | |
416 printf("Unhandled code\n"); | |
417 } | |
418 return -1; | |
419 } | |
420 | |
421 int | |
422 cddb_proto_level_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { | |
423 int max; | |
424 int ret, status; | |
425 char *ptr; | |
426 | |
427 ret = sscanf( http_hdr->body, "%d ", &status); | |
428 if( ret!=1 ) { | |
429 printf("Parse error\n"); | |
430 return -1; | |
431 } | |
432 | |
433 switch(status) { | |
434 case 210: | |
435 ptr = strstr(http_hdr->body, "max proto:"); | |
436 if( ptr==NULL ) { | |
437 printf("Parse error\n"); | |
438 return -1; | |
439 } | |
440 ret = sscanf(ptr, "max proto: %d", &max); | |
441 if( ret!=1 ) { | |
442 printf("Parse error\n"); | |
443 return -1; | |
444 } | |
445 cddb_data->freedb_proto_level = max; | |
446 return 0; | |
447 default: | |
448 printf("Unhandled code\n"); | |
449 } | |
450 return -1; | |
451 } | |
452 | |
453 int | |
454 cddb_get_proto_level(cddb_data_t *cddb_data) { | |
455 return cddb_http_request("stat", cddb_proto_level_parse, cddb_data); | |
456 } | |
457 | |
458 int | |
459 cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { | |
460 int ret, status; | |
461 | |
462 ret = sscanf( http_hdr->body, "%d ", &status); | |
463 if( ret!=1 ) { | |
464 printf("Parse error\n"); | |
465 return -1; | |
466 } | |
467 | |
468 switch(status) { | |
469 case 210: | |
470 // Parse the sites | |
471 return 0; | |
472 case 401: | |
473 printf("No sites information available\n"); | |
474 break; | |
475 default: | |
476 printf("Unhandled code\n"); | |
477 } | |
478 return -1; | |
479 } | |
480 | |
481 int | |
482 cddb_get_freedb_sites(cddb_data_t *cddb_data) { | |
483 return cddb_http_request("sites", cddb_freedb_sites_parse, cddb_data); | |
484 } | |
485 | |
486 void | |
487 cddb_create_hello(cddb_data_t *cddb_data) { | |
488 char host_name[51]; | |
489 char *user_name; | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
490 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
491 if( cddb_data->anonymous ) { // Default is anonymous |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
492 /* Note from Eduardo Pérez Ureta <eperez@it.uc3m.es> : |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
493 * We don't send current user/host name in hello to prevent spam. |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
494 * Software that sends this is considered spyware |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
495 * that most people don't like. |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
496 */ |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
497 user_name = "anonymous"; |
6474 | 498 strcpy(host_name, "localhost"); |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
499 } else { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
500 if( gethostname(host_name, 50)<0 ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
501 strcpy(host_name, "localhost"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
502 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
503 user_name = getenv("LOGNAME"); |
6474 | 504 } |
505 sprintf( cddb_data->cddb_hello, "&hello=%s+%s+%s+%s", user_name, host_name, "MPlayer", VERSION ); | |
506 } | |
507 | |
508 int | |
509 cddb_retrieve(cddb_data_t *cddb_data) { | |
510 char offsets[1024], command[1024]; | |
511 char *ptr; | |
512 int i, time_len; | |
513 | |
514 ptr = offsets; | |
515 for( i=0; i<cddb_data->tracks ; i++ ) { | |
516 ptr += sprintf(ptr, "%d+", cdtoc[i].frame ); | |
517 } | |
518 time_len = (cdtoc[cddb_data->tracks].frame)/75; | |
519 | |
520 cddb_data->freedb_server = DEFAULT_FREEDB_SERVER; | |
521 cddb_data->freedb_proto_level = 1; | |
522 cddb_data->xmcd_file = NULL; | |
523 | |
524 cddb_create_hello(cddb_data); | |
6475
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
525 if( cddb_get_proto_level(cddb_data)<0 ) { |
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
526 printf("Failed to get the protocol level\n"); |
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
527 return -1; |
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
528 } |
6474 | 529 |
530 //cddb_get_freedb_sites(&cddb_data); | |
531 | |
532 sprintf(command, "cddb+query+%08lx+%d+%s%d", cddb_data->disc_id, cddb_data->tracks, offsets, time_len ); | |
533 i = cddb_http_request(command, cddb_query_parse, cddb_data); | |
534 if( i<0 ) return -1; | |
535 | |
536 if( cddb_data->cache_dir!=NULL ) { | |
537 free(cddb_data->cache_dir); | |
538 } | |
539 return 0; | |
540 } | |
541 | |
542 int | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
543 cddb_resolve(char **xmcd_file) { |
6474 | 544 char cddb_cache_dir[] = DEFAULT_CACHE_DIR; |
545 char *home_dir = NULL; | |
546 cddb_data_t cddb_data; | |
547 | |
548 cddb_data.tracks = read_toc(); | |
549 cddb_data.disc_id = cddb_discid(cddb_data.tracks); | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
550 cddb_data.anonymous = 1; // Don't send user info by default |
6474 | 551 |
552 home_dir = getenv("HOME"); | |
553 if( home_dir==NULL ) { | |
554 cddb_data.cache_dir = NULL; | |
555 } else { | |
556 cddb_data.cache_dir = (char*)malloc(strlen(home_dir)+strlen(cddb_cache_dir)+1); | |
557 if( cddb_data.cache_dir==NULL ) { | |
558 printf("Memory allocation failed\n"); | |
559 return -1; | |
560 } | |
561 sprintf(cddb_data.cache_dir, "%s%s", home_dir, cddb_cache_dir ); | |
562 } | |
563 | |
564 // Check for a cached file | |
565 if( cddb_read_cache(&cddb_data)<0 ) { | |
566 // No Cache found | |
567 if( cddb_retrieve(&cddb_data)<0 ) { | |
568 return -1; | |
569 } | |
570 } | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
571 |
6474 | 572 if( cddb_data.xmcd_file!=NULL ) { |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
573 // printf("%s\n", cddb_data.xmcd_file ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
574 *xmcd_file = cddb_data.xmcd_file; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
575 return 0; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
576 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
577 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
578 return -1; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
579 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
580 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
581 /******************************************************************************************************************* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
582 * |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
583 * xmcd parser, cd info list |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
584 * |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
585 *******************************************************************************************************************/ |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
586 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
587 cd_info_t* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
588 cd_info_new() { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
589 cd_info_t *cd_info = NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
590 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
591 cd_info = (cd_info_t*)malloc(sizeof(cd_info_t)); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
592 if( cd_info==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
593 printf("Memory allocation failed\n"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
594 return NULL; |
6474 | 595 } |
596 | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
597 memset(cd_info, 0, sizeof(cd_info_t)); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
598 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
599 return cd_info; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
600 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
601 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
602 void |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
603 cd_info_free(cd_info_t *cd_info) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
604 cd_track_t *cd_track, *cd_track_next; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
605 int i; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
606 if( cd_info==NULL ) return; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
607 if( cd_info->artist!=NULL ) free(cd_info->artist); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
608 if( cd_info->album!=NULL ) free(cd_info->album); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
609 if( cd_info->genre!=NULL ) free(cd_info->genre); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
610 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
611 cd_track_next = cd_info->first; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
612 while( cd_track_next!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
613 cd_track = cd_track_next; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
614 cd_track_next = cd_track->next; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
615 if( cd_track->name!=NULL ) free(cd_track->name); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
616 free(cd_track); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
617 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
618 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
619 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
620 cd_track_t* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
621 cd_info_add_track(cd_info_t *cd_info, char *track_name, unsigned int track_nb, unsigned int min, unsigned int sec, unsigned int msec, unsigned long frame_begin, unsigned long frame_length) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
622 cd_track_t *cd_track, current_track; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
623 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
624 if( cd_info==NULL || track_name==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
625 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
626 cd_track = (cd_track_t*)malloc(sizeof(cd_track_t)); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
627 if( cd_track==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
628 printf("Memory allocation failed\n"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
629 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
630 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
631 memset(cd_track, 0, sizeof(cd_track_t)); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
632 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
633 cd_track->name = (char*)malloc(strlen(track_name)+1); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
634 if( cd_track->name==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
635 printf("Memory allocation failed\n"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
636 free(cd_track); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
637 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
638 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
639 strcpy(cd_track->name, track_name); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
640 cd_track->track_nb = track_nb; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
641 cd_track->min = min; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
642 cd_track->sec = sec; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
643 cd_track->msec = msec; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
644 cd_track->frame_begin = frame_begin; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
645 cd_track->frame_length = frame_length; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
646 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
647 if( cd_info->first==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
648 cd_info->first = cd_track; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
649 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
650 if( cd_info->last!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
651 cd_info->last->next = cd_track; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
652 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
653 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
654 cd_track->prev = cd_info->last; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
655 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
656 cd_info->last = cd_track; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
657 cd_info->current = cd_track; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
658 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
659 cd_info->nb_tracks++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
660 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
661 return cd_track; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
662 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
663 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
664 cd_track_t* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
665 cd_info_get_track(cd_info_t *cd_info, unsigned int track_nb) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
666 cd_track_t *cd_track=NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
667 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
668 if( cd_info==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
669 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
670 cd_track = cd_info->first; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
671 while( cd_track!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
672 if( cd_track->track_nb==track_nb ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
673 return cd_track; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
674 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
675 cd_track = cd_track->next; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
676 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
677 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
678 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
679 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
680 void |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
681 cd_info_debug(cd_info_t *cd_info) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
682 cd_track_t *current_track; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
683 printf("================ CD INFO === start =========\n"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
684 if( cd_info==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
685 printf("cd_info is NULL\n"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
686 return; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
687 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
688 printf(" artist=[%s]\n", cd_info->artist); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
689 printf(" album=[%s]\n", cd_info->album); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
690 printf(" genre=[%s]\n", cd_info->genre); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
691 printf(" nb_tracks=%d\n", cd_info->nb_tracks); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
692 printf(" length= %2d:%02d.%02d\n", cd_info->min, cd_info->sec, cd_info->msec); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
693 current_track = cd_info->first; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
694 while( current_track!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
695 printf(" #%2d %2d:%02d.%02d @ %7ld\t[%s] \n", current_track->track_nb, current_track->min, current_track->sec, current_track->msec, current_track->frame_begin, current_track->name); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
696 current_track = current_track->next; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
697 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
698 printf("================ CD INFO === end =========\n"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
699 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
700 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
701 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
702 xmcd_parse_dtitle(cd_info_t *cd_info, char *line) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
703 char *ptr, *album; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
704 ptr = strstr(line, "DTITLE="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
705 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
706 ptr += 7; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
707 album = strstr(ptr, "/"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
708 if( album==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
709 cd_info->album = (char*)malloc(strlen(album+2)+1); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
710 if( cd_info->album==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
711 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
712 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
713 strcpy( cd_info->album, album+2 ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
714 album--; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
715 album[0] = '\0'; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
716 cd_info->artist = (char*)malloc(strlen(ptr)+1); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
717 if( cd_info->artist==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
718 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
719 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
720 strcpy( cd_info->artist, ptr ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
721 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
722 return ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
723 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
724 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
725 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
726 xmcd_parse_dgenre(cd_info_t *cd_info, char *line) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
727 char *ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
728 ptr = strstr(line, "DGENRE="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
729 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
730 ptr += 7; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
731 cd_info->genre = (char*)malloc(strlen(ptr)+1); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
732 if( cd_info->genre==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
733 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
734 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
735 strcpy( cd_info->genre, ptr ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
736 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
737 return ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
738 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
739 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
740 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
741 xmcd_parse_ttitle(cd_info_t *cd_info, char *line) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
742 unsigned int track_nb; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
743 unsigned long sec, off; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
744 char *ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
745 ptr = strstr(line, "TTITLE"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
746 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
747 ptr += 6; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
748 // Here we point to the track number |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
749 track_nb = atoi(ptr); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
750 ptr = strstr(ptr, "="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
751 if( ptr==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
752 ptr++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
753 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
754 sec = cdtoc[track_nb].frame; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
755 off = cdtoc[track_nb+1].frame-sec+1; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
756 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
757 cd_info_add_track( cd_info, ptr, track_nb+1, (unsigned int)(off/(60*75)), (unsigned int)((off/75)%60), (unsigned int)(off%75), sec, off ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
758 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
759 return ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
760 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
761 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
762 cd_info_t* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
763 cddb_parse_xmcd(char *xmcd_file) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
764 cd_info_t *cd_info = NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
765 int length, pos = 0; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
766 char *ptr, *ptr2; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
767 unsigned int audiolen; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
768 if( xmcd_file==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
769 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
770 cd_info = cd_info_new(); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
771 if( cd_info==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
772 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
773 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
774 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
775 length = strlen(xmcd_file); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
776 ptr = xmcd_file; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
777 while( ptr!=NULL && pos<length ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
778 // Read a line |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
779 ptr2 = ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
780 while( ptr2[0]!='\0' && ptr2[0]!='\r' && ptr2[0]!='\n' ) ptr2++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
781 if( ptr2[0]=='\0' ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
782 break; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
783 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
784 ptr2[0] = '\0'; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
785 // Ignore comments |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
786 if( ptr[0]!='#' ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
787 // Search for the album title |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
788 if( xmcd_parse_dtitle(cd_info, ptr) ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
789 // Search for the genre |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
790 else if( xmcd_parse_dgenre(cd_info, ptr) ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
791 // Search for a track title |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
792 else if( xmcd_parse_ttitle(cd_info, ptr) ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
793 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
794 if( ptr2[1]=='\n' ) ptr2++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
795 pos = (ptr2+1)-ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
796 ptr = ptr2+1; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
797 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
798 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
799 audiolen = cdtoc[cd_info->nb_tracks].frame-cdtoc[0].frame; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
800 cd_info->min = (unsigned int)(audiolen/(60*75)); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
801 cd_info->sec = (unsigned int)((audiolen/75)%60); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
802 cd_info->msec = (unsigned int)(audiolen%75); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
803 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
804 return cd_info; |
6474 | 805 } |
806 | |
807 stream_t* | |
808 cddb_open(char *dev, char *track) { | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
809 stream_t *stream; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
810 cd_info_t *cd_info = NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
811 cdda_priv *priv; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
812 char *xmcd_file = NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
813 int ret; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
814 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
815 ret = cddb_resolve(&xmcd_file); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
816 if( ret==0 ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
817 cd_info = cddb_parse_xmcd(xmcd_file); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
818 free(xmcd_file); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
819 cd_info_debug( cd_info ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
820 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
821 stream = open_cdda(dev, track); |
6474 | 822 |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
823 priv = ((cdda_priv*)(stream->priv)); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
824 cd_info_debug(priv->cd_info); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
825 if( cd_info!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
826 cd_info_free(priv->cd_info); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
827 priv->cd_info = cd_info; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
828 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
829 return stream; |
6474 | 830 } |
831 #endif |