comparison src/madplug/plugin.c @ 1687:d158ce84fda7

Modified for Tuplez/plugin API changes.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Sep 2007 09:29:26 +0300
parents 4e612b01f303
children f35f9d6fcb6d
comparison
equal deleted inserted replaced
1600:49fe2225d236 1687:d158ce84fda7
514 #endif 514 #endif
515 return; 515 return;
516 } 516 }
517 517
518 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) { 518 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) {
519 if(tuple_get_string(myinfo.tuple, "track-name")) 519 if(tuple_get_string(myinfo.tuple, -1, "track-name"))
520 *title = g_strdup(tuple_get_string(myinfo.tuple, "track-name")); 520 *title = g_strdup(tuple_get_string(myinfo.tuple, -1, "track-name"));
521 else 521 else
522 *title = g_strdup(url); 522 *title = g_strdup(url);
523 if(tuple_get_int(myinfo.tuple, "length") == -1) 523 if(tuple_get_int(myinfo.tuple, FIELD_LENGTH, NULL) == -1)
524 *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS); 524 *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS);
525 else 525 else
526 *length = tuple_get_int(myinfo.tuple, "length"); 526 *length = tuple_get_int(myinfo.tuple, FIELD_LENGTH, NULL);
527 } 527 }
528 else { 528 else {
529 *title = g_strdup(url); 529 *title = g_strdup(url);
530 *length = -1; 530 *length = -1;
531 } 531 }
551 #endif 551 #endif
552 return; 552 return;
553 } 553 }
554 554
555 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) { 555 if (input_get_info(&myinfo, info.remote ? TRUE : audmad_config.fast_play_time_calc) == TRUE) {
556 if(tuple_get_int(myinfo.tuple, "length") == -1) 556 if(tuple_get_int(myinfo.tuple, FIELD_LENGTH, NULL) == -1)
557 *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS); 557 *length = mad_timer_count(myinfo.duration, MAD_UNITS_MILLISECONDS);
558 else 558 else
559 *length = tuple_get_int(myinfo.tuple, "length"); 559 *length = tuple_get_int(myinfo.tuple, FIELD_LENGTH, NULL);
560 } 560 }
561 else { 561 else {
562 *length = -1; 562 *length = -1;
563 } 563 }
564 input_term(&myinfo); 564 input_term(&myinfo);
627 } 627 }
628 628
629 extern void audmad_get_file_info(char *filename); 629 extern void audmad_get_file_info(char *filename);
630 extern void audmad_configure(); 630 extern void audmad_configure();
631 631
632 static void __set_and_free(Tuple *tuple, gchar *name, gchar *value) 632 static void __set_and_free(Tuple *tuple, gint nfield, gchar *name, gchar *value)
633 { 633 {
634 tuple_associate_string(tuple, name, value); 634 tuple_associate_string(tuple, nfield, name, value);
635 g_free(value); 635 g_free(value);
636 } 636 }
637 637
638 // tuple stuff 638 // tuple stuff
639 static Tuple *__audmad_get_song_tuple(char *filename, VFSFile *fd) 639 static Tuple *__audmad_get_song_tuple(char *filename, VFSFile *fd)
655 #endif 655 #endif
656 656
657 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){ 657 if(info.remote && mad_timer_count(info.duration, MAD_UNITS_SECONDS) <= 0){
658 if((fd && vfs_is_streaming(fd)) || (info.playback && info.playback->playing)) { 658 if((fd && vfs_is_streaming(fd)) || (info.playback && info.playback->playing)) {
659 gchar *tmp = NULL; 659 gchar *tmp = NULL;
660 tuple = tuple_new(); 660 tuple = tuple_new_from_filename(filename);
661 661
662 #ifdef DEBUG 662 #ifdef DEBUG
663 if(info.playback) 663 if(info.playback)
664 g_message("info.playback->playing = %d",info.playback->playing); 664 g_message("info.playback->playing = %d",info.playback->playing);
665 #endif 665 #endif
666 tmp = vfs_get_metadata(info.infile ? info.infile : fd, "track-name"); 666 tmp = vfs_get_metadata(info.infile ? info.infile : fd, "track-name");
667 if(tmp){ 667 if(tmp){
668 gchar *scratch; 668 gchar *scratch;
669 669
670 scratch = str_to_utf8(tmp); 670 scratch = str_to_utf8(tmp);
671 tuple_associate_string(tuple, "title", scratch); 671 tuple_associate_string(tuple, FIELD_TITLE, NULL, scratch);
672 g_free(tmp); 672 g_free(tmp);
673 g_free(scratch); 673 g_free(scratch);
674 674
675 tmp = NULL; 675 tmp = NULL;
676 } 676 }
677 tmp = vfs_get_metadata(info.infile ? info.infile : fd, "stream-name"); 677 tmp = vfs_get_metadata(info.infile ? info.infile : fd, "stream-name");
678 if(tmp){ 678 if(tmp){
679 gchar *scratch; 679 gchar *scratch;
680 680
681 scratch = str_to_utf8(tmp); 681 scratch = str_to_utf8(tmp);
682 tuple_associate_string(tuple, "title", scratch); 682 tuple_associate_string(tuple, FIELD_TITLE, NULL, scratch);
683 g_free(tmp); 683 g_free(tmp);
684 g_free(scratch); 684 g_free(scratch);
685 685
686 tmp = NULL; 686 tmp = NULL;
687 } 687 }
688 688
689 #ifdef DEBUG 689 #ifdef DEBUG
690 g_message("audmad_get_song_tuple: track_name = %s", tuple_get_string(tuple, "track-name")); 690 g_message("audmad_get_song_tuple: track_name = %s", tuple_get_string(tuple, -1, "track-name"));
691 g_message("audmad_get_song_tuple: stream_name = %s", tuple_get_string(tuple, "stream-name")); 691 g_message("audmad_get_song_tuple: stream_name = %s", tuple_get_string(tuple, -1, "stream-name"));
692 #endif 692 #endif
693 realfn = g_filename_from_uri(filename, NULL, NULL); 693 tuple_associate_int(tuple, FIELD_LENGTH, NULL, -1);
694 __set_and_free(tuple, "file-name", g_path_get_basename(realfn ? realfn : filename)); 694 tuple_associate_int(tuple, FIELD_MTIME, NULL, 0); // this indicates streaming
695 __set_and_free(tuple, "file-path", g_path_get_dirname(realfn ? realfn : filename));
696 tuple_associate_string(tuple, "file-ext", extname(realfn ? realfn : filename));
697 g_free(realfn); realfn = NULL;
698
699 tuple_associate_int(tuple, "length", -1);
700 tuple_associate_int(tuple, "mtime", 0); // this indicates streaming
701 #ifdef DEBUG 695 #ifdef DEBUG
702 g_message("get_song_tuple: remote: tuple"); 696 g_message("get_song_tuple: remote: tuple");
703 #endif 697 #endif
704 return tuple; 698 return tuple;
705 } 699 }
716 return NULL; 710 return NULL;
717 local_fd = TRUE; 711 local_fd = TRUE;
718 } 712 }
719 713
720 tuple = tuple_new(); 714 tuple = tuple_new();
721 tuple_associate_int(tuple, "length", -1); 715 tuple_associate_int(tuple, FIELD_LENGTH, NULL, -1);
722 716
723 id3file = id3_file_vfsopen(fd, ID3_FILE_MODE_READONLY); 717 id3file = id3_file_vfsopen(fd, ID3_FILE_MODE_READONLY);
724 718
725 if (id3file) { 719 if (id3file) {
726 720
727 tag = id3_file_tag(id3file); 721 tag = id3_file_tag(id3file);
728 if (tag) { 722 if (tag) {
729 __set_and_free(tuple, "artist", input_id3_get_string(tag, ID3_FRAME_ARTIST)); 723 __set_and_free(tuple, FIELD_ARTIST, NULL, input_id3_get_string(tag, ID3_FRAME_ARTIST));
730 __set_and_free(tuple, "album", input_id3_get_string(tag, ID3_FRAME_ALBUM)); 724 __set_and_free(tuple, FIELD_ALBUM, NULL, input_id3_get_string(tag, ID3_FRAME_ALBUM));
731 __set_and_free(tuple, "title", input_id3_get_string(tag, ID3_FRAME_TITLE)); 725 __set_and_free(tuple, FIELD_TITLE, NULL, input_id3_get_string(tag, ID3_FRAME_TITLE));
732 726
733 // year 727 // year
734 string = NULL; 728 string = NULL;
735 string = input_id3_get_string(tag, ID3_FRAME_YEAR); //TDRC 729 string = input_id3_get_string(tag, ID3_FRAME_YEAR); //TDRC
736 if (!string) 730 if (!string)
737 string = input_id3_get_string(tag, "TYER"); 731 string = input_id3_get_string(tag, "TYER");
738 732
739 if (string) { 733 if (string) {
740 tuple_associate_int(tuple, "year", atoi(string)); 734 tuple_associate_int(tuple, FIELD_YEAR, NULL, atoi(string));
741 g_free(string); 735 g_free(string);
742 string = NULL; 736 string = NULL;
743 } 737 }
744 realfn = g_filename_from_uri(filename, NULL, NULL); 738 realfn = g_filename_from_uri(filename, NULL, NULL);
745 __set_and_free(tuple, "file-name", g_path_get_basename(realfn ? realfn : filename)); 739 __set_and_free(tuple, FIELD_FILE_NAME, NULL, g_path_get_basename(realfn ? realfn : filename));
746 __set_and_free(tuple, "file-path", g_path_get_dirname(realfn ? realfn : filename)); 740 __set_and_free(tuple, FIELD_FILE_PATH, NULL, g_path_get_dirname(realfn ? realfn : filename));
747 tuple_associate_string(tuple, "file-ext", extname(realfn ? realfn : filename)); 741 tuple_associate_string(tuple, FIELD_FILE_EXT, NULL, extname(realfn ? realfn : filename));
748 g_free(realfn); realfn = NULL; 742 g_free(realfn); realfn = NULL;
749 743
750 // length 744 // length
751 string = input_id3_get_string(tag, "TLEN"); 745 string = input_id3_get_string(tag, "TLEN");
752 if (string) { 746 if (string) {
753 tuple_associate_int(tuple, "length", atoi(string)); 747 tuple_associate_int(tuple, FIELD_LENGTH, NULL, atoi(string));
754 #ifdef DEBUG 748 #ifdef DEBUG
755 g_message("get_song_tuple: TLEN = %d", tuple_get_int(tuple, "length")); 749 g_message("get_song_tuple: TLEN = %d", tuple_get_int(tuple, FIELD_LENGTH, NULL));
756 #endif 750 #endif
757 g_free(string); 751 g_free(string);
758 string = NULL; 752 string = NULL;
759 } 753 }
760 else { 754 else {
761 char *dummy = NULL; 755 char *dummy = NULL;
762 int length = 0; 756 int length = 0;
763 audmad_get_song_length(filename, &length, fd); 757 audmad_get_song_length(filename, &length, fd);
764 tuple_associate_int(tuple, "length", length); 758 tuple_associate_int(tuple, FIELD_LENGTH, NULL, length);
765 g_free(dummy); 759 g_free(dummy);
766 } 760 }
767 761
768 // track number 762 // track number
769 string = input_id3_get_string(tag, ID3_FRAME_TRACK); 763 string = input_id3_get_string(tag, ID3_FRAME_TRACK);
770 if (string) { 764 if (string) {
771 tuple_associate_int(tuple, "track-number", atoi(string)); 765 tuple_associate_int(tuple, FIELD_TRACK_NUMBER, NULL, atoi(string));
772 g_free(string); 766 g_free(string);
773 string = NULL; 767 string = NULL;
774 } 768 }
775 // genre 769 // genre
776 __set_and_free(tuple, "genre", input_id3_get_string(tag, ID3_FRAME_GENRE)); 770 __set_and_free(tuple, FIELD_GENRE, NULL, input_id3_get_string(tag, ID3_FRAME_GENRE));
777 __set_and_free(tuple, "comment", input_id3_get_string(tag, ID3_FRAME_COMMENT)); 771 __set_and_free(tuple, FIELD_COMMENT, NULL, input_id3_get_string(tag, ID3_FRAME_COMMENT));
778 #ifdef DEBUG 772 #ifdef DEBUG
779 g_message("genre = %s", tuple_get_string(tuple, "genre")); 773 g_message("genre = %s", tuple_get_string(tuple, FIELD_GENRE, NULL));
780 #endif 774 #endif
781 } 775 }
782 id3_file_close(id3file); 776 id3_file_close(id3file);
783 } // id3file 777 } // id3file
784 else { // no id3tag 778 else { // no id3tag
785 realfn = g_filename_from_uri(filename, NULL, NULL); 779 realfn = g_filename_from_uri(filename, NULL, NULL);
786 __set_and_free(tuple, "file-name", g_path_get_basename(realfn ? realfn : filename)); 780 __set_and_free(tuple, FIELD_FILE_NAME, NULL, g_path_get_basename(realfn ? realfn : filename));
787 __set_and_free(tuple, "file-path", g_path_get_dirname(realfn ? realfn : filename)); 781 __set_and_free(tuple, FIELD_FILE_PATH, NULL, g_path_get_dirname(realfn ? realfn : filename));
788 tuple_associate_string(tuple, "file-ext", extname(realfn ? realfn : filename)); 782 tuple_associate_string(tuple, FIELD_FILE_EXT, NULL, extname(realfn ? realfn : filename));
789 g_free(realfn); realfn = NULL; 783 g_free(realfn); realfn = NULL;
790 // length 784 // length
791 { 785 {
792 char *dummy = NULL; 786 char *dummy = NULL;
793 int length = 0; 787 int length = 0;
794 if(tuple_get_int(tuple, "length") == -1) { 788 if(tuple_get_int(tuple, FIELD_LENGTH, NULL) == -1) {
795 audmad_get_song_length(filename, &length, fd); 789 audmad_get_song_length(filename, &length, fd);
796 tuple_associate_int(tuple, "length", length); 790 tuple_associate_int(tuple, FIELD_LENGTH, NULL, length);
797 } 791 }
798 g_free(dummy); 792 g_free(dummy);
799 } 793 }
800 } 794 }
801 795
802 tuple_associate_string(tuple, "quality", "lossy"); 796 tuple_associate_string(tuple, FIELD_QUALITY, NULL, "lossy");
803 tuple_associate_string(tuple, "codec", "MPEG Audio (MP3)"); 797 tuple_associate_string(tuple, FIELD_CODEC, NULL, "MPEG Audio (MP3)");
804 798
805 if(local_fd) 799 if(local_fd)
806 vfs_fclose(fd); 800 vfs_fclose(fd);
807 801
808 #ifdef DEBUG 802 #ifdef DEBUG