diff options
Diffstat (limited to 'src/plugins/mp3_extractor.c')
-rw-r--r-- | src/plugins/mp3_extractor.c | 275 |
1 files changed, 7 insertions, 268 deletions
diff --git a/src/plugins/mp3_extractor.c b/src/plugins/mp3_extractor.c index 2696431..a60754a 100644 --- a/src/plugins/mp3_extractor.c +++ b/src/plugins/mp3_extractor.c | |||
@@ -36,172 +36,6 @@ | |||
36 | #include <unistd.h> | 36 | #include <unistd.h> |
37 | #include <stdlib.h> | 37 | #include <stdlib.h> |
38 | 38 | ||
39 | typedef struct | ||
40 | { | ||
41 | char *title; | ||
42 | char *artist; | ||
43 | char *album; | ||
44 | char *year; | ||
45 | char *comment; | ||
46 | const char *genre; | ||
47 | unsigned int track_number; | ||
48 | } id3tag; | ||
49 | |||
50 | static const char *const genre_names[] = { | ||
51 | gettext_noop ("Blues"), | ||
52 | gettext_noop ("Classic Rock"), | ||
53 | gettext_noop ("Country"), | ||
54 | gettext_noop ("Dance"), | ||
55 | gettext_noop ("Disco"), | ||
56 | gettext_noop ("Funk"), | ||
57 | gettext_noop ("Grunge"), | ||
58 | gettext_noop ("Hip-Hop"), | ||
59 | gettext_noop ("Jazz"), | ||
60 | gettext_noop ("Metal"), | ||
61 | gettext_noop ("New Age"), | ||
62 | gettext_noop ("Oldies"), | ||
63 | gettext_noop ("Other"), | ||
64 | gettext_noop ("Pop"), | ||
65 | gettext_noop ("R&B"), | ||
66 | gettext_noop ("Rap"), | ||
67 | gettext_noop ("Reggae"), | ||
68 | gettext_noop ("Rock"), | ||
69 | gettext_noop ("Techno"), | ||
70 | gettext_noop ("Industrial"), | ||
71 | gettext_noop ("Alternative"), | ||
72 | gettext_noop ("Ska"), | ||
73 | gettext_noop ("Death Metal"), | ||
74 | gettext_noop ("Pranks"), | ||
75 | gettext_noop ("Soundtrack"), | ||
76 | gettext_noop ("Euro-Techno"), | ||
77 | gettext_noop ("Ambient"), | ||
78 | gettext_noop ("Trip-Hop"), | ||
79 | gettext_noop ("Vocal"), | ||
80 | gettext_noop ("Jazz+Funk"), | ||
81 | gettext_noop ("Fusion"), | ||
82 | gettext_noop ("Trance"), | ||
83 | gettext_noop ("Classical"), | ||
84 | gettext_noop ("Instrumental"), | ||
85 | gettext_noop ("Acid"), | ||
86 | gettext_noop ("House"), | ||
87 | gettext_noop ("Game"), | ||
88 | gettext_noop ("Sound Clip"), | ||
89 | gettext_noop ("Gospel"), | ||
90 | gettext_noop ("Noise"), | ||
91 | gettext_noop ("Alt. Rock"), | ||
92 | gettext_noop ("Bass"), | ||
93 | gettext_noop ("Soul"), | ||
94 | gettext_noop ("Punk"), | ||
95 | gettext_noop ("Space"), | ||
96 | gettext_noop ("Meditative"), | ||
97 | gettext_noop ("Instrumental Pop"), | ||
98 | gettext_noop ("Instrumental Rock"), | ||
99 | gettext_noop ("Ethnic"), | ||
100 | gettext_noop ("Gothic"), | ||
101 | gettext_noop ("Darkwave"), | ||
102 | gettext_noop ("Techno-Industrial"), | ||
103 | gettext_noop ("Electronic"), | ||
104 | gettext_noop ("Pop-Folk"), | ||
105 | gettext_noop ("Eurodance"), | ||
106 | gettext_noop ("Dream"), | ||
107 | gettext_noop ("Southern Rock"), | ||
108 | gettext_noop ("Comedy"), | ||
109 | gettext_noop ("Cult"), | ||
110 | gettext_noop ("Gangsta Rap"), | ||
111 | gettext_noop ("Top 40"), | ||
112 | gettext_noop ("Christian Rap"), | ||
113 | gettext_noop ("Pop/Funk"), | ||
114 | gettext_noop ("Jungle"), | ||
115 | gettext_noop ("Native American"), | ||
116 | gettext_noop ("Cabaret"), | ||
117 | gettext_noop ("New Wave"), | ||
118 | gettext_noop ("Psychedelic"), | ||
119 | gettext_noop ("Rave"), | ||
120 | gettext_noop ("Showtunes"), | ||
121 | gettext_noop ("Trailer"), | ||
122 | gettext_noop ("Lo-Fi"), | ||
123 | gettext_noop ("Tribal"), | ||
124 | gettext_noop ("Acid Punk"), | ||
125 | gettext_noop ("Acid Jazz"), | ||
126 | gettext_noop ("Polka"), | ||
127 | gettext_noop ("Retro"), | ||
128 | gettext_noop ("Musical"), | ||
129 | gettext_noop ("Rock & Roll"), | ||
130 | gettext_noop ("Hard Rock"), | ||
131 | gettext_noop ("Folk"), | ||
132 | gettext_noop ("Folk/Rock"), | ||
133 | gettext_noop ("National Folk"), | ||
134 | gettext_noop ("Swing"), | ||
135 | gettext_noop ("Fast-Fusion"), | ||
136 | gettext_noop ("Bebob"), | ||
137 | gettext_noop ("Latin"), | ||
138 | gettext_noop ("Revival"), | ||
139 | gettext_noop ("Celtic"), | ||
140 | gettext_noop ("Bluegrass"), | ||
141 | gettext_noop ("Avantgarde"), | ||
142 | gettext_noop ("Gothic Rock"), | ||
143 | gettext_noop ("Progressive Rock"), | ||
144 | gettext_noop ("Psychedelic Rock"), | ||
145 | gettext_noop ("Symphonic Rock"), | ||
146 | gettext_noop ("Slow Rock"), | ||
147 | gettext_noop ("Big Band"), | ||
148 | gettext_noop ("Chorus"), | ||
149 | gettext_noop ("Easy Listening"), | ||
150 | gettext_noop ("Acoustic"), | ||
151 | gettext_noop ("Humour"), | ||
152 | gettext_noop ("Speech"), | ||
153 | gettext_noop ("Chanson"), | ||
154 | gettext_noop ("Opera"), | ||
155 | gettext_noop ("Chamber Music"), | ||
156 | gettext_noop ("Sonata"), | ||
157 | gettext_noop ("Symphony"), | ||
158 | gettext_noop ("Booty Bass"), | ||
159 | gettext_noop ("Primus"), | ||
160 | gettext_noop ("Porn Groove"), | ||
161 | gettext_noop ("Satire"), | ||
162 | gettext_noop ("Slow Jam"), | ||
163 | gettext_noop ("Club"), | ||
164 | gettext_noop ("Tango"), | ||
165 | gettext_noop ("Samba"), | ||
166 | gettext_noop ("Folklore"), | ||
167 | gettext_noop ("Ballad"), | ||
168 | gettext_noop ("Power Ballad"), | ||
169 | gettext_noop ("Rhythmic Soul"), | ||
170 | gettext_noop ("Freestyle"), | ||
171 | gettext_noop ("Duet"), | ||
172 | gettext_noop ("Punk Rock"), | ||
173 | gettext_noop ("Drum Solo"), | ||
174 | gettext_noop ("A Cappella"), | ||
175 | gettext_noop ("Euro-House"), | ||
176 | gettext_noop ("Dance Hall"), | ||
177 | gettext_noop ("Goa"), | ||
178 | gettext_noop ("Drum & Bass"), | ||
179 | gettext_noop ("Club-House"), | ||
180 | gettext_noop ("Hardcore"), | ||
181 | gettext_noop ("Terror"), | ||
182 | gettext_noop ("Indie"), | ||
183 | gettext_noop ("BritPop"), | ||
184 | gettext_noop ("Negerpunk"), | ||
185 | gettext_noop ("Polsk Punk"), | ||
186 | gettext_noop ("Beat"), | ||
187 | gettext_noop ("Christian Gangsta Rap"), | ||
188 | gettext_noop ("Heavy Metal"), | ||
189 | gettext_noop ("Black Metal"), | ||
190 | gettext_noop ("Crossover"), | ||
191 | gettext_noop ("Contemporary Christian"), | ||
192 | gettext_noop ("Christian Rock"), | ||
193 | gettext_noop ("Merengue"), | ||
194 | gettext_noop ("Salsa"), | ||
195 | gettext_noop ("Thrash Metal"), | ||
196 | gettext_noop ("Anime"), | ||
197 | gettext_noop ("JPop"), | ||
198 | gettext_noop ("Synthpop"), | ||
199 | }; | ||
200 | |||
201 | #define GENRE_NAME_COUNT \ | ||
202 | ((unsigned int)(sizeof genre_names / sizeof (const char *const))) | ||
203 | |||
204 | |||
205 | #define MAX_MP3_SCAN_DEEP 16768 | 39 | #define MAX_MP3_SCAN_DEEP 16768 |
206 | const int max_frames_scan = 1024; | 40 | const int max_frames_scan = 1024; |
207 | enum | 41 | enum |
@@ -270,64 +104,15 @@ static const char * const layer_names[3] = { | |||
270 | #define SYSERR 1 | 104 | #define SYSERR 1 |
271 | #define INVALID_ID3 2 | 105 | #define INVALID_ID3 2 |
272 | 106 | ||
273 | static void | ||
274 | trim (char *k) | ||
275 | { | ||
276 | while ((strlen (k) > 0) && (isspace (k[strlen (k) - 1]))) | ||
277 | k[strlen (k) - 1] = '\0'; | ||
278 | } | ||
279 | |||
280 | static int | ||
281 | get_id3 (const char *data, size_t size, id3tag * id3) | ||
282 | { | ||
283 | const char *pos; | ||
284 | |||
285 | if (size < 128) | ||
286 | return INVALID_ID3; | ||
287 | |||
288 | pos = &data[size - 128]; | ||
289 | if (0 != strncmp ("TAG", pos, 3)) | ||
290 | return INVALID_ID3; | ||
291 | pos += 3; | ||
292 | |||
293 | id3->title = EXTRACTOR_common_convert_to_utf8 (pos, 30, "ISO-8859-1"); | ||
294 | trim (id3->title); | ||
295 | pos += 30; | ||
296 | id3->artist = EXTRACTOR_common_convert_to_utf8 (pos, 30, "ISO-8859-1"); | ||
297 | trim (id3->artist); | ||
298 | pos += 30; | ||
299 | id3->album = EXTRACTOR_common_convert_to_utf8 (pos, 30, "ISO-8859-1"); | ||
300 | trim (id3->album); | ||
301 | pos += 30; | ||
302 | id3->year = EXTRACTOR_common_convert_to_utf8 (pos, 4, "ISO-8859-1"); | ||
303 | trim (id3->year); | ||
304 | pos += 4; | ||
305 | id3->comment = EXTRACTOR_common_convert_to_utf8 (pos, 30, "ISO-8859-1"); | ||
306 | trim (id3->comment); | ||
307 | if ( (pos[28] == '\0') && | ||
308 | (pos[29] != '\0') ) | ||
309 | { | ||
310 | /* ID3v1.1 */ | ||
311 | id3->track_number = pos[29]; | ||
312 | } | ||
313 | else | ||
314 | { | ||
315 | id3->track_number = 0; | ||
316 | } | ||
317 | pos += 30; | ||
318 | id3->genre = ""; | ||
319 | if (pos[0] < GENRE_NAME_COUNT) | ||
320 | id3->genre = dgettext (PACKAGE, genre_names[(unsigned) pos[0]]); | ||
321 | return OK; | ||
322 | } | ||
323 | |||
324 | |||
325 | #define ADDR(s,t) do { if (0 != proc (proc_cls, "mp3", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1)) return 1; } while (0) | 107 | #define ADDR(s,t) do { if (0 != proc (proc_cls, "mp3", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1)) return 1; } while (0) |
326 | 108 | ||
327 | static int | 109 | /* mimetype = audio/mpeg */ |
328 | mp3parse (const unsigned char *data, size_t size, | 110 | int |
329 | EXTRACTOR_MetaDataProcessor proc, | 111 | EXTRACTOR_mp3_extract (const unsigned char *data, |
330 | void *proc_cls) | 112 | size_t size, |
113 | EXTRACTOR_MetaDataProcessor proc, | ||
114 | void *proc_cls, | ||
115 | const char *options) | ||
331 | { | 116 | { |
332 | unsigned int header; | 117 | unsigned int header; |
333 | int counter = 0; | 118 | int counter = 0; |
@@ -474,50 +259,4 @@ mp3parse (const unsigned char *data, size_t size, | |||
474 | return 0; | 259 | return 0; |
475 | } | 260 | } |
476 | 261 | ||
477 | |||
478 | #define ADD(s,t) do { if (0 != (ret = proc (proc_cls, "mp3", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1))) goto FINISH; } while (0) | ||
479 | |||
480 | |||
481 | /* mimetype = audio/mpeg */ | ||
482 | int | ||
483 | EXTRACTOR_mp3_extract (const char *data, | ||
484 | size_t size, | ||
485 | EXTRACTOR_MetaDataProcessor proc, | ||
486 | void *proc_cls, | ||
487 | const char *options) | ||
488 | { | ||
489 | id3tag info; | ||
490 | char track[16]; | ||
491 | int ret; | ||
492 | |||
493 | if (0 != get_id3 (data, size, &info)) | ||
494 | return 0; | ||
495 | if (strlen (info.title) > 0) | ||
496 | ADD (info.title, EXTRACTOR_METATYPE_TITLE); | ||
497 | if (strlen (info.artist) > 0) | ||
498 | ADD (info.artist, EXTRACTOR_METATYPE_ARTIST); | ||
499 | if (strlen (info.album) > 0) | ||
500 | ADD (info.album, EXTRACTOR_METATYPE_ALBUM); | ||
501 | if (strlen (info.year) > 0) | ||
502 | ADD (info.year, EXTRACTOR_METATYPE_PUBLICATION_YEAR); | ||
503 | if (strlen (info.genre) > 0) | ||
504 | ADD (info.genre, EXTRACTOR_METATYPE_GENRE); | ||
505 | if (strlen (info.comment) > 0) | ||
506 | ADD (info.comment, EXTRACTOR_METATYPE_COMMENT); | ||
507 | if (info.track_number != 0) | ||
508 | { | ||
509 | snprintf(track, | ||
510 | sizeof(track), "%u", info.track_number); | ||
511 | ADD (track, EXTRACTOR_METATYPE_TRACK_NUMBER); | ||
512 | } | ||
513 | ret = mp3parse ((const unsigned char *) data, size, proc, proc_cls); | ||
514 | FINISH: | ||
515 | free (info.title); | ||
516 | free (info.year); | ||
517 | free (info.album); | ||
518 | free (info.artist); | ||
519 | free (info.comment); | ||
520 | return ret; | ||
521 | } | ||
522 | |||
523 | /* end of mp3_extractor.c */ | 262 | /* end of mp3_extractor.c */ |