comparison src/madplug/input.c @ 1432:e6eab0c725cd

Branch merge madness.
author Tony Vroon <chainsaw@gentoo.org>
date Fri, 10 Aug 2007 14:02:18 +0100
parents 4993976d7ed0
children db616ccdd40c
comparison
equal deleted inserted replaced
1431:6b1f888a4c52 1432:e6eab0c725cd
278 } 278 }
279 } 279 }
280 return ret; 280 return ret;
281 } 281 }
282 282
283 gchar *input_id3_get_string(struct id3_tag * tag, char *frame_name) 283 gchar *input_id3_get_string(struct id3_tag * tag, const gchar *frame_name)
284 { 284 {
285 gchar *rtn0 = NULL, *rtn = NULL; 285 gchar *rtn0 = NULL, *rtn = NULL;
286 const id3_ucs4_t *string_const = NULL; 286 const id3_ucs4_t *string_const = NULL;
287 id3_ucs4_t *string = NULL; 287 id3_ucs4_t *string = NULL;
288 struct id3_frame *frame; 288 struct id3_frame *frame;
339 g_print("i: string = %s\n", rtn); 339 g_print("i: string = %s\n", rtn);
340 #endif 340 #endif
341 return rtn; 341 return rtn;
342 } 342 }
343 343
344 static void input_set_and_free_tag(struct id3_tag *tag, Tuple *tuple, const gchar *frame, const gchar *tuple_name)
345 {
346 gchar *scratch = input_id3_get_string(tag, frame);
347
348 tuple_associate_string(tuple, tuple_name, scratch);
349 tuple_associate_string(tuple, frame, scratch);
350
351 g_free(scratch);
352 }
344 353
345 static void input_alloc_tag(struct mad_info_t *info) 354 static void input_alloc_tag(struct mad_info_t *info)
346 { 355 {
347 TitleInput *title_input; 356 Tuple *title_input;
348 357
349 if (info->tuple == NULL) { 358 if (info->tuple == NULL) {
350 title_input = bmp_title_input_new(); 359 title_input = tuple_new();
351 info->tuple = title_input; 360 info->tuple = title_input;
352 info->tuple->length = -1; //will be refferd in decoder.c 361 tuple_associate_int(info->tuple, "length", -1);
353 } 362 }
354 else 363 else
355 title_input = info->tuple; 364 title_input = info->tuple;
356 } 365 }
357 366
360 */ 369 */
361 static void input_read_tag(struct mad_info_t *info) 370 static void input_read_tag(struct mad_info_t *info)
362 { 371 {
363 gchar *string = NULL; 372 gchar *string = NULL;
364 gchar *realfn = NULL; 373 gchar *realfn = NULL;
365 TitleInput *title_input; 374 Tuple *title_input;
366 glong curpos = 0; 375 glong curpos = 0;
367 376
368 #ifdef DEBUG 377 #ifdef DEBUG
369 g_message("f: input_read_tag"); 378 g_message("f: input_read_tag");
370 #endif 379 #endif
371 if (info->tuple == NULL) { 380 if (info->tuple == NULL) {
372 title_input = bmp_title_input_new(); 381 title_input = tuple_new();
373 info->tuple = title_input; 382 info->tuple = title_input;
374 } 383 }
375 else 384 else
376 title_input = info->tuple; 385 title_input = info->tuple;
377 386
396 g_message("read_tag: no tag"); 405 g_message("read_tag: no tag");
397 #endif 406 #endif
398 return; 407 return;
399 } 408 }
400 409
401 title_input->performer = 410 input_set_and_free_tag(info->tag, title_input, ID3_FRAME_ARTIST, "artist");
402 input_id3_get_string(info->tag, ID3_FRAME_ARTIST); 411 input_set_and_free_tag(info->tag, title_input, ID3_FRAME_TITLE, "title");
403 title_input->track_name = 412 input_set_and_free_tag(info->tag, title_input, ID3_FRAME_ALBUM, "album");
404 input_id3_get_string(info->tag, ID3_FRAME_TITLE); 413 input_set_and_free_tag(info->tag, title_input, ID3_FRAME_GENRE, "genre");
405 title_input->album_name = 414 input_set_and_free_tag(info->tag, title_input, ID3_FRAME_COMMENT, "comment");
406 input_id3_get_string(info->tag, ID3_FRAME_ALBUM); 415
407 title_input->genre = input_id3_get_string(info->tag, ID3_FRAME_GENRE);
408 title_input->comment =
409 input_id3_get_string(info->tag, ID3_FRAME_COMMENT);
410 string = input_id3_get_string(info->tag, ID3_FRAME_TRACK); 416 string = input_id3_get_string(info->tag, ID3_FRAME_TRACK);
411 if (string) { 417 if (string) {
412 title_input->track_number = atoi(string); 418 tuple_associate_int(title_input, "track-number", atoi(string));
413 g_free(string); 419 g_free(string);
414 string = NULL; 420 string = NULL;
415 } 421 }
422
416 // year 423 // year
417 string = NULL; 424 string = NULL;
418 string = input_id3_get_string(info->tag, ID3_FRAME_YEAR); //TDRC 425 string = input_id3_get_string(info->tag, ID3_FRAME_YEAR); //TDRC
419 if (!string) 426 if (!string)
420 string = input_id3_get_string(info->tag, "TYER"); 427 string = input_id3_get_string(info->tag, "TYER");
421 428
422 if (string) { 429 if (string) {
423 title_input->year = atoi(string); 430 tuple_associate_int(title_input, "year", atoi(string));
424 g_free(string); 431 g_free(string);
425 string = NULL; 432 string = NULL;
426 } 433 }
427 434
428 // length 435 // length
429 title_input->length = -1;
430 string = input_id3_get_string(info->tag, "TLEN"); 436 string = input_id3_get_string(info->tag, "TLEN");
431 if (string) { 437 if (string) {
432 title_input->length = atoi(string); 438 tuple_associate_int(title_input, "length", atoi(string));
433 #ifdef DEBUG 439 #ifdef DEBUG
434 g_message("input_read_tag: TLEN = %d", title_input->length); 440 g_message("input_read_tag: TLEN = %d", atoi(string));
435 #endif 441 #endif
436 g_free(string); 442 g_free(string);
437 string = NULL; 443 string = NULL;
438 } 444 }
439 445
440 realfn = g_filename_from_uri(info->filename, NULL, NULL); 446 realfn = g_filename_from_uri(info->filename, NULL, NULL);
441 title_input->file_name = g_strdup(g_basename(realfn ? realfn : info->filename)); 447
442 title_input->file_path = g_path_get_dirname(realfn ? realfn : info->filename); 448 string = g_strdup(g_basename(realfn ? realfn : info->filename));
449 tuple_associate_string(title_input, "file-name", string);
450 g_free(string);
451
452 string = g_path_get_dirname(realfn ? realfn : info->filename);
453 tuple_associate_string(title_input, "file-path", string);
454 g_free(string);
455
456 if ((string = strrchr(realfn ? realfn : info->filename, '.'))) {
457 *string = '\0'; // make filename end at dot.
458 tuple_associate_string(title_input, "file-ext", string + 1);
459 }
460
443 g_free(realfn); realfn = NULL; 461 g_free(realfn); realfn = NULL;
444 if ((string = strrchr(title_input->file_name, '.'))) { 462
445 title_input->file_ext = string + 1; 463 tuple_associate_string(title_input, "codec", "MPEG Audio (MP3)");
446 *string = '\0'; // make filename end at dot. 464 tuple_associate_string(title_input, "quality", "lossy");
447 } 465
448 466 info->title = tuple_formatter_process_string(title_input, audmad_config.title_override == TRUE ?
449 info->title = xmms_get_titlestring(audmad_config.title_override == TRUE ? 467 audmad_config.id3_format : cfg.gentitle_format);
450 audmad_config.id3_format : xmms_get_gentitle_format(), title_input);
451 468
452 // for connection via proxy, we have to stop transfer once. I can't explain the reason. 469 // for connection via proxy, we have to stop transfer once. I can't explain the reason.
453 if (info->infile != NULL) { 470 if (info->infile != NULL) {
454 vfs_fseek(info->infile, -1, SEEK_SET); // an impossible request 471 vfs_fseek(info->infile, -1, SEEK_SET); // an impossible request
455 vfs_fseek(info->infile, curpos, SEEK_SET); 472 vfs_fseek(info->infile, curpos, SEEK_SET);
456 } 473 }
457 474
458 #ifdef DEBUG 475 #ifdef DEBUG
459 g_message("e: input_read_tag"); 476 g_message("e: input_read_tag");
460 #endif 477 #endif
461
462 } 478 }
463 479
464 void input_process_remote_metadata(struct mad_info_t *info) 480 void input_process_remote_metadata(struct mad_info_t *info)
465 { 481 {
482 gboolean metadata = FALSE;
483
466 if(info->remote && mad_timer_count(info->duration, MAD_UNITS_SECONDS) <= 0){ 484 if(info->remote && mad_timer_count(info->duration, MAD_UNITS_SECONDS) <= 0){
467 gchar *tmp = NULL; 485 gchar *tmp = NULL;
468 #ifdef DEBUG 486 #ifdef DEBUG
469 #ifdef DEBUG_INTENSIVELY 487 #ifdef DEBUG_INTENSIVELY
470 g_message("process_remote_meta"); 488 g_message("process_remote_meta");
471 #endif 489 #endif
472 #endif 490 #endif
491
473 g_free(info->title); 492 g_free(info->title);
474 info->title = NULL; 493 info->title = NULL;
475 g_free(info->tuple->track_name); 494 tuple_disassociate(info->tuple, "title");
476 info->tuple->track_name = NULL; 495 tuple_disassociate(info->tuple, "album");
477 g_free(info->tuple->album_name);
478 info->tuple->album_name = NULL;
479 496
480 tmp = vfs_get_metadata(info->infile, "track-name"); 497 tmp = vfs_get_metadata(info->infile, "track-name");
481 if(tmp){ 498 if(tmp){
482 info->tuple->track_name = str_to_utf8(tmp); 499 metadata = TRUE;
483 info->title = g_strdup(info->tuple->track_name); 500 gchar *scratch;
501
502 scratch = str_to_utf8(tmp);
503 tuple_associate_string(info->tuple, "title", scratch);
504 g_free(scratch);
505
484 g_free(tmp); 506 g_free(tmp);
485 tmp = NULL; 507 tmp = NULL;
486 } 508 }
487 509
488 tmp = vfs_get_metadata(info->infile, "stream-name"); 510 tmp = vfs_get_metadata(info->infile, "stream-name");
489 if(tmp){ 511 if(tmp){
490 info->tuple->album_name = str_to_utf8(tmp); 512 metadata = TRUE;
513 gchar *scratch;
514
515 scratch = str_to_utf8(tmp);
516 tuple_associate_string(info->tuple, "album", scratch);
517 tuple_associate_string(info->tuple, "stream", scratch);
518 g_free(scratch);
519
491 g_free(tmp); 520 g_free(tmp);
492 tmp = NULL; 521 tmp = NULL;
493 } 522 }
494 523
495 if (info->tuple->track_name && info->tuple->album_name) 524 if (metadata)
496 tmp = g_strdup_printf("%s (%s)", info->tuple->track_name, info->tuple->album_name); 525 tmp = tuple_formatter_process_string(info->tuple, "${?title:${title}}${?stream: (${stream})");
497 else if (info->tuple->album_name)
498 tmp = g_strdup(info->tuple->album_name);
499 else { 526 else {
500 gchar *realfn = g_filename_from_uri(info->filename, NULL, NULL); 527 gchar *realfn = g_filename_from_uri(info->filename, NULL, NULL);
501 gchar *tmp2 = g_path_get_basename(realfn ? realfn : info->filename); // info->filename is uri. --yaz 528 gchar *tmp2 = g_path_get_basename(realfn ? realfn : info->filename); // info->filename is uri. --yaz
502 tmp = str_to_utf8(tmp2); 529 tmp = str_to_utf8(tmp2);
503 g_free(tmp2); tmp2 = NULL; 530 g_free(tmp2); tmp2 = NULL;
635 g_free(info->mp3gain_undo_str); 662 g_free(info->mp3gain_undo_str);
636 if (info->mp3gain_minmax_str) 663 if (info->mp3gain_minmax_str)
637 g_free(info->mp3gain_minmax_str); 664 g_free(info->mp3gain_minmax_str);
638 665
639 if (info->tuple) { 666 if (info->tuple) {
640 bmp_title_input_free(info->tuple); 667 mowgli_object_unref(info->tuple);
641 info->tuple = NULL; 668 info->tuple = NULL;
642 } 669 }
643 670
644 if (info->prev_title) 671 if (info->prev_title)
645 g_free(info->prev_title); 672 g_free(info->prev_title);