libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

it_extractor.c
Go to the documentation of this file.
1 /*
2  * This file is part of libextractor.
3  * Copyright (C) 2008 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 Impulse Tracker (IT) files
24  * @author Toni Ruottu
25  * @author Christian Grothoff
26  */
27 #include "platform.h"
28 #include "extractor.h"
29 
30 
31 /**
32  * Number of bytes in the full IT header and thus
33  * the minimum size we're going to accept for an IT file.
34  */
35 #define HEADER_SIZE 0xD0
36 
37 
38 /**
39  * Header of an IT file.
40  */
41 struct Header
42 {
43  char magicid[4];
44  char title[26];
45  char hilight[2];
46  char orders[2];
47  char instruments[2];
48  char samples[2];
49  char patterns[2];
50  char version[2];
51  char compatible[2];
52  char flags[2];
53  char special[2];
54 };
55 
56 
57 /**
58  * extract meta data from an Impulse Tracker module
59  *
60  * ITTECH.TXT as taken from IT 2.14p5 was used, while this piece of
61  * software was originally written.
62  *
63  * @param ec extraction context
64  */
65 void
67 {
68  void *data;
69  char title[27];
70  char itversion[8];
71  const struct Header *head;
72 
73  if ((ssize_t) HEADER_SIZE >
74  ec->read (ec->cls,
75  &data,
76  HEADER_SIZE))
77  return;
78  head = (struct Header *) data;
79  /* Check "magic" id bytes */
80  if (memcmp (head->magicid, "IMPM", 4))
81  return;
82  /* Mime-type */
83  if (0 != ec->proc (ec->cls,
84  "it",
87  "text/plain",
88  "audio/x-mod",
89  strlen ("audio/x-mod") + 1))
90  return;
91 
92  /* Version of Tracker */
93  snprintf (itversion,
94  sizeof (itversion),
95  "%d.%d",
96  (head->version[0] & 0x01),
97  head->version[1]);
98  if (0 != ec->proc (ec->cls,
99  "it",
102  "text/plain",
103  itversion,
104  strlen (itversion) + 1))
105  return;
106 
107  /* Song title */
108  memcpy (&title, head->title, 26);
109  title[26] = '\0';
110  if (0 != ec->proc (ec->cls,
111  "it",
114  "text/plain",
115  title,
116  strlen (title) + 1))
117  return;
118 }
119 
120 
121 /* end of it_extractor.c */
@ EXTRACTOR_METAFORMAT_C_STRING
Definition: extractor.h:113
@ EXTRACTOR_METAFORMAT_UTF8
Definition: extractor.h:102
@ EXTRACTOR_METATYPE_FORMAT_VERSION
Definition: extractor.h:191
@ EXTRACTOR_METATYPE_TITLE
Definition: extractor.h:134
@ EXTRACTOR_METATYPE_MIMETYPE
Definition: extractor.h:129
#define HEADER_SIZE
Definition: it_extractor.c:35
void EXTRACTOR_it_extract_method(struct EXTRACTOR_ExtractContext *ec)
Definition: it_extractor.c:66
plaform specifics
EXTRACTOR_MetaDataProcessor proc
Definition: extractor.h:525
ssize_t(* read)(void *cls, void **data, size_t size)
Definition: extractor.h:494
char patterns[2]
Definition: it_extractor.c:49
char special[2]
Definition: it_extractor.c:53
char compatible[2]
Definition: it_extractor.c:51
char title[26]
Definition: it_extractor.c:44
char magicid[4]
Definition: it_extractor.c:43
char version[2]
Definition: it_extractor.c:50
char instruments[2]
Definition: it_extractor.c:47
char flags[2]
Definition: it_extractor.c:52
char samples[2]
Definition: it_extractor.c:48
char orders[2]
Definition: it_extractor.c:46
char hilight[2]
Definition: it_extractor.c:45