comparison libmpdemux/cddb.c @ 16967:32e2c59c8e86

[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
author reynaldo
date Thu, 10 Nov 2005 21:33:12 +0000
parents 60bd6aeed405
children 6ff3379a0862
comparison
equal deleted inserted replaced
16966:46490266341d 16967:32e2c59c8e86
34 #include <sys/ioctl.h> 34 #include <sys/ioctl.h>
35 #endif 35 #endif
36 #include <sys/types.h> 36 #include <sys/types.h>
37 #include <sys/stat.h> 37 #include <sys/stat.h>
38 38
39 #include "mp_msg.h"
40 #include "help_mp.h"
41
39 #if defined(__linux__) 42 #if defined(__linux__)
40 #include <linux/cdrom.h> 43 #include <linux/cdrom.h>
41 #elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) 44 #elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
42 #include <sys/cdio.h> 45 #include <sys/cdio.h>
43 #elif defined(WIN32) 46 #elif defined(WIN32)
104 107
105 sprintf(device, "\\\\.\\%s", dev); 108 sprintf(device, "\\\\.\\%s", dev);
106 drive = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); 109 drive = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
107 110
108 if(!DeviceIoControl(drive, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(CDROM_TOC), &r, 0)) { 111 if(!DeviceIoControl(drive, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(CDROM_TOC), &r, 0)) {
109 mp_msg(MSGT_OPEN, MSGL_ERR, "Failed to read TOC.\n"); 112 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToReadTOC);
110 return 0; 113 return 0;
111 } 114 }
112 115
113 for (i = toc.FirstTrack; i <= toc.LastTrack; i++) { 116 for (i = toc.FirstTrack; i <= toc.LastTrack; i++) {
114 toc.FirstTrack = i; 117 toc.FirstTrack = i;
218 if (identify) 221 if (identify)
219 { 222 {
220 int i, min, sec, frame; 223 int i, min, sec, frame;
221 cdtoc_last_track = read_toc(dev); 224 cdtoc_last_track = read_toc(dev);
222 if (cdtoc_last_track < 0) { 225 if (cdtoc_last_track < 0) {
223 mp_msg(MSGT_OPEN, MSGL_ERR, "Failed to open %s device.\n", dev); 226 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice, dev);
224 return -1; 227 return -1;
225 } 228 }
226 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_CDDA_TRACKS=%d\n", cdtoc_last_track); 229 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_CDDA_TRACKS=%d\n", cdtoc_last_track);
227 for (i = 1; i <= cdtoc_last_track; i++) 230 for (i = 1; i <= cdtoc_last_track; i++)
228 { 231 {
277 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 ); 280 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 );
278 printf("Request[%s]\n", request ); 281 printf("Request[%s]\n", request );
279 282
280 url = url_new(request); 283 url = url_new(request);
281 if( url==NULL ) { 284 if( url==NULL ) {
282 printf("Not a valid URL\n"); 285 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NotAValidURL);
283 return -1; 286 return -1;
284 } 287 }
285 288
286 fd = http_send_request(url,0); 289 fd = http_send_request(url,0);
287 if( fd<0 ) { 290 if( fd<0 ) {
288 printf("failed to send the http request\n"); 291 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToSendHTTPRequest);
289 return -1; 292 return -1;
290 } 293 }
291 294
292 http_hdr = http_read_response( fd ); 295 http_hdr = http_read_response( fd );
293 if( http_hdr==NULL ) { 296 if( http_hdr==NULL ) {
294 printf("Failed to read the http response\n"); 297 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToReadHTTPResponse);
295 return -1; 298 return -1;
296 } 299 }
297 300
298 http_debug_hdr(http_hdr); 301 http_debug_hdr(http_hdr);
299 printf("body=[%s]\n", http_hdr->body ); 302 printf("body=[%s]\n", http_hdr->body );
301 switch(http_hdr->status_code) { 304 switch(http_hdr->status_code) {
302 case 200: 305 case 200:
303 ret = reply_parser(http_hdr, cddb_data); 306 ret = reply_parser(http_hdr, cddb_data);
304 break; 307 break;
305 case 400: 308 case 400:
306 printf("Not Found\n"); 309 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_HTTPErrorNOTFOUND);
307 break; 310 break;
308 default: 311 default:
309 printf("Unknown Error code\n"); 312 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_HTTPErrorUnknown);
310 } 313 }
311 314
312 http_free( http_hdr ); 315 http_free( http_hdr );
313 url_free( url ); 316 url_free( url );
314 317
330 #ifdef WIN32 333 #ifdef WIN32
331 | O_BINARY 334 | O_BINARY
332 #endif 335 #endif
333 ); 336 );
334 if( file_fd<0 ) { 337 if( file_fd<0 ) {
335 printf("No cache found\n"); 338 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NoCacheFound);
336 return -1; 339 return -1;
337 } 340 }
338 341
339 ret = fstat( file_fd, &stats ); 342 ret = fstat( file_fd, &stats );
340 if( ret<0 ) { 343 if( ret<0 ) {
344 file_size = stats.st_size; 347 file_size = stats.st_size;
345 } 348 }
346 349
347 cddb_data->xmcd_file = (char*)malloc(file_size); 350 cddb_data->xmcd_file = (char*)malloc(file_size);
348 if( cddb_data->xmcd_file==NULL ) { 351 if( cddb_data->xmcd_file==NULL ) {
349 printf("Memory allocation failed\n"); 352 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed);
350 close(file_fd); 353 close(file_fd);
351 return -1; 354 return -1;
352 } 355 }
353 cddb_data->xmcd_file_size = read(file_fd, cddb_data->xmcd_file, file_size); 356 cddb_data->xmcd_file_size = read(file_fd, cddb_data->xmcd_file, file_size);
354 if( cddb_data->xmcd_file_size!=file_size ) { 357 if( cddb_data->xmcd_file_size!=file_size ) {
355 printf("Not all the xmcd file has been read\n"); 358 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenRead);
356 close(file_fd); 359 close(file_fd);
357 return -1; 360 return -1;
358 } 361 }
359 362
360 close(file_fd); 363 close(file_fd);
381 if( ret<0 && errno != EEXIST ) { 384 if( ret<0 && errno != EEXIST ) {
382 #else 385 #else
383 if( ret<0 ) { 386 if( ret<0 ) {
384 #endif 387 #endif
385 perror("mkdir"); 388 perror("mkdir");
386 printf("Failed to create directory %s\n", cddb_data->cache_dir ); 389 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToCreateDirectory, cddb_data->cache_dir);
387 return -1; 390 return -1;
388 } 391 }
389 } 392 }
390 393
391 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id ); 394 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id );
401 perror("write"); 404 perror("write");
402 close(file_fd); 405 close(file_fd);
403 return -1; 406 return -1;
404 } 407 }
405 if( (unsigned int)wrote!=cddb_data->xmcd_file_size ) { 408 if( (unsigned int)wrote!=cddb_data->xmcd_file_size ) {
406 printf("Not all the xmcd file has been written\n"); 409 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenWritten);
407 close(file_fd); 410 close(file_fd);
408 return -1; 411 return -1;
409 } 412 }
410 413
411 close(file_fd); 414 close(file_fd);
422 425
423 if( http_hdr==NULL || cddb_data==NULL ) return -1; 426 if( http_hdr==NULL || cddb_data==NULL ) return -1;
424 427
425 ret = sscanf( http_hdr->body, "%d ", &status); 428 ret = sscanf( http_hdr->body, "%d ", &status);
426 if( ret!=1 ) { 429 if( ret!=1 ) {
427 printf("Parse error\n"); 430 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
428 return -1; 431 return -1;
429 } 432 }
430 433
431 switch(status) { 434 switch(status) {
432 case 210: 435 case 210:
433 ret = sscanf( http_hdr->body, "%d %s %08lx", &status, category, &disc_id); 436 ret = sscanf( http_hdr->body, "%d %s %08lx", &status, category, &disc_id);
434 if( ret!=3 ) { 437 if( ret!=3 ) {
435 printf("Parse error\n"); 438 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
436 return -1; 439 return -1;
437 } 440 }
438 // Check if it's a xmcd database file 441 // Check if it's a xmcd database file
439 ptr = strstr(http_hdr->body, "# xmcd"); 442 ptr = strstr(http_hdr->body, "# xmcd");
440 if( ptr==NULL ) { 443 if( ptr==NULL ) {
441 printf("Invalid xmcd database file returned\n"); 444 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_InvalidXMCDDatabaseReturned);
442 return -1; 445 return -1;
443 } 446 }
444 // Ok found the beginning of the file 447 // Ok found the beginning of the file
445 // look for the end 448 // look for the end
446 ptr2 = strstr(ptr, "\r\n.\r\n"); 449 ptr2 = strstr(ptr, "\r\n.\r\n");
447 if( ptr2==NULL ) { 450 if( ptr2==NULL ) {
448 ptr2 = strstr(ptr, "\n.\n"); 451 ptr2 = strstr(ptr, "\n.\n");
449 if( ptr2==NULL ) { 452 if( ptr2==NULL ) {
450 printf("Unable to find '.'\n"); 453 mp_msg(MSGT_DEMUX, MSGL_FIXME, "Unable to find '.'\n");
451 ptr2=ptr+strlen(ptr); //return -1; 454 ptr2=ptr+strlen(ptr); //return -1;
452 } 455 }
453 } 456 }
454 // Ok found the end 457 // Ok found the end
455 // do a sanity check 458 // do a sanity check
456 if( http_hdr->body_size<(unsigned int)(ptr2-ptr) ) { 459 if( http_hdr->body_size<(unsigned int)(ptr2-ptr) ) {
457 printf("Unexpected fix me\n"); 460 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_UnexpectedFIXME);
458 return -1; 461 return -1;
459 } 462 }
460 cddb_data->xmcd_file = ptr; 463 cddb_data->xmcd_file = ptr;
461 cddb_data->xmcd_file_size = ptr2-ptr+2; 464 cddb_data->xmcd_file_size = ptr2-ptr+2;
462 cddb_data->xmcd_file[cddb_data->xmcd_file_size] = '\0'; 465 cddb_data->xmcd_file[cddb_data->xmcd_file_size] = '\0';
463 // Avoid the http_free function to free the xmcd file...save a mempcy... 466 // Avoid the http_free function to free the xmcd file...save a mempcy...
464 http_hdr->body = NULL; 467 http_hdr->body = NULL;
465 http_hdr->body_size = 0; 468 http_hdr->body_size = 0;
466 return cddb_write_cache(cddb_data); 469 return cddb_write_cache(cddb_data);
467 default: 470 default:
468 printf("Unhandled code\n"); 471 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode);
469 } 472 }
470 return 0; 473 return 0;
471 } 474 }
472 475
473 int 476 int
483 char *ptr = NULL; 486 char *ptr = NULL;
484 int ret; 487 int ret;
485 488
486 ptr = strstr(http_hdr->body, "\n"); 489 ptr = strstr(http_hdr->body, "\n");
487 if( ptr==NULL ) { 490 if( ptr==NULL ) {
488 printf("Unable to find end of line\n"); 491 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_UnableToFindEOL);
489 return -1; 492 return -1;
490 } 493 }
491 ptr++; 494 ptr++;
492 // We have a list of exact/inexact matches, so which one do we use? 495 // We have a list of exact/inexact matches, so which one do we use?
493 // So let's take the first one. 496 // So let's take the first one.
494 ret = sscanf(ptr, "%s %08lx %s", cddb_data->category, &(cddb_data->disc_id), album_title); 497 ret = sscanf(ptr, "%s %08lx %s", cddb_data->category, &(cddb_data->disc_id), album_title);
495 if( ret!=3 ) { 498 if( ret!=3 ) {
496 printf("Parse error\n"); 499 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
497 return -1; 500 return -1;
498 } 501 }
499 ptr = strstr(http_hdr->body, album_title); 502 ptr = strstr(http_hdr->body, album_title);
500 if( ptr!=NULL ) { 503 if( ptr!=NULL ) {
501 char *ptr2; 504 char *ptr2;
507 len = ptr2-ptr+1; 510 len = ptr2-ptr+1;
508 } 511 }
509 strncpy(album_title, ptr, len); 512 strncpy(album_title, ptr, len);
510 album_title[len-2]='\0'; 513 album_title[len-2]='\0';
511 } 514 }
512 printf("Parse OK, found: %s\n", album_title); 515 mp_msg(MSGT_DEMUX, MSGL_STATUS, MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle, album_title);
513 return 0; 516 return 0;
514 } 517 }
515 518
516 int 519 int
517 cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { 520 cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
519 char *ptr = NULL; 522 char *ptr = NULL;
520 int ret, status; 523 int ret, status;
521 524
522 ret = sscanf( http_hdr->body, "%d ", &status); 525 ret = sscanf( http_hdr->body, "%d ", &status);
523 if( ret!=1 ) { 526 if( ret!=1 ) {
524 printf("Parse error\n"); 527 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
525 return -1; 528 return -1;
526 } 529 }
527 530
528 switch(status) { 531 switch(status) {
529 case 200: 532 case 200:
530 // Found exact match 533 // Found exact match
531 ret = sscanf(http_hdr->body, "%d %s %08lx %s", &status, cddb_data->category, &(cddb_data->disc_id), album_title); 534 ret = sscanf(http_hdr->body, "%d %s %08lx %s", &status, cddb_data->category, &(cddb_data->disc_id), album_title);
532 if( ret!=4 ) { 535 if( ret!=4 ) {
533 printf("Parse error\n"); 536 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
534 return -1; 537 return -1;
535 } 538 }
536 ptr = strstr(http_hdr->body, album_title); 539 ptr = strstr(http_hdr->body, album_title);
537 if( ptr!=NULL ) { 540 if( ptr!=NULL ) {
538 char *ptr2; 541 char *ptr2;
544 len = ptr2-ptr+1; 547 len = ptr2-ptr+1;
545 } 548 }
546 strncpy(album_title, ptr, len); 549 strncpy(album_title, ptr, len);
547 album_title[len-2]='\0'; 550 album_title[len-2]='\0';
548 } 551 }
549 printf("Parse OK, found: %s\n", album_title); 552 mp_msg(MSGT_DEMUX, MSGL_STATUS, MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle, album_title);
550 return cddb_request_titles(cddb_data); 553 return cddb_request_titles(cddb_data);
551 case 202: 554 case 202:
552 // No match found 555 // No match found
553 printf("Album not found\n"); 556 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_AlbumNotFound);
554 break; 557 break;
555 case 210: 558 case 210:
556 // Found exact matches, list follows 559 // Found exact matches, list follows
557 cddb_parse_matches_list(http_hdr, cddb_data); 560 cddb_parse_matches_list(http_hdr, cddb_data);
558 return cddb_request_titles(cddb_data); 561 return cddb_request_titles(cddb_data);
566 case 211: 569 case 211:
567 // Found inexact matches, list follows 570 // Found inexact matches, list follows
568 cddb_parse_matches_list(http_hdr, cddb_data); 571 cddb_parse_matches_list(http_hdr, cddb_data);
569 return cddb_request_titles(cddb_data); 572 return cddb_request_titles(cddb_data);
570 case 500: 573 case 500:
571 printf("Server returns: Command syntax error\n"); 574 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_ServerReturnsCommandSyntaxErr);
572 break; 575 break;
573 default: 576 default:
574 printf("Unhandled code\n"); 577 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode);
575 } 578 }
576 return -1; 579 return -1;
577 } 580 }
578 581
579 int 582 int
582 int ret, status; 585 int ret, status;
583 char *ptr; 586 char *ptr;
584 587
585 ret = sscanf( http_hdr->body, "%d ", &status); 588 ret = sscanf( http_hdr->body, "%d ", &status);
586 if( ret!=1 ) { 589 if( ret!=1 ) {
587 printf("Parse error\n"); 590 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
588 return -1; 591 return -1;
589 } 592 }
590 593
591 switch(status) { 594 switch(status) {
592 case 210: 595 case 210:
593 ptr = strstr(http_hdr->body, "max proto:"); 596 ptr = strstr(http_hdr->body, "max proto:");
594 if( ptr==NULL ) { 597 if( ptr==NULL ) {
595 printf("Parse error\n"); 598 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
596 return -1; 599 return -1;
597 } 600 }
598 ret = sscanf(ptr, "max proto: %d", &max); 601 ret = sscanf(ptr, "max proto: %d", &max);
599 if( ret!=1 ) { 602 if( ret!=1 ) {
600 printf("Parse error\n"); 603 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
601 return -1; 604 return -1;
602 } 605 }
603 cddb_data->freedb_proto_level = max; 606 cddb_data->freedb_proto_level = max;
604 return 0; 607 return 0;
605 default: 608 default:
606 printf("Unhandled code\n"); 609 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode);
607 } 610 }
608 return -1; 611 return -1;
609 } 612 }
610 613
611 int 614 int
617 cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { 620 cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
618 int ret, status; 621 int ret, status;
619 622
620 ret = sscanf( http_hdr->body, "%d ", &status); 623 ret = sscanf( http_hdr->body, "%d ", &status);
621 if( ret!=1 ) { 624 if( ret!=1 ) {
622 printf("Parse error\n"); 625 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError);
623 return -1; 626 return -1;
624 } 627 }
625 628
626 switch(status) { 629 switch(status) {
627 case 210: 630 case 210:
628 // TODO: Parse the sites 631 // TODO: Parse the sites
629 ret = cddb_data->anonymous; // For gcc complaining about unused parameter. 632 ret = cddb_data->anonymous; // For gcc complaining about unused parameter.
630 return 0; 633 return 0;
631 case 401: 634 case 401:
632 printf("No sites information available\n"); 635 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_NoSitesInfoAvailable);
633 break; 636 break;
634 default: 637 default:
635 printf("Unhandled code\n"); 638 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode);
636 } 639 }
637 return -1; 640 return -1;
638 } 641 }
639 642
640 int 643 int
683 cddb_data->freedb_proto_level = 1; 686 cddb_data->freedb_proto_level = 1;
684 cddb_data->xmcd_file = NULL; 687 cddb_data->xmcd_file = NULL;
685 688
686 cddb_create_hello(cddb_data); 689 cddb_create_hello(cddb_data);
687 if( cddb_get_proto_level(cddb_data)<0 ) { 690 if( cddb_get_proto_level(cddb_data)<0 ) {
688 printf("Failed to get the protocol level\n"); 691 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToGetProtocolLevel);
689 return -1; 692 return -1;
690 } 693 }
691 694
692 //cddb_get_freedb_sites(&cddb_data); 695 //cddb_get_freedb_sites(&cddb_data);
693 696
709 712
710 if (cdtoc_last_track <= 0) 713 if (cdtoc_last_track <= 0)
711 { 714 {
712 cdtoc_last_track = read_toc(dev); 715 cdtoc_last_track = read_toc(dev);
713 if (cdtoc_last_track < 0) { 716 if (cdtoc_last_track < 0) {
714 printf("Failed to open %s device.\n", dev); 717 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice, dev);
715 return -1; 718 return -1;
716 } 719 }
717 } 720 }
718 cddb_data.tracks = cdtoc_last_track; 721 cddb_data.tracks = cdtoc_last_track;
719 cddb_data.disc_id = cddb_discid(cddb_data.tracks); 722 cddb_data.disc_id = cddb_discid(cddb_data.tracks);
720 cddb_data.anonymous = 1; // Don't send user info by default 723 cddb_data.anonymous = 1; // Don't send user info by default
721 724
722 // Check if there is a CD in the drive 725 // Check if there is a CD in the drive
723 // FIXME: That's not really a good way to check 726 // FIXME: That's not really a good way to check
724 if( cddb_data.disc_id==0 ) { 727 if( cddb_data.disc_id==0 ) {
725 printf("No CD in the drive\n"); 728 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NoCDInDrive);
726 return -1; 729 return -1;
727 } 730 }
728 731
729 home_dir = getenv("HOME"); 732 home_dir = getenv("HOME");
730 #ifdef __MINGW32__ 733 #ifdef __MINGW32__
736 if( home_dir==NULL ) { 739 if( home_dir==NULL ) {
737 cddb_data.cache_dir = NULL; 740 cddb_data.cache_dir = NULL;
738 } else { 741 } else {
739 cddb_data.cache_dir = (char*)malloc(strlen(home_dir)+strlen(cddb_cache_dir)+1); 742 cddb_data.cache_dir = (char*)malloc(strlen(home_dir)+strlen(cddb_cache_dir)+1);
740 if( cddb_data.cache_dir==NULL ) { 743 if( cddb_data.cache_dir==NULL ) {
741 printf("Memory allocation failed\n"); 744 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed);
742 return -1; 745 return -1;
743 } 746 }
744 sprintf(cddb_data.cache_dir, "%s%s", home_dir, cddb_cache_dir ); 747 sprintf(cddb_data.cache_dir, "%s%s", home_dir, cddb_cache_dir );
745 } 748 }
746 749