1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 #include <sys/types.h>
41 ////////////////////////////////////////////////////////////////////////////////
42 static char *trimstr (char *s
) {
44 if (s
!= NULL
&& s
[0]) {
45 //char *olds = strdup(s), *xs = s;
47 // change all '/' to underlines
48 for (ns
= s
; *ns
; ++ns
) if (*ns
== '/' || *ns
== 127) *ns
= '_';
49 // remove duplicate underlines
50 for (ns
= p
= s
; *ns
; ++ns
) {
52 if (p
> s
&& p
[-1] != '_') *p
++ = *ns
;
58 // remove duplicate spaces
59 for (ns
= p
= s
; *ns
; ++ns
) {
61 if (p
> s
&& !leIsSpace(p
[-1])) *p
++ = *ns
;
67 // trim trailing spaces and underlines
69 while (ns
>= s
&& (leIsSpace(*ns
) || *ns
== '_')) --ns
;
71 // trim leading spaces and underlines
72 for (ns
= s
; *ns
&& (leIsSpace(*ns
) || *ns
== '_'); ++ns
) ;
73 if (ns
!= s
) memmove(s
, ns
, strlen(ns
)+1);
79 ////////////////////////////////////////////////////////////////////////////////
80 #define xstrdup(ss) ({ \
82 char *d = alloca(s != NULL ? strlen(s)+1 : 1); \
83 if (s != NULL) strcpy(d, s); \
87 static int show_tags (const char *filename
, int donl
) {
90 //const TagLib_AudioProperties *properties;
92 taglib_set_strings_unicode(1);
93 file
= taglib_file_new(filename
);
94 if (file
== NULL
) return 0;
95 tag
= taglib_file_tag(file
);
97 char *artist
= trimstr(xstrdup(taglib_tag_artist(tag
)));
98 char *album
= trimstr(xstrdup(taglib_tag_album(tag
)));
99 char *title
= trimstr(xstrdup(taglib_tag_title(tag
)));
100 char *genre
= trimstr(xstrdup(taglib_tag_genre(tag
)));
101 unsigned int yy
= taglib_tag_year(tag
);
102 unsigned int tno
= taglib_tag_track(tag
);
105 if (yy
< 30) yy
+= 2000;
106 else if (yy
< 100) yy
+= 1900;
107 else if (yy
< 1930) yy
= 0;
109 if (tno
== 0 || tno
> 99) tno
= 0;
110 if (artist
[0] || album
[0] || title
[0] || genre
[0] || yy
|| tno
) {
111 if (donl
) printf("\n");
112 if (artist
[0]) printf("ARTIST=%s\n", artist
);
113 if (album
[0]) printf("ALBUM=%s\n", album
);
114 if (title
[0]) printf("TITLE=%s\n", title
);
115 if (genre
[0]) printf("GENRE=%s\n", genre
);
116 if (yy
) printf("YEAR=%u\n", yy
);
117 if (tno
) printf("TRACKNUMBER=%u\n", tno
);
124 properties = taglib_file_audioproperties(file);
125 if (properties != NULL) {
126 int seconds = taglib_audioproperties_length(properties)%60;
127 int minutes = (taglib_audioproperties_length(properties)-seconds)/60;
128 printf("-- AUDIO --\n");
129 printf("bitrate : %d\n", taglib_audioproperties_bitrate(properties));
130 printf("sample rate: %d\n", taglib_audioproperties_samplerate(properties));
131 printf("channels : %d\n", taglib_audioproperties_channels(properties));
132 printf("length : %d:%02i\n", minutes, seconds);
136 taglib_tag_free_strings();
137 taglib_file_free(file
);
142 ////////////////////////////////////////////////////////////////////////////////
143 int main (int argc
, char *argv
[]) {
145 for (int f
= 1; f
< argc
; ++f
) {
146 if (show_tags(argv
[f
], donl
) > 0) donl
= 1;