xm_extractor.c (3069B)
1 /* 2 * This file is part of libextractor. 3 * Copyright (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 3, 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., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 * 20 */ 21 /** 22 * @file plugins/xm_extractor.c 23 * @brief plugin to support XM files 24 * @author Toni Ruottu 25 * @author Christian Grothoff 26 */ 27 #include "platform.h" 28 #include "extractor.h" 29 30 31 /** 32 * Header of an XM file. 33 */ 34 struct Header 35 { 36 char magicid[17]; 37 char title[20]; 38 char something[1]; 39 char tracker[20]; 40 char version[2]; 41 }; 42 43 44 /** 45 * Give meta data to LE. 46 * 47 * @param s utf-8 string meta data value 48 * @param t type of the meta data 49 */ 50 #define ADD(s,t) do { if (0 != ec->proc (ec->cls, "xm", t, \ 51 EXTRACTOR_METAFORMAT_UTF8, \ 52 "text/plain", s, strlen (s) \ 53 + 1)) return; \ 54 } while (0) 55 56 57 /** 58 * "extract" metadata from an Extended Module 59 * 60 * The XM module format description for XM files 61 * version $0104 that was written by Mr.H of Triton 62 * in 1994 was used, while this piece of software 63 * was originally written. 64 * 65 * @param ec extraction context 66 */ 67 void 68 EXTRACTOR_xm_extract_method (struct EXTRACTOR_ExtractContext *ec); 69 70 void 71 EXTRACTOR_xm_extract_method (struct EXTRACTOR_ExtractContext *ec) 72 { 73 void *data; 74 const struct Header *head; 75 char title[21]; 76 char tracker[21]; 77 char xmversion[8]; 78 size_t n; 79 80 if ((ssize_t) sizeof (struct Header) > 81 ec->read (ec->cls, 82 &data, 83 sizeof (struct Header))) 84 return; 85 head = data; 86 /* Check "magic" id bytes */ 87 if (memcmp (head->magicid, "Extended Module: ", 17)) 88 return; 89 ADD ("audio/x-xm", EXTRACTOR_METATYPE_MIMETYPE); 90 /* Version of Tracker */ 91 snprintf (xmversion, 92 sizeof (xmversion), 93 "%u.%u", 94 head->version[1], 95 head->version[0]); 96 ADD (xmversion, EXTRACTOR_METATYPE_FORMAT_VERSION); 97 /* Song title */ 98 memcpy (&title, head->title, 20); 99 n = 19; 100 while ( (n > 0) && isspace ((unsigned char) title[n])) 101 n--; 102 title[n + 1] = '\0'; 103 ADD (title, EXTRACTOR_METATYPE_TITLE); 104 /* software used for creating the data */ 105 memcpy (&tracker, head->tracker, 20); 106 n = 19; 107 while ( (n > 0) && isspace ((unsigned char) tracker[n])) 108 n--; 109 tracker[n + 1] = '\0'; 110 ADD (tracker, EXTRACTOR_METATYPE_CREATED_BY_SOFTWARE); 111 return; 112 } 113 114 115 /* end of xm_extractor.c */