comparison src/madplug/plugin.c @ 2205:2faee266ea1e

madplug now provides more informative tuple
author Eugene Zagidullin <e.asphyx@gmail.com>
date Tue, 04 Dec 2007 02:04:49 +0300
parents 13b8ab116b69
children 7c7e6f5c494e
comparison
equal deleted inserted replaced
2204:43da009d6e76 2205:2faee266ea1e
534 #ifdef DEBUG 534 #ifdef DEBUG
535 g_message("e: audmad_get_song_info"); 535 g_message("e: audmad_get_song_info");
536 #endif /* DEBUG */ 536 #endif /* DEBUG */
537 } 537 }
538 538
539 static void 539 static gboolean
540 audmad_get_song_length(char *url, int *length, VFSFile *fd) 540 audmad_fill_info(struct mad_info_t *info, VFSFile *fd)
541 { 541 {
542 struct mad_info_t myinfo; 542 if (fd == NULL || info == NULL) return FALSE;
543 #ifdef DEBUG 543 #ifdef DEBUG
544 gchar *tmp = g_filename_to_utf8(url, -1, NULL, NULL, NULL); 544 g_message("f: audmad_fill_info(): %s", fd->uri);
545 g_message("f: audmad_get_song_length: %s", tmp); 545 #endif
546 g_free(tmp); 546
547 #endif /* DEBUG */ 547 if (input_init(info, fd->uri, fd) == FALSE) {
548 548 #ifdef DEBUG
549 if (input_init(&myinfo, url, fd ? fd : NULL) == FALSE) { 549 g_message("audmad_fill_info(): error initialising input");
550 #ifdef DEBUG 550 #endif
551 g_message("error initialising input"); 551 return FALSE;
552 #endif 552 }
553 return; 553
554 } 554 info->fileinfo_request = FALSE; /* we don't need to read tuple again */
555 555 return input_get_info(info, aud_vfs_is_remote(fd->uri) ? TRUE : audmad_config.fast_play_time_calc);
556 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) {
557 *length = aud_tuple_get_int(myinfo.tuple, FIELD_LENGTH, NULL);
558 if(*length == -1)
559 *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS);
560 }
561 else {
562 *length = -1;
563 }
564 input_term(&myinfo);
565 #ifdef DEBUG
566 g_message("e: audmad_get_song_info");
567 #endif /* DEBUG */
568 } 556 }
569 557
570 static void audmad_about() 558 static void audmad_about()
571 { 559 {
572 static GtkWidget *aboutbox; 560 static GtkWidget *aboutbox;
642 gchar *realfn = NULL; 630 gchar *realfn = NULL;
643 631
644 struct id3_file *id3file = NULL; 632 struct id3_file *id3file = NULL;
645 struct id3_tag *tag = NULL; 633 struct id3_tag *tag = NULL;
646 634
635 struct mad_info_t myinfo;
636
647 gboolean local_fd = FALSE; 637 gboolean local_fd = FALSE;
638 int length;
648 639
649 #ifdef DEBUG 640 #ifdef DEBUG
650 string = aud_str_to_utf8(filename); 641 string = aud_str_to_utf8(filename);
651 g_message("f: mad: audmad_get_song_tuple: %s", string); 642 g_message("f: mad: audmad_get_song_tuple: %s", string);
652 g_free(string); 643 g_free(string);
653 string = NULL; 644 string = NULL;
654 #endif 645 #endif
646
647 /* isn't is obfuscated? --eugene */
655 648
656 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){ 649 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){
657 if((fd && aud_vfs_is_streaming(fd)) || (info.playback && info.playback->playing)) { 650 if((fd && aud_vfs_is_streaming(fd)) || (info.playback && info.playback->playing)) {
658 gchar *tmp = NULL; 651 gchar *tmp = NULL;
659 tuple = aud_tuple_new_from_filename(filename); 652 tuple = aud_tuple_new_from_filename(filename);
706 if(!fd) { 699 if(!fd) {
707 fd = aud_vfs_fopen(filename, "rb"); 700 fd = aud_vfs_fopen(filename, "rb");
708 if(!fd) 701 if(!fd)
709 return NULL; 702 return NULL;
710 local_fd = TRUE; 703 local_fd = TRUE;
704 }
705
706 if (!audmad_fill_info(&myinfo, fd)) {
707 #ifdef DEBUG
708 g_message("get_song_tuple: error obtaining info\n");
709 #endif
710 if (local_fd) aud_vfs_fclose(fd);
711 return NULL;
711 } 712 }
712 713
713 tuple = aud_tuple_new(); 714 tuple = aud_tuple_new();
714 aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, -1); 715 aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, -1);
715 716
739 __set_and_free(tuple, FIELD_FILE_PATH, NULL, g_path_get_dirname(realfn ? realfn : filename)); 740 __set_and_free(tuple, FIELD_FILE_PATH, NULL, g_path_get_dirname(realfn ? realfn : filename));
740 aud_tuple_associate_string(tuple, FIELD_FILE_EXT, NULL, extname(realfn ? realfn : filename)); 741 aud_tuple_associate_string(tuple, FIELD_FILE_EXT, NULL, extname(realfn ? realfn : filename));
741 g_free(realfn); realfn = NULL; 742 g_free(realfn); realfn = NULL;
742 743
743 // length 744 // length
744 string = input_id3_get_string(tag, "TLEN"); 745 length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS);
745 if (string) { 746 aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, length);
746 aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, atoi(string));
747 #ifdef DEBUG
748 g_message("get_song_tuple: TLEN = %d", aud_tuple_get_int(tuple, FIELD_LENGTH, NULL));
749 #endif
750 g_free(string);
751 string = NULL;
752 }
753 else {
754 char *dummy = NULL;
755 int length = 0;
756 audmad_get_song_length(filename, &length, fd);
757 aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, length);
758 g_free(dummy);
759 }
760 747
761 // track number 748 // track number
762 string = input_id3_get_string(tag, ID3_FRAME_TRACK); 749 string = input_id3_get_string(tag, ID3_FRAME_TRACK);
763 if (string) { 750 if (string) {
764 aud_tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, atoi(string)); 751 aud_tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, atoi(string));
779 __set_and_free(tuple, FIELD_FILE_NAME, NULL, g_path_get_basename(realfn ? realfn : filename)); 766 __set_and_free(tuple, FIELD_FILE_NAME, NULL, g_path_get_basename(realfn ? realfn : filename));
780 __set_and_free(tuple, FIELD_FILE_PATH, NULL, g_path_get_dirname(realfn ? realfn : filename)); 767 __set_and_free(tuple, FIELD_FILE_PATH, NULL, g_path_get_dirname(realfn ? realfn : filename));
781 aud_tuple_associate_string(tuple, FIELD_FILE_EXT, NULL, extname(realfn ? realfn : filename)); 768 aud_tuple_associate_string(tuple, FIELD_FILE_EXT, NULL, extname(realfn ? realfn : filename));
782 g_free(realfn); realfn = NULL; 769 g_free(realfn); realfn = NULL;
783 // length 770 // length
784 { 771 length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS);
785 char *dummy = NULL; 772 aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, length);
786 int length = 0; 773 }
787 if(aud_tuple_get_int(tuple, FIELD_LENGTH, NULL) == -1) { 774
788 audmad_get_song_length(filename, &length, fd); 775 if (myinfo.vbr) {
789 aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, length); 776 string = g_strdup_printf("lossy, bitrate: VBR (avg. %d kbps)", myinfo.bitrate / 1000);
790 } 777 } else {
791 g_free(dummy); 778 string = g_strdup_printf("lossy, bitrate: %d kbps", myinfo.bitrate / 1000);
792 } 779 }
793 } 780 aud_tuple_associate_string(tuple, FIELD_QUALITY, NULL, string);
794 781 g_free(string);
795 /* TUDO: make tuple more informative (bitrate, layer). 782
796 * but it can slowdown tuple creation and avoid sense of TLEN reading. --eugene */ 783 string = g_strdup_printf("MPEG-1 Audio Layer %d", myinfo.mpeg_layer);
797 784 aud_tuple_associate_string(tuple, FIELD_CODEC, NULL, string);
798 aud_tuple_associate_string(tuple, FIELD_QUALITY, NULL, "lossy"); 785 g_free(string);
799 aud_tuple_associate_string(tuple, FIELD_CODEC, NULL, "MPEG Audio (MP3)"); 786
800 aud_tuple_associate_string(tuple, FIELD_MIMETYPE, NULL, "audio/mpeg"); 787 aud_tuple_associate_string(tuple, FIELD_MIMETYPE, NULL, "audio/mpeg");
788
789 input_term(&myinfo);
801 790
802 if(local_fd) 791 if(local_fd)
803 aud_vfs_fclose(fd); 792 aud_vfs_fclose(fd);
804 793
805 #ifdef DEBUG 794 #ifdef DEBUG