libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

it_extractor.c (3239B)


      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/it_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
     66 EXTRACTOR_it_extract_method (struct EXTRACTOR_ExtractContext *ec);
     67 
     68 void
     69 EXTRACTOR_it_extract_method (struct EXTRACTOR_ExtractContext *ec)
     70 {
     71   void *data;
     72   char title[27];
     73   char itversion[8];
     74   const struct Header *head;
     75 
     76   if ((ssize_t) HEADER_SIZE >
     77       ec->read (ec->cls,
     78                 &data,
     79                 HEADER_SIZE))
     80     return;
     81   head = (struct Header *) data;
     82   /* Check "magic" id bytes */
     83   if (memcmp (head->magicid, "IMPM", 4))
     84     return;
     85   /* Mime-type */
     86   if (0 != ec->proc (ec->cls,
     87                      "it",
     88                      EXTRACTOR_METATYPE_MIMETYPE,
     89                      EXTRACTOR_METAFORMAT_UTF8,
     90                      "text/plain",
     91                      "audio/x-mod",
     92                      strlen ("audio/x-mod") + 1))
     93     return;
     94 
     95   /* Version of Tracker */
     96   snprintf (itversion,
     97             sizeof (itversion),
     98             "%d.%d",
     99             (head->version[0] & 0x01),
    100             head->version[1]);
    101   if (0 != ec->proc (ec->cls,
    102                      "it",
    103                      EXTRACTOR_METATYPE_FORMAT_VERSION,
    104                      EXTRACTOR_METAFORMAT_C_STRING,
    105                      "text/plain",
    106                      itversion,
    107                      strlen (itversion) + 1))
    108     return;
    109 
    110   /* Song title */
    111   memcpy (&title, head->title, 26);
    112   title[26] = '\0';
    113   if (0 != ec->proc (ec->cls,
    114                      "it",
    115                      EXTRACTOR_METATYPE_TITLE,
    116                      EXTRACTOR_METAFORMAT_C_STRING,
    117                      "text/plain",
    118                      title,
    119                      strlen (title) + 1))
    120     return;
    121 }
    122 
    123 
    124 /* end of it_extractor.c */