diff options
Diffstat (limited to 'src/plugins/xm_extractor.c')
-rw-r--r-- | src/plugins/xm_extractor.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/plugins/xm_extractor.c b/src/plugins/xm_extractor.c new file mode 100644 index 0000000..d8e0829 --- /dev/null +++ b/src/plugins/xm_extractor.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | * This file is part of libextractor. | ||
3 | * (C) 2008, 2009 Toni Ruottu | ||
4 | * | ||
5 | * libextractor is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published | ||
7 | * by the Free Software Foundation; either version 2, or (at your | ||
8 | * option) any later version. | ||
9 | * | ||
10 | * libextractor is distributed in the hope that it will be useful, but | ||
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with libextractor; see the file COPYING. If not, write to the | ||
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | * Boston, MA 02111-1307, USA. | ||
19 | * | ||
20 | */ | ||
21 | |||
22 | #include "platform.h" | ||
23 | #include "extractor.h" | ||
24 | #include "convert.h" | ||
25 | |||
26 | #define HEADER_SIZE 64 | ||
27 | |||
28 | struct header | ||
29 | { | ||
30 | char magicid[17]; | ||
31 | char title[20]; | ||
32 | char something[1]; | ||
33 | char tracker[20]; | ||
34 | char version[2]; | ||
35 | }; | ||
36 | |||
37 | #define ADD(s,t) do { if (0 != proc (proc_cls, "xm", t, EXTRACTOR_METAFORMAT_UTF8, "text/plain", s, strlen(s)+1)) return 1; } while (0) | ||
38 | |||
39 | |||
40 | /* "extract" keyword from an Extended Module | ||
41 | * | ||
42 | * The XM module format description for XM files | ||
43 | * version $0104 that was written by Mr.H of Triton | ||
44 | * in 1994 was used, while this piece of software | ||
45 | * was originally written. | ||
46 | * | ||
47 | */ | ||
48 | int | ||
49 | EXTRACTOR_xm_extract (const unsigned char *data, | ||
50 | size_t size, | ||
51 | EXTRACTOR_MetaDataProcessor proc, | ||
52 | void *proc_cls, | ||
53 | const char *options) | ||
54 | { | ||
55 | char title[21]; | ||
56 | char tracker[21]; | ||
57 | char xmversion[8]; | ||
58 | const struct header *head; | ||
59 | |||
60 | /* Check header size */ | ||
61 | if (size < HEADER_SIZE) | ||
62 | return 0; | ||
63 | head = (const struct header *) data; | ||
64 | /* Check "magic" id bytes */ | ||
65 | if (memcmp (head->magicid, "Extended Module: ", 17)) | ||
66 | return 0; | ||
67 | ADD("audio/x-xm", EXTRACTOR_METATYPE_MIMETYPE); | ||
68 | /* Version of Tracker */ | ||
69 | snprintf (xmversion, | ||
70 | sizeof(xmversion), | ||
71 | "%d.%d", | ||
72 | head->version[1], | ||
73 | head->version[0]); | ||
74 | ADD (xmversion, EXTRACTOR_METATYPE_FORMAT_VERSION); | ||
75 | /* Song title */ | ||
76 | memcpy (&title, head->title, 20); | ||
77 | title[20] = '\0'; | ||
78 | ADD (title, EXTRACTOR_METATYPE_TITLE); | ||
79 | /* software used for creating the data */ | ||
80 | memcpy (&tracker, head->tracker, 20); | ||
81 | tracker[20] = '\0'; | ||
82 | ADD (tracker, EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE); | ||
83 | return 0; | ||
84 | } | ||