libextractor

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

commit aafe569d51be89c6d59b72a71fb97e674cd8a7a3
parent f63594c7e4f61eb1d11ed292c0fcf2f589718429
Author: Toni Ruottu <toni.ruottu@helsinki.fi>
Date:   Fri, 10 Nov 2006 21:41:11 +0000

Added nsf support.

Diffstat:
MAUTHORS | 1+
MChangeLog | 3+++
MNEWS | 3+++
Msrc/main/extractor.c | 3++-
Msrc/plugins/Makefile.am | 8++++++++
Asrc/plugins/nsfextractor.c | 160+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 177 insertions(+), 1 deletion(-)

diff --git a/AUTHORS b/AUTHORS @@ -33,6 +33,7 @@ thumbnailqt - Nils Durner <durner@gnunet.org> exiv2 - Andreas Huggel <ahuggel@gmx.net> language - Roberto Cappuccio <roberto.cappuccio@gmail.com> (from libkat) word - Ariya Hidayat <ariya@kde.org> and Sacha Fuentes <mandelman@iname.com> +nsf - Toni Ruottu <toni.ruottu@iki.fi> General contributors: Yuri N. Sedunov <aris@altlinux.ru> diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,6 @@ +Sat Nov 11 00:04:34 EET 2006 + Added a NSF ( NES Sound Format ) plugin + Sat Sep 16 12:36:42 MDT 2006 Added support for various additional tags to ID3v2 extractors. Now (again) trimming whitespace at the end of ID3v1 tags. diff --git a/NEWS b/NEWS @@ -1,3 +1,6 @@ +Sat Nov 11 00:04:34 EET 2006 + Added a NSF ( NES Sound Format ) plugin + Tue Apr 18 14:44:37 PDT 2006 Added dictionaries for Finnish, French, Gaelic and Swedish (for printable extractors). diff --git a/src/main/extractor.c b/src/main/extractor.c @@ -234,7 +234,8 @@ libextractor_riff:\ libextractor_mpeg:\ libextractor_elf:\ libextractor_oo:\ -libextractor_asf" +libextractor_asf:\ +libextractor_nsf" #define DEFAULT_LIBRARIES EXSO OLESO OGGSO QTSO DEFSO diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am @@ -73,6 +73,7 @@ plugin_LTLIBRARIES = $(pdfplugin) \ libextractor_mime.la \ libextractor_mp3.la \ $(extrampeg) \ + libextractor_nsf.la \ $(extraogg) \ libextractor_png.la \ libextractor_ps.la \ @@ -291,6 +292,13 @@ libextractor_filename_la_LIBADD = \ $(top_builddir)/src/main/libextractor.la \ libconvert.la +libextractor_nsf_la_SOURCES = \ + nsfextractor.c +libextractor_nsf_la_LDFLAGS = \ + $(PLUGINFLAGS) $(retaincommand) +libextractor_nsf_la_LIBADD = \ + $(top_builddir)/src/main/libextractor.la + libextractor_split_la_SOURCES = \ splitextractor.c libextractor_split_la_LDFLAGS = \ diff --git a/src/plugins/nsfextractor.c b/src/plugins/nsfextractor.c @@ -0,0 +1,160 @@ +/* + This file is part of libextractor. + (C) 2006 Toni Ruottu + + libextractor is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + libextractor is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libextractor; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +#include "platform.h" +#include "extractor.h" +#include "convert.h" + + +static struct EXTRACTOR_Keywords * +addkword(EXTRACTOR_KeywordList *oldhead, + const char * phrase, + EXTRACTOR_KeywordType type) { + EXTRACTOR_KeywordList * keyword; + + keyword = malloc(sizeof(EXTRACTOR_KeywordList)); + keyword->next = oldhead; + keyword->keyword = strdup(phrase); + keyword->keywordType = type; + return keyword; +} + + +/* "extract" keyword from a Nes Sound Format file + * + * NSF specification version 1.61 was used, + * while this piece of software was originally + * written. + * + * */ +struct EXTRACTOR_Keywords * +libextractor_nsf_extract(const char * filename, + char * data, + size_t size, + struct EXTRACTOR_Keywords * prev) { + int i; + char name[32]; + char artist[32]; + char copyright[32]; + char songs[32]; + char startingsong[32]; + + + /* Check header size and "magic" id bytes */ + + if + ( + size < 0x80 || + data[0] != 'N' || + data[1] != 'E' || + data[2] != 'S' || + data[3] != 'M' || + data[4] != 0x1a + ) + { + return prev; + } + + + /* Mime-type */ + + prev = addkword(prev, "audio/x-nsf", EXTRACTOR_MIMETYPE); + + + /* Version of NSF format */ + + sprintf( startingsong, "NSF version: %d", data[5] ); + prev = addkword(prev, startingsong, EXTRACTOR_UNKNOWN); + + + /* Get song count */ + + sprintf( songs, "total songs: %d", data[6] ); + prev = addkword(prev, songs, EXTRACTOR_UNKNOWN); + + + /* Get number of the first song to be played */ + + sprintf( startingsong, "starting song: %d", data[7] ); + prev = addkword(prev, startingsong, EXTRACTOR_UNKNOWN); + + + /* Parse name, artist, copyright fields */ + + for( i = 0; i < 32; i++ ) + { + name[i] = data[ 0x0e + i ]; + artist[i] = data[ 0x2e + i ]; + copyright[i] = data[ 0x4e + i ]; + } + + prev = addkword(prev, name, EXTRACTOR_TITLE); + prev = addkword(prev, artist, EXTRACTOR_ARTIST); + prev = addkword(prev, copyright, EXTRACTOR_COPYRIGHT); + + + /* PAL or NTSC */ + + if( data[0x7a] & 2 ) + { + prev = addkword(prev, "a dual PAL/NTSC tune", EXTRACTOR_UNKNOWN); + } + else + { + if( data[0x7a] & 1 ) + { + prev = addkword(prev, "a PAL tune", EXTRACTOR_UNKNOWN); + } + else + { + prev = addkword(prev, "an NTSC tune", EXTRACTOR_UNKNOWN); + } + } + + + /* Detect Extra Sound Chips needed to play the files */ + + if( data[0x7b] & 1 ) + { + prev = addkword(prev, "uses VRCVI", EXTRACTOR_UNKNOWN); + } + if( data[0x7b] & 2 ) + { + prev = addkword(prev, "uses VRCVII", EXTRACTOR_UNKNOWN); + } + if( data[0x7b] & 4 ) + { + prev = addkword(prev, "uses FDS Sound", EXTRACTOR_UNKNOWN); + } + if( data[0x7b] & 8 ) + { + prev = addkword(prev, "uses MMC5 audio", EXTRACTOR_UNKNOWN); + } + if( data[0x7b] & 16 ) + { + prev = addkword(prev, "uses Namco 106", EXTRACTOR_UNKNOWN); + } + if( data[0x7b] & 32 ) + { + prev = addkword(prev, "uses Sunsoft FME-07", EXTRACTOR_UNKNOWN); + } + + return prev; +}