Mercurial > audlegacy
changeset 1238:dc6f7048a9fa trunk
[svn] - remove metatag entirely
author | nenolod |
---|---|
date | Wed, 14 Jun 2006 22:41:05 -0700 |
parents | 17630223d25b |
children | 8a2d526864c2 |
files | ChangeLog Plugins/General/scrobbler/Makefile.in Plugins/General/scrobbler/tags/ape.c Plugins/General/scrobbler/tags/cdaudio.c Plugins/General/scrobbler/tags/id3genres.c Plugins/General/scrobbler/tags/id3v1.c Plugins/General/scrobbler/tags/id3v2.c Plugins/General/scrobbler/tags/include/ape.h Plugins/General/scrobbler/tags/include/cdaudio.h Plugins/General/scrobbler/tags/include/endian.h Plugins/General/scrobbler/tags/include/id3v1.h Plugins/General/scrobbler/tags/include/id3v2.h Plugins/General/scrobbler/tags/include/itunes.h Plugins/General/scrobbler/tags/include/tags.h Plugins/General/scrobbler/tags/include/unicode.h Plugins/General/scrobbler/tags/include/vorbis.h Plugins/General/scrobbler/tags/include/wma.h Plugins/General/scrobbler/tags/itunes.c Plugins/General/scrobbler/tags/tags.c Plugins/General/scrobbler/tags/unicode.c Plugins/General/scrobbler/tags/vorbis.c Plugins/General/scrobbler/tags/wma.c |
diffstat | 22 files changed, 10 insertions(+), 3882 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Jun 14 22:39:13 2006 -0700 +++ b/ChangeLog Wed Jun 14 22:41:05 2006 -0700 @@ -1,3 +1,12 @@ +2006-06-15 05:39:13 +0000 William Pitcock <nenolod@nenolod.net> + revision [1388] + - if a PlaylistEntry does not have a cached tuple, generate it on demand. + + + Changes: Modified: + +6 -0 trunk/audacious/playlist.c + + 2006-06-15 05:30:04 +0000 William Pitcock <nenolod@nenolod.net> revision [1386] - disconnect the scrobbler client from metatag logically
--- a/Plugins/General/scrobbler/Makefile.in Wed Jun 14 22:39:13 2006 -0700 +++ b/Plugins/General/scrobbler/Makefile.in Wed Jun 14 22:41:05 2006 -0700 @@ -21,21 +21,8 @@ md5.c \ queue.c \ scrobbler.c \ - xmms_scrobbler.c \ - tags/tags.c \ - tags/id3v1.c \ - tags/id3v2.c \ - tags/id3genres.c \ - tags/ape.c \ - tags/cdaudio.c \ - tags/itunes.c \ - tags/unicode.c \ - tags/vorbis.c \ - tags/wma.c + xmms_scrobbler.c CFLAGS += -fPIC -DPIC $(GTK_CFLAGS) $(BEEP_DEFINES) $(CURL_CFLAGS) -I../../../intl -I../../.. OBJECTS = ${SOURCES:.c=.o} - -clean-posthook: - @rm -f tags/*.o
--- a/Plugins/General/scrobbler/tags/ape.c Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,187 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "include/ape.h" -#include "include/endian.h" -#include "../fmt.h" -#include "../config.h" -#include "include/unicode.h" -#define BUFFER_SIZE 4096 - -static ape_t *readItems(VFSFile *fp, int version) -{ - ape_t *ape = calloc(sizeof(ape_t), 1); - unsigned char *tag_buffer = NULL, *bp, cToInt[4]; - int size, start; - unsigned int i; - - ape->version = version; - - /* - * Now for the actual reading. - * APE2 and APE1 tags are identical for all the structure we care about. - */ - - vfs_fread(cToInt, 1, 4, fp); - size = le2int(cToInt); - vfs_fread(cToInt, 1, 4, fp); - ape->numitems = le2int(cToInt); - /* pdebug(fmt_vastr("tag size: %d", size)); - pdebug(fmt_vastr("items: %d", ape->numitems)); */ - vfs_fread(cToInt, 1, 4, fp); - /* Is it a footer? Header? */ - if((cToInt[3] & 0x20) == 0x0 || version == 1000) - start = 8 - size; - else - start = 8; - vfs_fseek(fp, start, SEEK_CUR); - - tag_buffer = realloc(tag_buffer, size); - vfs_fread(tag_buffer, 1, size, fp); - bp = tag_buffer; - - ape->items = realloc(ape->items, - (ape->numitems) * sizeof(apefielddata_t *)); - - for(i = 0; i < ape->numitems && strncmp((char*)bp, "APETAGEX", 8) != 0; i++) - { - apefielddata_t *field = calloc(sizeof(apefielddata_t), 1); - - memcpy(cToInt, bp, 4); - bp += 8; - field->len = le2int(cToInt); - field->name = (unsigned char*)strdup((char*)bp); - bp += strlen((char*)bp) + 1; - field->data = malloc(field->len + 1); - memcpy(field->data, bp, field->len); - *(field->data + field->len) = '\0'; - bp += field->len; - - ape->items[i] = field; - } - if(i < ape->numitems && strncmp((char*)bp, "APETAGEX", 8) == 0) - { - ape->numitems = i; - ape->items = realloc(ape->items, - (ape->numitems) * sizeof(apefielddata_t *)); - } - - - free(tag_buffer); - - return ape; -} - -int findAPE(VFSFile *fp) -{ - unsigned char *tag_buffer, *bp, cToInt[4]; - int pb = 0, status = 0, pos = 0, i, ape_version; - - /* Find the tag header or footer and point the file pointer there. */ - tag_buffer = malloc(BUFFER_SIZE); - pb += vfs_fread(tag_buffer, 1, BUFFER_SIZE, fp); - bp = tag_buffer; - while(status == 0) - { - for(i = 0; i < BUFFER_SIZE - 8 && status == 0; i++) - { - bp++; - if(!strncmp((char*)bp, "APETAGEX", 8)) - status = 1; - } - if(status == 1 || vfs_feof(fp)) - break; - memmove(tag_buffer, tag_buffer + BUFFER_SIZE - 7, 7); - pos += BUFFER_SIZE - 7; - pb += vfs_fread(tag_buffer + 7, 1, BUFFER_SIZE - 7, fp); - bp = tag_buffer; - } - if(status == 1) - { - vfs_fseek(fp, pos + (bp - tag_buffer) + 8, SEEK_SET); - - free(tag_buffer); - - /* Get the tag version. */ - vfs_fread(cToInt, 1, 4, fp); - ape_version = le2int(cToInt); - pdebug(ape_version == 1000 ? "Found APE1 tag..." : - ape_version == 2000 ? "Found APE2 tag..." : - "Found unknown APE tag...", META_DEBUG); - - return ape_version; - } - else - { - free(tag_buffer); - return 0; - } -} - -ape_t *readAPE(char *filename) -{ - VFSFile *fp; - ape_t *ape; - int status; - - fp = vfs_fopen(filename, "r"); - - if(!fp) - { - pdebug("Couldn't open file!", META_DEBUG); - return NULL; - } - - vfs_fseek(fp, 0, SEEK_SET); - - pdebug("Searching for tag...", META_DEBUG); - status = findAPE(fp); - if(status == 0) - { - vfs_fclose(fp); - return NULL; - } - ape = readItems(fp, status); - - vfs_fclose(fp); - - return ape; -} - -void freeAPE(ape_t *ape) -{ - unsigned int i; - - for(i = 0; i < ape->numitems; i++) - { - apefielddata_t *field; - - field = ape->items[i]; - free(field->name); - free(field->data); - free(field); - } - free(ape->items); - free(ape); -}
--- a/Plugins/General/scrobbler/tags/cdaudio.c Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,150 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <musicbrainz/mb_c.h> -#include "include/cdaudio.h" -#include "include/endian.h" -#include "../fmt.h" -#include "../config.h" -#include "include/unicode.h" -#define BUFFER_SIZE 4096 - -#ifdef MAKE_BMP -#include <libaudacious/vfs.h> -#define vfs_fopen vfs_fopen -#define vfs_fclose vfs_fclose -#define vfs_fread vfs_fread -#define vfs_fseek vfs_fseek -#define ftell vfs_ftell -#define VFSFile VFSFile -#endif - -/* - * Determining if a CD is being played is left up to the reader. - * - -int cdaudio_find(char *filename) -{ - We've got to find a way to ensure this works on all platforms. - - return !(fmt_strcasecmp(strrchr(filename, '.') + 1, "cda")); -} -*/ - -cdaudio_t *readCDAudio(char *filename, char track) -{ - int retVal; - musicbrainz_t mb; - char *tmp; - cdaudio_t *musicbrainz = calloc(sizeof(cdaudio_t), 1); - - memset(musicbrainz, 0, sizeof(cdaudio_t)); - - tmp = malloc(BUFFER_SIZE / 4 + 1); - mb = mb_New(); - mb_SetDevice(mb, filename); - pdebug("Submitting query to MusicBrainz...", META_DEBUG); - retVal = mb_Query(mb, MBQ_GetCDInfo); - if(retVal == 0) - { -#ifdef META_DEBUG - char error[129] = ""; - pdebug("ERROR: Query failed.", META_DEBUG); - mb_GetQueryError(mb, error, 128); - pdebug(fmt_vastr("REASON: %s", error), META_DEBUG); -#endif - mb_Delete(mb); - free(tmp); - free(musicbrainz); - return NULL; - } - pdebug("Selecting result...", META_DEBUG); - retVal = mb_Select1(mb, MBS_SelectAlbum, 1); - if(retVal == 0) - { - pdebug("ERROR: Album select failed.", META_DEBUG); - mb_Delete(mb); - free(tmp); - free(musicbrainz); - return NULL; - } - pdebug("Extracting MusicBrainz data from result...", META_DEBUG); - memset(tmp, '\0', BUFFER_SIZE / 4 + 1); - retVal = mb_GetResultData(mb, MBE_AlbumGetAlbumName, tmp, BUFFER_SIZE / 4); - if(retVal == 0) - { - pdebug("ERROR: Album title not found.", META_DEBUG); - musicbrainz->album = calloc(1, 1); - } - else - { - musicbrainz->album = (unsigned char*)strdup(tmp); - } - memset(tmp, '\0', BUFFER_SIZE / 4 + 1); - retVal = mb_GetResultData1(mb, MBE_AlbumGetArtistName, tmp, BUFFER_SIZE / 4, track); - if(retVal == 0) - { - pdebug("ERROR: Artist name not found.", META_DEBUG); - musicbrainz->artist = calloc(1, 1); - } - else - { - musicbrainz->artist = (unsigned char*)strdup(tmp); - } - memset(tmp, '\0', BUFFER_SIZE / 4 + 1); - retVal = mb_GetResultData1(mb, MBE_AlbumGetTrackName, tmp, BUFFER_SIZE / 4, track); - if(retVal == 0) - { - pdebug("ERROR: Track title not found.", META_DEBUG); - musicbrainz->title = calloc(1, 1); - } - else - { - musicbrainz->title = (unsigned char*)strdup(tmp); - } - memset(tmp, '\0', BUFFER_SIZE / 4 + 1); - retVal = mb_GetResultData1(mb, MBE_AlbumGetTrackId, tmp, BUFFER_SIZE / 4, track); - if(retVal == 0) - { - pdebug("ERROR: MBID not found.", META_DEBUG); - musicbrainz->mbid = calloc(1, 1); - } - else - { - musicbrainz->mbid = malloc(64); - mb_GetIDFromURL(mb, tmp, (char*)musicbrainz->mbid, 64); - } - mb_Delete(mb); - free(tmp); - - return musicbrainz; -} - -void freeCDAudio(cdaudio_t *musicbrainz) -{ - free(musicbrainz->mbid); - free(musicbrainz->title); - free(musicbrainz->artist); - free(musicbrainz->album); - free(musicbrainz); -}
--- a/Plugins/General/scrobbler/tags/id3genres.c Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -const char *genre_list[148] = -{ - /* The following genres are defined in ID3v1 */ - "Blues", "Classic Rock", "Country", - "Dance", "Disco", "Funk", - "Grunge", "Hip-Hop", "Jazz", - "Metal", "New Age", "Oldies", - "Other", "Pop", "R&B", - "Rap", "Reggae", "Rock", - "Techno", "Industrial", "Alternative", - "Ska", "Death Metal", "Pranks", - "Soundtrack", "Euro-Techno", "Ambient", - "Trip-Hop", "Vocal", "Jazz+Funk", - "Fusion", "Trance", "Classical", - "Instrumental", "Acid", "House", - "Game", "Sound Clip", "Gospel", - "Noise", "AlternRock", "Bass", - "Soul", "Punk", "Space", - "Meditative", "Instrumental Pop", "Instrumental Rock", - "Ethnic", "Gothic", "Darkwave", - "Techno-Industrial", "Electronic", "Pop-Folk", - "Eurodance", "Dream", "Southern Rock", - "Comedy", "Cult", "Gangsta", - "Top 40", "Christian Rap", "Pop/Funk", - "Jungle", "Native American", "Cabaret", - "New Wave", "Psychedelic", "Rave", - "Showtunes", "Trailer", "Lo-Fi", - "Tribal", "Acid Punk", "Acid Jazz", - "Polka", "Retro", "Musical", - "Rock & Roll", "Hard Rock", - /* The following genres are defined in early versions of Winamp */ - "Folk", "Folk-Rock", "National Folk", - "Swing", "Fast Fusion", "Bebob", - "Latin", "Revival", "Celtic", - "Bluegrass", "Avantgarde", "Gothic Rock", - "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", - "Slow Rock", "Big Band", "Chorus", - "Easy Listening", "Acoustic", "Humour", - "Speech", "Chanson", "Opera", - "Chamber Music", "Sonata", "Symphony", - "Booty Bass", "Primus", "Porn Groove", - "Satire", - /* By Winamp 1.70, the following were added. */ - "Slow Jam", "Club", "Tango", - "Samba", "Folklore", - /* By Winamp 1.90, the following were added. */ - "Ballad", "Power Ballad", "Rhythmic Soul", - "Freestyle", "Duet", "Punk Rock", - "Drum Solo", "A capella", "Euro-House", - "Dance Hall", "Goa", "Drum & Bass", - "Club-House", "Hardcore", "Terror", - "Indie", "BritPop", "Negerpunk", - "Polsk Punk", "Beat", "Christian Gangsta Rap", - "Heavy Metal", "Black Metal", "Crossover", - "Contemporary Christian", "Christian Rock", - /* The following were added in Winamp 1.91 */ - "Merengue", "Salsa", "Trash Metal", - "Anime", "JPop", "SynthPop" -};
--- a/Plugins/General/scrobbler/tags/id3v1.c Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,149 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <libaudacious/vfs.h> -#include "include/id3v1.h" -#include "include/endian.h" -#include "../fmt.h" -#include "../config.h" -#include "include/unicode.h" -#define BUFFER_SIZE 4096 - -static void cleanID3v1(unsigned char *data, size_t size) -{ - int i; - - for(i = size - 1; i > -1; i--) - { - if(data[i] == ' ') data[i] = '\0'; - else break; - } -} - -static void cleanComment(unsigned char *data) -{ - int i; - - for(i = 27; i > -1; i--) - { - if(data[i] == ' ' || data[i] == '\0') data[i] = '\0'; - else break; - } -} - -int findID3v1(VFSFile *fp) -{ - char tag_id[4] = ""; - - vfs_fread(tag_id, 1, 3, fp); - - if(!strncmp(tag_id, "TAG", 3)) - return 1; - else - return 0; -} - -id3v1_t *readID3v1(char *filename) -{ - VFSFile *fp; - id3v1_t *id3v1 = NULL; - int status; - - fp = vfs_fopen(filename, "rb"); - - if(!fp) - { - pdebug("Couldn't open file!", META_DEBUG); - return NULL; - } - - pdebug("Searching for tag...", META_DEBUG); - vfs_fseek(fp, -128, SEEK_END); - status = findID3v1(fp); - if(status) - { - unsigned char *data; - - id3v1 = calloc(sizeof(id3v1_t), 1); - data = malloc(31); - *(data + 30) = '\0'; - vfs_fread(data, 1, 30, fp); - cleanID3v1(data, 30); - // id3v1->title = realloc(id3v1->title, 31); - if(data && *data) - iso88591_to_utf8(data, strlen((char*)data), &id3v1->title); - else - id3v1->title = NULL; - vfs_fread(data, 1, 30, fp); - cleanID3v1(data, 30); - if(data && *data) - iso88591_to_utf8(data, strlen((char*)data), &id3v1->artist); - else - id3v1->artist = NULL; - vfs_fread(data, 1, 30, fp); - cleanID3v1(data, 30); - if(data && *data) - iso88591_to_utf8(data, strlen((char*)data), &id3v1->album); - else - id3v1->album = NULL; - data = realloc(data, 5); - *(data + 4) = '\0'; - vfs_fread(data, 1, 4, fp); - cleanID3v1(data, 4); - if(data && *data) - iso88591_to_utf8(data, strlen((char*)data), &id3v1->year); - else - id3v1->year = NULL; - data = realloc(data, 31); - *(data + 30) = '\0'; - vfs_fread(data, 1, 30, fp); - cleanComment(data); - id3v1->comment = realloc(id3v1->comment, 31); - memset(id3v1->comment, 0, 31); - memcpy(id3v1->comment, data, 30); - if(data[28] == '\0' && data[29] != '\0') - id3v1->track = data[29]; - else - id3v1->track = 255; - free(data); - vfs_fread(&id3v1->genre, 1, 1, fp); - } - - vfs_fclose(fp); - - return id3v1; -} - -void freeID3v1(id3v1_t *id3v1) -{ - if(id3v1->title != NULL) - free(id3v1->title); - if(id3v1->artist != NULL) - free(id3v1->artist); - if(id3v1->album != NULL) - free(id3v1->album); - if(id3v1->year != NULL) - free(id3v1->year); - free(id3v1->comment); - free(id3v1); -}
--- a/Plugins/General/scrobbler/tags/id3v2.c Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,711 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "include/id3v2.h" -#include "include/endian.h" -#include "../fmt.h" -#include "../config.h" -#include "include/unicode.h" -#define BUFFER_SIZE 4096 - -id3_lookup_t id3v22_lookup[] = -{ - {"BUF", ID3V22_BUF}, {"CNT", ID3V22_CNT}, {"COM", ID3V22_COM}, - {"CRA", ID3V22_CRA}, {"CRM", ID3V22_CRM}, {"ETC", ID3V22_ETC}, - {"EQU", ID3V22_EQU}, {"GEO", ID3V22_GEO}, {"IPL", ID3V22_IPL}, - {"LNK", ID3V22_LNK}, {"MCI", ID3V22_MCI}, {"MLL", ID3V22_MLL}, - {"PIC", ID3V22_PIC}, {"POP", ID3V22_POP}, {"REV", ID3V22_REV}, - {"RVA", ID3V22_RVA}, {"SLT", ID3V22_SLT}, {"STC", ID3V22_STC}, - {"TAL", ID3V22_TAL}, {"TBP", ID3V22_TBP}, {"TCM", ID3V22_TCM}, - {"TCO", ID3V22_TCO}, {"TCR", ID3V22_TCR}, {"TDA", ID3V22_TDA}, - {"TDY", ID3V22_TDY}, {"TEN", ID3V22_TEN}, {"TFT", ID3V22_TFT}, - {"TIM", ID3V22_TIM}, {"TKE", ID3V22_TKE}, {"TLA", ID3V22_TLA}, - {"TLE", ID3V22_TLE}, {"TMT", ID3V22_TMT}, {"TOA", ID3V22_TOA}, - {"TOF", ID3V22_TOF}, {"TOL", ID3V22_TOL}, {"TOR", ID3V22_TOR}, - {"TOT", ID3V22_TOT}, {"TP1", ID3V22_TP1}, {"TP2", ID3V22_TP2}, - {"TP3", ID3V22_TP3}, {"TP4", ID3V22_TP4}, {"TPA", ID3V22_TPA}, - {"TPB", ID3V22_TPB}, {"TRC", ID3V22_TRC}, {"TRD", ID3V22_TRD}, - {"TRK", ID3V22_TRK}, {"TSI", ID3V22_TSI}, {"TSS", ID3V22_TSS}, - {"TT1", ID3V22_TT1}, {"TT2", ID3V22_TT2}, {"TT3", ID3V22_TT3}, - {"TXT", ID3V22_TXT}, {"TXX", ID3V22_TXX}, {"TYE", ID3V22_TYE}, - {"UFI", ID3V22_UFI}, {"ULT", ID3V22_ULT}, {"WAF", ID3V22_WAF}, - {"WAR", ID3V22_WAR}, {"WAS", ID3V22_WAS}, {"WCM", ID3V22_WCM}, - {"WCP", ID3V22_WCP}, {"WPB", ID3V22_WPB}, {"WXX", ID3V22_WXX}, - {NULL, -1} -}; - -id3_lookup_t id3v24_lookup[] = -{ - {"AENC", ID3V24_AENC}, {"APIC", ID3V24_APIC}, {"ASPI", ID3V24_ASPI}, - {"COMM", ID3V24_COMM}, {"COMR", ID3V24_COMR}, {"ENCR", ID3V24_ENCR}, - {"EQU2", ID3V24_EQU2}, {"ETCO", ID3V24_ETCO}, {"GEOB", ID3V24_GEOB}, - {"GRID", ID3V24_GRID}, {"LINK", ID3V24_LINK}, {"MCDI", ID3V24_MCDI}, - {"MLLT", ID3V24_MLLT}, {"OWNE", ID3V24_OWNE}, {"PRIV", ID3V24_PRIV}, - {"PCNT", ID3V24_PCNT}, {"POPM", ID3V24_POPM}, {"POSS", ID3V24_POSS}, - {"RBUF", ID3V24_RBUF}, {"RVA2", ID3V24_RVA2}, {"RVRB", ID3V24_RVRB}, - {"SEEK", ID3V24_SEEK}, {"SIGN", ID3V24_SIGN}, {"SYLT", ID3V24_SYLT}, - {"SYTC", ID3V24_SYTC}, {"TALB", ID3V24_TALB}, {"TBPM", ID3V24_TBPM}, - {"TCOM", ID3V24_TCOM}, {"TCON", ID3V24_TCON}, {"TCOP", ID3V24_TCOP}, - {"TDEN", ID3V24_TDEN}, {"TDLY", ID3V24_TDLY}, {"TDOR", ID3V24_TDOR}, - {"TDRC", ID3V24_TDRC}, {"TDRL", ID3V24_TDRL}, {"TDTG", ID3V24_TDTG}, - {"TENC", ID3V24_TENC}, {"TEXT", ID3V24_TEXT}, {"TFLT", ID3V24_TFLT}, - {"TIPL", ID3V24_TIPL}, {"TIT1", ID3V24_TIT1}, {"TIT2", ID3V24_TIT2}, - {"TIT3", ID3V24_TIT3}, {"TKEY", ID3V24_TKEY}, {"TLAN", ID3V24_TLAN}, - {"TLEN", ID3V24_TLEN}, {"TMCL", ID3V24_TMCL}, {"TMED", ID3V24_TMED}, - {"TMOO", ID3V24_TMOO}, {"TOAL", ID3V24_TOAL}, {"TOFN", ID3V24_TOFN}, - {"TOLY", ID3V24_TOLY}, {"TOPE", ID3V24_TOPE}, {"TOWN", ID3V24_TOWN}, - {"TPE1", ID3V24_TPE1}, {"TPE2", ID3V24_TPE2}, {"TPE3", ID3V24_TPE3}, - {"TPE4", ID3V24_TPE4}, {"TPOS", ID3V24_TPOS}, {"TPRO", ID3V24_TPRO}, - {"TPUB", ID3V24_TPUB}, {"TRCK", ID3V24_TRCK}, {"TRSN", ID3V24_TRSN}, - {"TRSO", ID3V24_TRSO}, {"TSOA", ID3V24_TSOA}, {"TSOP", ID3V24_TSOP}, - {"TSOT", ID3V24_TSOT}, {"TSRC", ID3V24_TSRC}, {"TSSE", ID3V24_TSSE}, - {"TSST", ID3V24_TSST}, {"TXXX", ID3V24_TXXX}, {"UFID", ID3V24_UFID}, - {"USER", ID3V24_USER}, {"USLT", ID3V24_USLT}, {"WCOM", ID3V24_WCOM}, - {"WCOP", ID3V24_WCOP}, {"WOAF", ID3V24_WOAF}, {"WOAR", ID3V24_WOAR}, - {"WOAS", ID3V24_WOAS}, {"WORS", ID3V24_WORS}, {"WPAY", ID3V24_WPAY}, - {"WPUB", ID3V24_WPUB}, {"WXXX", ID3V24_WXXX}, {NULL, -1} -}; - -id3_lookup_t id3v23_lookup[] = -{ - {"AENC", ID3V23_AENC}, {"APIC", ID3V23_APIC}, {"COMM", ID3V23_COMM}, - {"COMR", ID3V23_COMR}, {"ENCR", ID3V23_ENCR}, {"EQUA", ID3V23_EQUA}, - {"ETCO", ID3V23_ETCO}, {"GEOB", ID3V23_GEOB}, {"GRID", ID3V23_GRID}, - {"IPLS", ID3V23_IPLS}, {"LINK", ID3V23_LINK}, {"MCDI", ID3V23_MCDI}, - {"MLLT", ID3V23_MLLT}, {"OWNE", ID3V23_OWNE}, {"PRIV", ID3V23_PRIV}, - {"PCNT", ID3V23_PCNT}, {"POPM", ID3V23_POPM}, {"POSS", ID3V23_POSS}, - {"RBUF", ID3V23_RBUF}, {"RVAD", ID3V23_RVAD}, {"RVRB", ID3V23_RVRB}, - {"SYLT", ID3V23_SYLT}, {"SYTC", ID3V23_SYTC}, {"TALB", ID3V23_TALB}, - {"TBPM", ID3V23_TBPM}, {"TCOM", ID3V23_TCOM}, {"TCON", ID3V23_TCON}, - {"TCOP", ID3V23_TCOP}, {"TDAT", ID3V23_TDAT}, {"TDLY", ID3V23_TDLY}, - {"TENC", ID3V23_TENC}, {"TEXT", ID3V23_TEXT}, {"TFLT", ID3V23_TFLT}, - {"TIME", ID3V23_TIME}, {"TIT1", ID3V23_TIT1}, {"TIT2", ID3V23_TIT2}, - {"TIT3", ID3V23_TIT3}, {"TKEY", ID3V23_TKEY}, {"TLAN", ID3V23_TLAN}, - {"TLEN", ID3V23_TLEN}, {"TMED", ID3V23_TMED}, {"TOAL", ID3V23_TOAL}, - {"TOFN", ID3V23_TOFN}, {"TOLY", ID3V23_TOLY}, {"TOPE", ID3V23_TOPE}, - {"TORY", ID3V23_TORY}, {"TOWN", ID3V23_TOWN}, {"TPE1", ID3V23_TPE1}, - {"TPE2", ID3V23_TPE2}, {"TPE3", ID3V23_TPE3}, {"TPE4", ID3V23_TPE4}, - {"TPOS", ID3V23_TPOS}, {"TPUB", ID3V23_TPUB}, {"TRCK", ID3V23_TRCK}, - {"TRDA", ID3V23_TRDA}, {"TRSN", ID3V23_TRSN}, {"TRSO", ID3V23_TRSO}, - {"TSIZ", ID3V23_TSIZ}, {"TSRC", ID3V23_TSRC}, {"TSSE", ID3V23_TSSE}, - {"TYER", ID3V23_TYER}, {"TXXX", ID3V23_TXXX}, {"UFID", ID3V23_UFID}, - {"USER", ID3V23_USER}, {"USLT", ID3V23_USLT}, {"WCOM", ID3V23_WCOM}, - {"WCOP", ID3V23_WCOP}, {"WOAF", ID3V23_WOAF}, {"WOAR", ID3V23_WOAR}, - {"WOAS", ID3V23_WOAS}, {"WORS", ID3V23_WORS}, {"WPAY", ID3V23_WPAY}, - {"WPUB", ID3V23_WPUB}, {"WXXX", ID3V23_WXXX}, {NULL, -1} -}; - - -typedef struct -{ - unsigned char *check; - int count; -} resync_t; - -typedef struct -{ - int unsync, extended, size; - char version[2]; -} id3header_t; - -static resync_t *checkunsync(char *syncCheck, int size) -{ - int i, j; - resync_t *sync; - - sync = malloc(sizeof(resync_t)); - - sync->check = (unsigned char*)syncCheck; - sync->count = 0; - - if(size == 0) - size = strlen((char*)sync->check); - - for(i = 0; i < size; i++) - { - if(sync->check[i] == 0xFF && sync->check[i + 1] == 0x00) - { - for(j = i + 1; j < size - 1; j++) - syncCheck[j] = syncCheck[j + 1]; - sync->check[j] = '\0'; - sync->count++; - } - } - - return sync; -} - -static void unsync(char *data, char *bp) -{ - resync_t *unsynced; - char *syncFix = NULL; - int i; - - unsynced = checkunsync(data, 0); - while(unsynced->count > 0) - { - if(syncFix != NULL) - syncFix = realloc(syncFix, unsynced->count); - else - syncFix = malloc(unsynced->count); - memcpy(syncFix, bp, unsynced->count); - bp += unsynced->count; - for(i = 0; i < unsynced->count; i++) - data[4 - unsynced->count + i] = syncFix[i]; - free(unsynced); - unsynced = checkunsync(data, 0); - } - free(unsynced); - free(syncFix); -} - -/* - * Header: - * - * identifier: 3 bytes "ID3" ("3DI" if footer) - * version: 2 bytes - * flags: 1 byte - * tag size: 4 bytes - */ -static id3header_t *read_header(VFSFile *fp) -{ - id3header_t *id3_data = calloc(sizeof(id3header_t), 1); - char id3_flags, cToInt[4]; - int bottom = 0; - - vfs_fread(cToInt, 1, 3, fp); - if(strncmp(cToInt, "3DI", 3) == 0) - bottom = 1; - vfs_fread(id3_data->version, 1, 2, fp); - vfs_fread(&id3_flags, 1, 1, fp); - if((id3_flags & 0x80) == 0x80) - id3_data->unsync = 1; - if((id3_flags & 0x40) == 0x40 && id3_data->version[0] > 0x02) - id3_data->extended = 1; - vfs_fread(cToInt, 1, 4, fp); - id3_data->size = synchsafe2int(cToInt); - if(bottom == 1) - vfs_fseek(fp, -10 - id3_data->size, SEEK_CUR); - -#ifdef META_DEBUG - if(id3_data->version[0] == 0x04) - { - pdebug("Version: ID3v2.4", META_DEBUG); - } - else if(id3_data->version[0] == 0x03) - { - pdebug("Version: ID3v2.3", META_DEBUG); - } - else if(id3_data->version[0] == 0x02) - { - pdebug("Version: ID3v2.2", META_DEBUG); - } -#endif - if(id3_data->version[0] < 0x02 || id3_data->version[0] > 0x04) - { - free(id3_data); - return NULL; - } - - return id3_data; -} - -static int id3_lookupframe(char *tag, int tagver) -{ - int i; - - switch (tagver) { - case ID3v22: - for (i = 0; id3v22_lookup[i].frameid; i++) - if (!strcmp(tag, id3v22_lookup[i].frameid)) - return id3v22_lookup[i].code; - return -1; - break; - case ID3v23: - for (i = 0; id3v23_lookup[i].frameid; i++) - if (!strcmp(tag, id3v23_lookup[i].frameid)) - return id3v23_lookup[i].code; - return -1; - break; - case ID3v24: - for (i = 0; id3v23_lookup[i].frameid; i++) - if (!strcmp(tag, id3v24_lookup[i].frameid)) - return id3v24_lookup[i].code; - return -1; - break; - } - return -1; -} - -static framedata_t *parseFrame(char **bp, char *end, id3header_t *id3_data) -{ - static unsigned char frameid[5]; - unsigned char frameflags[2] = "", cToInt[5]; - int framesize, frameidcode; - framedata_t *framedata; - - /* TODO: Unsync, decompress, decrypt, grouping, data length */ - switch (id3_data->version[0]) { - case 2: - if (end - *bp < 6) - return NULL; - frameid[3] = 0; - memcpy(frameid, *bp, 3); - *bp += 3; - frameidcode = id3_lookupframe((char*)frameid, ID3v22); - memcpy(cToInt, *bp, 3); - cToInt[3] = 0; - if(id3_data->unsync) - unsync((char*)cToInt, *bp); - framesize = be24int(cToInt); - *bp += 3; - break; - case 3: - if (end - *bp < 10) - return NULL; - frameid[4] = 0; - memcpy(frameid, *bp, 4); - *bp += 4; - frameidcode = id3_lookupframe((char*)frameid, ID3v23); - memcpy(cToInt, *bp, 4); - if(id3_data->unsync) - unsync((char*)cToInt, *bp); - framesize = be2int(cToInt); - *bp += 4; - - memcpy(frameflags, *bp, 2); - *bp += 2; - break; - case 4: - if (end - *bp < 10) - return NULL; - frameid[4] = 0; - memcpy(frameid, *bp, 4); - *bp += 4; - frameidcode = id3_lookupframe((char*)frameid, ID3v24); - memcpy(cToInt, *bp, 4); - framesize = synchsafe2int(cToInt); - *bp += 4; - - memcpy(frameflags, *bp, 2); - *bp += 2; - break; - default: - /* Should not be reached */ - return NULL; - } - - /* printf("found id:%s, size:%-8d\n", frameid, framesize); */ - if (framesize > end - *bp) - return NULL; - framedata = calloc(sizeof(framedata_t), 1); - framedata->frameid = frameidcode; - if(id3_data->unsync) - frameflags[1] |= 0x02; - framedata->flags = malloc(2); - memcpy(framedata->flags, frameflags, 2); - if(id3_data->version[0] == 0x04) - { - /* - * 4 bytes extra for compression or original size - * 1 byte extra for encyption - * 1 byte extra for grouping - */ - if((frameflags[1] & 0x08) == 0x08 || - (frameflags[1] & 0x01) == 0x01) - { - *bp += 4; - framesize -= 4; - } - if((frameflags[1] & 0x04) == 0x04) - { - (*bp)++; - framesize--; - } - if((frameflags[1] & 0x40) == 0x40) - { - (*bp)++; - framesize--; - } - } - else if(id3_data->version[0] == 0x03) - { - /* - * 4 bytes extra for compression or original size - * 1 byte extra for encyption - * 1 byte extra for grouping - */ - if((frameflags[1] & 0x80) == 0x80) - { - char tmp[4]; - - memcpy(tmp, *bp, 4); - *bp += 4; - if((frameflags[1] & 0x02) == 0x02) - unsync(tmp, *bp); - framesize -= 4; - } - if((frameflags[1] & 0x40) == 0x40) - { - (*bp)++; - framesize--; - } - if((frameflags[1] & 0x20) == 0x20) - { - (*bp)++; - framesize--; - } - } - framedata->len = framesize; - framedata->data = malloc(framesize); - memcpy(framedata->data, *bp, framesize); - *bp += framesize; - - /* Parse text appropriately to UTF-8. */ - if(frameid[0] == 'T' && strcmp((char*)frameid, "TXXX") && - strcmp((char*)frameid, "TXX")) - { - unsigned char *ptr, *data = NULL, *utf = NULL; - int encoding; - - ptr = framedata->data; - - if(framedata->len == 0) - { - framedata->data = realloc(framedata->data, 1); - framedata->data[0] = '\0'; - return framedata; - } - - encoding = *(ptr++); - data = realloc(data, framedata->len); - *(data + framedata->len - 1) = '\0'; - memcpy(data, ptr, framedata->len - 1); - if((framedata->flags[1] & 0x02) == 0x02) - { - resync_t *unsync = checkunsync((char*)data, framedata->len); - framedata->len -= unsync->count; - free(unsync); - } - if(encoding == 0x00) - { - if(utf != NULL) - free(utf); - iso88591_to_utf8(data, framedata->len - 1, &utf); - } - else if(encoding == 0x01) - { - if(utf != NULL) - free(utf); - utf16bom_to_utf8(data, framedata->len - 1, &utf); - } - else if(encoding == 0x02) - { - if(utf != NULL) - free(utf); - utf16be_to_utf8(data, framedata->len - 1, &utf); - } - else if(encoding == 0x03) - { - utf = realloc(utf, framedata->len); - strcpy((char*)utf, (char*)data); - } - - if (utf == NULL) - return framedata; - - framedata->len = strlen((char*)utf) + 1; - framedata->data = realloc(framedata->data, framedata->len); - strcpy((char*)framedata->data, (char*)utf); - framedata->data[framedata->len - 1] = '\0'; - free(utf); - free(data); - } - /* Or unsync. */ - else - { - unsigned char *data = NULL, *ptr; - - ptr = framedata->data; - - data = realloc(data, framedata->len); - // *(data + framedata->len - 1) = '\0'; - memcpy(data, ptr, framedata->len); - if((framedata->flags[1] & 0x02) == 0x02) - { - resync_t *unsync = checkunsync((char*)data, framedata->len); - framedata->len -= unsync->count; - free(unsync); - } - framedata->data = realloc(framedata->data, framedata->len); - memcpy(framedata->data, data, framedata->len); - free(data); - } - - return framedata; -} - -static id3v2_t *readFrames(char *bp, char *end, id3header_t *id3_data) -{ - id3v2_t *id3v2 = calloc(sizeof(id3v2_t), 1); - - while(bp < end) - { - framedata_t *framedata = NULL; - - if(*bp == '\0') - break; - - framedata = parseFrame(&bp, end, id3_data); - - id3v2->items = realloc(id3v2->items, (id3v2->numitems + 1) * - sizeof(framedata_t *)); - id3v2->items[id3v2->numitems++] = framedata; - } - id3v2->version = id3_data->version[0]; - - return id3v2; -} - -/*unsigned char *ID3v2_parseText(framedata_t *frame) -{ - unsigned char *data = NULL, *utf = NULL, *ptr; - char encoding; - - ptr = frame->data; - - encoding = *(ptr++); - data = realloc(data, frame->len); - memset(data, '\0', frame->len); - memcpy(data, ptr, frame->len - 1); - if((frame->flags[1] & 0x02) == 0x02) - { - resync_t *unsync = checkunsync(data, 0); - free(unsync); - } - if(encoding == 0x00) - { - if(utf != NULL) - free(utf); - iso88591_to_utf8(data, &utf); - } - else if(encoding == 0x01) - { - if(utf != NULL) - free(utf); - utf16bom_to_utf8(data, frame->len - 1, &utf); - } - else if(encoding == 0x02) - { - if(utf != NULL) - free(utf); - utf16be_to_utf8(data, frame->len - 1, &utf); - } - else if(encoding == 0x03) - { - utf = realloc(utf, strlen(data) + 1); - strcpy(utf, data); - } - free(data); - - return utf; -} - -unsigned char *ID3v2_getData(framedata_t *frame) -{ - unsigned char *data = NULL, *ptr; - - ptr = frame->data; - - data = realloc(data, frame->len + 1); - memset(data, '\0', frame->len + 1); - memcpy(data, ptr, frame->len); - if((frame->flags[1] & 0x02) == 0x02) - { - resync_t *unsync = checkunsync(data, frame->len); - free(unsync); - } - - return data; -}*/ - -int findID3v2(VFSFile *fp) -{ - unsigned char tag_buffer[BUFFER_SIZE], *bp = tag_buffer; - int pos, search = -1, i, status = 0, charsRead; - - charsRead = vfs_fread(tag_buffer, 1, 10, fp); - pos = 0; - bp = tag_buffer; - while(status == 0 && !vfs_feof(fp)) - { - if(search == -1) - { - if((strncmp((char*)bp, "ID3", 3) == 0 || - strncmp((char*)bp, "3DI", 3) == 0)) - status = 1; - else - { - vfs_fseek(fp, 3, SEEK_END); - charsRead = vfs_fread(tag_buffer, 1, 3, fp); - search = -2; - } - } - else - { - if(search == -2) - { - bp = tag_buffer; - pos = vfs_ftell(fp); - if((strncmp((char*)bp, "ID3", 3) == 0 || - strncmp((char*)bp, "3DI", 3) == 0)) status = 1; - search = 1; - } - if(status != 1) - { - pos = vfs_ftell(fp) - BUFFER_SIZE; - vfs_fseek(fp, pos, SEEK_SET); - charsRead = vfs_fread(tag_buffer, 1, BUFFER_SIZE, - fp); - - bp = tag_buffer; - for(i = 0; i < charsRead - 3 && status == 0; - i++) - { - bp++; - if((strncmp((char*)bp, "ID3", 3) == 0 || - strncmp((char*)bp, "3DI", 3) == 0)) - status = 1; - } - if(status == 1) - pos += bp - tag_buffer; - pos -= BUFFER_SIZE - 9; - if((pos < -BUFFER_SIZE + 9 || vfs_feof(fp)) && - status != 1) - status = -1; - } - } - /* - * An ID3v2 tag can be detected with the following pattern: - * - * $49 44 33 yy yy xx zz zz zz zz - * - * Where yy is less than $FF, xx is the 'flags' byte and zz is - * less than $80. - */ - if(status == 1 && *(bp + 3) < 0xFF && *(bp + 4) < 0xFF && - *(bp + 6) < 0x80 && *(bp + 7) < 0x80 && - *(bp + 8) < 0x80 && *(bp + 9) < 0x80) - status = 1; - else if(status != -1) - status = 0; - if(search == 0) - search = -1; - } - if(status < 0 || vfs_feof(fp)) - return -1; - else - return pos; -} - -id3v2_t *readID3v2(char *filename) -{ - VFSFile *fp; - id3v2_t *id3v2 = NULL; - int pos; - - fp = vfs_fopen(filename, "rb"); - - if(!fp) - { - pdebug("Couldn't open file!", META_DEBUG); - return NULL; - } - - vfs_fseek(fp, 0, SEEK_SET); - - pdebug("Searching for tag...", META_DEBUG); - pos = findID3v2(fp); - if(pos > -1) - { - id3header_t *id3_data; - char *tag_buffer, *bp; - - /* Found the tag. */ - vfs_fseek(fp, pos, SEEK_SET); - pdebug("Found ID3v2 tag...", META_DEBUG); - /* Read the header */ - id3_data = read_header(fp); - if(id3_data == NULL) - { - pdebug("Or not.", META_DEBUG); - vfs_fclose(fp); - return NULL; - } - /* Read tag into buffer */ - tag_buffer = malloc(id3_data->size); - vfs_fread(tag_buffer, 1, id3_data->size, fp); - bp = tag_buffer; - /* Skip extended header */ - if(id3_data->extended) - { - char cToInt[4]; - - memcpy(cToInt, bp, 4); - bp += 4; - if(id3_data->version[0] == 0x03 && - id3_data->unsync == 1) - unsync(cToInt, bp); - if(id3_data->version[0] > 0x03) - bp += synchsafe2int(cToInt); - else - bp += be2int(cToInt); - } - /* Read frames into id3v2_t */ - id3v2 = readFrames(bp, tag_buffer + id3_data->size, id3_data); - - free(tag_buffer); - free(id3_data); - } - - vfs_fclose(fp); - - return id3v2; -} - -void freeID3v2(id3v2_t *id3v2) -{ - int i; - - for(i = 0; i < id3v2->numitems; i++) - { - framedata_t *frame; - - frame = id3v2->items[i]; - free(frame->flags); - free(frame->data); - free(frame); - } - free(id3v2->items); - free(id3v2); -}
--- a/Plugins/General/scrobbler/tags/include/ape.h Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef APE_H -#define APE_H 1 - -#include <libaudacious/vfs.h> - - -typedef struct -{ - unsigned int len; - unsigned char *data, *name; -} apefielddata_t; - -typedef struct -{ - unsigned int numitems, version; - apefielddata_t **items; -} ape_t; - -#ifndef MAKE_BMP -int findAPE(VFSFile *); -#else -int findAPE(VFSFile *); -#endif -ape_t *readAPE(char *); -void freeAPE(ape_t *); -#endif
--- a/Plugins/General/scrobbler/tags/include/cdaudio.h Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef CDAUDIO_H -#define CDAUDIO_H 1 - -typedef struct -{ - unsigned char *title, *artist, *album, *mbid; -} cdaudio_t; - -cdaudio_t *readCDAudio(char *, char); -void freeCDAudio(cdaudio_t *); -#endif
--- a/Plugins/General/scrobbler/tags/include/endian.h Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * libmetatag: - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef ENDIAN_H -#define ENDIAN_H 1 -#define le2long(le) (le2long_internal(((unsigned char *)(le)))) -#define le2long_internal(le) \ -((le[0] << 0) | (le[1] << 8) | (le[2] << 16) | (le[3] << 24) \ -(le[4] << 32) | (le[5] << 40) | (le[6] << 48) | (le[7] << 56)) -#define le2int(le) (le2int_internal(((unsigned char *)(le)))) -#define le2int_internal(le) \ -((le[0] << 0) | (le[1] << 8) | (le[2] << 16) | (le[3] << 24)) -#define le2short(le) (le2short_internal(((unsigned char *)(le)))) -#define le2short_internal(le) \ -((le[0] << 0) | (le[1] << 8)) -#define be2int(be) (be2int_internal(((unsigned char *)(be)))) -#define be2int_internal(be) \ -((be[3] << 0) | (be[2] << 8) | (be[1] << 16) | (be[0] << 24)) -#define be24int(be) (be24int_internal(((unsigned char *)(be)))) -#define be24int_internal(be) \ -((be[2] << 0) | (be[1] << 8) | (be[0] << 16)) -#define be2short(be) (be2short_internal(((unsigned char *)(be)))) -#define be2short_internal(be) \ -((be[1] << 0) | (be[0] << 8)) -#define flac2int(flac) (flac2int_internal(((unsigned char *)(flac)))) -#define flac2int_internal(flac) \ -((flac[1] << 16) | (flac[2] << 8) | (flac[3] << 0)) -#define synchsafe2int(synch) (synchsafe2int_internal(((unsigned char *)(synch)))) -#define synchsafe2int_internal(synch) \ -((synch[0] << 21) | (synch[1] << 14) | \ -(synch[2] << 7) | (synch[3] << 0)) -#define tagid2int(bp) be2int(bp) -#endif -
--- a/Plugins/General/scrobbler/tags/include/id3v1.h Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef ID3V1_H -#define ID3V1_H 1 - -typedef struct -{ - unsigned char *title, *artist, *album, *year, *comment, track, genre; -} id3v1_t; - -#ifndef MAKE_BMP -int findID3v1(VFSFile *); -#else -int findID3v1(VFSFile *); -#endif -id3v1_t *readID3v1(char *); -void freeID3v1(id3v1_t *); -#endif
--- a/Plugins/General/scrobbler/tags/include/id3v2.h Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef ID3V2_H -#define ID3V2_H 1 - -#include <libaudacious/vfs.h> - -typedef struct -{ - int frameid, len; - unsigned char *data, *flags; -} framedata_t; - -typedef struct -{ - int numitems, version; - framedata_t **items; -} id3v2_t; - -typedef struct -{ - char *frameid; - int code; -} id3_lookup_t; - -enum -{ - ID3v22, - ID3v23, - ID3v24 -}; - -enum -{ - ID3V24_AENC, ID3V24_APIC, ID3V24_ASPI, ID3V24_COMM, ID3V24_COMR, - ID3V24_ENCR, ID3V24_EQU2, ID3V24_ETCO, ID3V24_GEOB, ID3V24_GRID, - ID3V24_LINK, ID3V24_MCDI, ID3V24_MLLT, ID3V24_OWNE, ID3V24_PRIV, - ID3V24_PCNT, ID3V24_POPM, ID3V24_POSS, ID3V24_RBUF, ID3V24_RVA2, - ID3V24_RVRB, ID3V24_SEEK, ID3V24_SIGN, ID3V24_SYLT, ID3V24_SYTC, - ID3V24_TALB, ID3V24_TBPM, ID3V24_TCOM, ID3V24_TCON, ID3V24_TCOP, - ID3V24_TDEN, ID3V24_TDLY, ID3V24_TDOR, ID3V24_TDRC, ID3V24_TDRL, - ID3V24_TDTG, ID3V24_TENC, ID3V24_TEXT, ID3V24_TFLT, ID3V24_TIPL, - ID3V24_TIT1, ID3V24_TIT2, ID3V24_TIT3, ID3V24_TKEY, ID3V24_TLAN, - ID3V24_TLEN, ID3V24_TMCL, ID3V24_TMED, ID3V24_TMOO, ID3V24_TOAL, - ID3V24_TOFN, ID3V24_TOLY, ID3V24_TOPE, ID3V24_TOWN, ID3V24_TPE1, - ID3V24_TPE2, ID3V24_TPE3, ID3V24_TPE4, ID3V24_TPOS, ID3V24_TPRO, - ID3V24_TPUB, ID3V24_TRCK, ID3V24_TRSN, ID3V24_TRSO, ID3V24_TSOA, - ID3V24_TSOP, ID3V24_TSOT, ID3V24_TSRC, ID3V24_TSSE, ID3V24_TSST, - ID3V24_TXXX, ID3V24_UFID, ID3V24_USER, ID3V24_USLT, ID3V24_WCOM, - ID3V24_WCOP, ID3V24_WOAF, ID3V24_WOAR, ID3V24_WOAS, ID3V24_WORS, - ID3V24_WPAY, ID3V24_WPUB, ID3V24_WXXX -}; - -enum -{ - ID3V22_BUF, ID3V22_CNT, ID3V22_COM, ID3V22_CRA, ID3V22_CRM, ID3V22_ETC, - ID3V22_EQU, ID3V22_GEO, ID3V22_IPL, ID3V22_LNK, ID3V22_MCI, ID3V22_MLL, - ID3V22_PIC, ID3V22_POP, ID3V22_REV, ID3V22_RVA, ID3V22_SLT, ID3V22_STC, - ID3V22_TAL, ID3V22_TBP, ID3V22_TCM, ID3V22_TCO, ID3V22_TCR, ID3V22_TDA, - ID3V22_TDY, ID3V22_TEN, ID3V22_TFT, ID3V22_TIM, ID3V22_TKE, ID3V22_TLA, - ID3V22_TLE, ID3V22_TMT, ID3V22_TOA, ID3V22_TOF, ID3V22_TOL, ID3V22_TOR, - ID3V22_TOT, ID3V22_TP1, ID3V22_TP2, ID3V22_TP3, ID3V22_TP4, ID3V22_TPA, - ID3V22_TPB, ID3V22_TRC, ID3V22_TRD, ID3V22_TRK, ID3V22_TSI, ID3V22_TSS, - ID3V22_TT1, ID3V22_TT2, ID3V22_TT3, ID3V22_TXT, ID3V22_TXX, ID3V22_TYE, - ID3V22_UFI, ID3V22_ULT, ID3V22_WAF, ID3V22_WAR, ID3V22_WAS, ID3V22_WCM, - ID3V22_WCP, ID3V22_WPB, ID3V22_WXX -}; - -enum -{ - ID3V23_AENC, ID3V23_APIC, ID3V23_COMM, ID3V23_COMR, ID3V23_ENCR, - ID3V23_EQUA, ID3V23_ETCO, ID3V23_GEOB, ID3V23_GRID, ID3V23_IPLS, - ID3V23_LINK, ID3V23_MCDI, ID3V23_MLLT, ID3V23_OWNE, ID3V23_PRIV, - ID3V23_PCNT, ID3V23_POPM, ID3V23_POSS, ID3V23_RBUF, ID3V23_RVAD, - ID3V23_RVRB, ID3V23_SYLT, ID3V23_SYTC, ID3V23_TALB, ID3V23_TBPM, - ID3V23_TCOM, ID3V23_TCON, ID3V23_TCOP, ID3V23_TDAT, ID3V23_TDLY, - ID3V23_TENC, ID3V23_TEXT, ID3V23_TFLT, ID3V23_TIME, ID3V23_TIT1, - ID3V23_TIT2, ID3V23_TIT3, ID3V23_TKEY, ID3V23_TLAN, ID3V23_TLEN, - ID3V23_TMED, ID3V23_TOAL, ID3V23_TOFN, ID3V23_TOLY, ID3V23_TOPE, - ID3V23_TORY, ID3V23_TOWN, ID3V23_TPE1, ID3V23_TPE2, ID3V23_TPE3, - ID3V23_TPE4, ID3V23_TPOS, ID3V23_TPUB, ID3V23_TRCK, ID3V23_TRDA, - ID3V23_TRSN, ID3V23_TRSO, ID3V23_TSIZ, ID3V23_TSRC, ID3V23_TSSE, - ID3V23_TYER, ID3V23_TXXX, ID3V23_UFID, ID3V23_USER, ID3V23_USLT, - ID3V23_WCOM, ID3V23_WCOP, ID3V23_WOAF, ID3V23_WOAR, ID3V23_WOAS, - ID3V23_WORS, ID3V23_WPAY, ID3V23_WPUB, ID3V23_WXXX -}; - - -unsigned char *ID3v2_parseText(framedata_t *); -unsigned char *ID3v2_getData(framedata_t *); -#ifndef MAKE_BMP -int findID3v2(VFSFile *); -#else -int findID3v2(VFSFile *); -#endif -id3v2_t *readID3v2(char *); -void freeID3v2(id3v2_t *); -#endif
--- a/Plugins/General/scrobbler/tags/include/itunes.h Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef ITUNES_H -#define ITUNES_H 1 - -#include <libaudacious/vfs.h> - -typedef struct -{ - unsigned char *title, *artist, *album, *genre, *year, *copyright, - track, maxtrack, disc, maxdisc; -} itunes_t; - -#ifndef MAKE_BMP -int findiTunes(VFSFile *); -#else -int findiTunes(VFSFile *); -#endif -itunes_t *readiTunes(char *); -void freeiTunes(itunes_t *); -#endif
--- a/Plugins/General/scrobbler/tags/include/tags.h Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef METATAGS_H -#define METATAGS_H 1 - -#include <libaudacious/vfs.h> - -#include "wma.h" -#include "id3v2.h" -#include "id3v1.h" -#include "vorbis.h" -#include "itunes.h" -#include "ape.h" -#include "cdaudio.h" - -extern const char *genre_list[148]; - -/* - * Note: This struct has some signs to determine what tags a file has - * and it is left to the program to interpret them. The main unsigned chars - * are merely used as references directly to something in one of the substructs. - * - */ - -typedef struct { - unsigned char *artist, - *title, - *mb, - *album, - *year, - *track, - *genre; - int has_wma, - has_id3v1, - has_id3v2, - has_ape, - has_vorbis, - has_flac, - has_oggflac, - has_speex, - has_itunes, - has_cdaudio, - prefer_ape; - wma_t *wma; - id3v1_t *id3v1; - id3v2_t *id3v2; - ape_t *ape; - vorbis_t *vorbis, - *flac, - *oggflac, - *speex; - itunes_t *itunes; - cdaudio_t *cdaudio; -} metatag_t; - -void get_tag_data(metatag_t *, char *, int); -metatag_t *metatag_new(void); -void metatag_delete(metatag_t *); -#endif
--- a/Plugins/General/scrobbler/tags/include/unicode.h Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef UNICODE_H -#define UNICODE_H 1 -wchar_t *utf8_to_wchar(unsigned char *, size_t); -unsigned char *wchar_to_utf8(wchar_t *, size_t); -void iso88591_to_utf8(unsigned char *, size_t, unsigned char **); -void utf16bom_to_utf8(unsigned char *, size_t, unsigned char **); -void utf16be_to_utf8(unsigned char *, size_t, unsigned char **); -void utf16le_to_utf8(unsigned char *, size_t, unsigned char **); -#endif
--- a/Plugins/General/scrobbler/tags/include/vorbis.h Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef VORBIS_H -#define VORBIS_H 1 - -#include <libaudacious/vfs.h> - -#define READ_VORBIS 1 -#define READ_FLAC 2 -#define READ_OGGFLAC 3 -#define READ_SPEEX 4 - -typedef struct -{ - unsigned int len; - unsigned char *data, *name; -} vorbisfielddata_t; - -typedef struct -{ - unsigned int numitems, vendorlen; - unsigned char *vendor; - vorbisfielddata_t **items; -} vorbis_t; - -#ifndef MAKE_BMP -int findVorbis(VFSFile *); -int findFlac(VFSFile *); -int findOggFlac(VFSFile *); -int findSpeex(VFSFile *); -#else -int findVorbis(VFSFile *); -int findFlac(VFSFile *); -int findOggFlac(VFSFile *); -int findSpeex(VFSFile *); -#endif -vorbis_t *readVorbis(char *); -vorbis_t *readFlac(char *); -vorbis_t *readOggFlac(char *); -vorbis_t *readSpeex(char *); -void freeVorbis(vorbis_t *); -#endif
--- a/Plugins/General/scrobbler/tags/include/wma.h Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef WMA_H -#define WMA_H 1 - -#include <libaudacious/vfs.h> - -typedef struct -{ - unsigned char *data, *name; - int type; -} attribute_t; - -typedef struct -{ - unsigned int numitems; - attribute_t **items; -} wma_t; - -#ifndef MAKE_BMP -int findWMA(VFSFile *); -#else -int findWMA(VFSFile *); -#endif -wma_t *readWMA(char *); -void freeWMA(wma_t *); -#endif
--- a/Plugins/General/scrobbler/tags/itunes.c Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,303 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "include/itunes.h" -#include "include/endian.h" -#include "../fmt.h" -#include "../config.h" -#include "include/unicode.h" -#define BUFFER_SIZE 4096 -#define NAME_ATOM ((0xa9 << 24) | ('n' << 16) | ('a' << 8) | ('m' << 0)) -#define ARTIST_ATOM ((0xa9 << 24) | ('A' << 16) | ('R' << 8) | ('T' << 0)) -#define ALBUM_ATOM ((0xa9 << 24) | ('a' << 16) | ('l' << 8) | ('b' << 0)) -#define YEAR_ATOM ((0xa9 << 24) | ('d' << 16) | ('a' << 8) | ('y' << 0)) -#define GENRE_ATOM (('g' << 24) | ('n' << 16) | ('r' << 8) | ('e' << 0)) -#define TRACK_ATOM (('t' << 24) | ('r' << 16) | ('k' << 8) | ('n' << 0)) -#define DISC_ATOM (('d' << 24) | ('i' << 16) | ('s' << 8) | ('k' << 0)) -#define COPYRIGHT_ATOM (('c' << 24) | ('p' << 16) | ('r' << 8) | ('t' << 0)) - -static itunes_t *readAtoms(VFSFile *fp) -{ - itunes_t *itunes = calloc(sizeof(itunes_t), 1); - unsigned char *tag_buffer, *bp, cToInt[4]; - int size, meta_size; - - vfs_fread(cToInt, 1, 4, fp); - size = be2int(cToInt) - 4; - tag_buffer = malloc(size); - vfs_fread(tag_buffer, 1, size, fp); - bp = tag_buffer; - bp += 8; - while(bp - tag_buffer < size) - { - unsigned char **tag_data = NULL; - switch(tagid2int(bp)) - { - case NAME_ATOM: - tag_data = &itunes->title; - break; - case ARTIST_ATOM: - tag_data = &itunes->artist; - break; - case ALBUM_ATOM: - tag_data = &itunes->album; - break; - /* - * Genre is weird. I don't know how user input genres - * work. Use at your own risk. Is terminated with an - * extra 0. - */ - case GENRE_ATOM: - tag_data = &itunes->genre; - break; - case YEAR_ATOM: - tag_data = &itunes->year; - break; - case COPYRIGHT_ATOM: - tag_data = &itunes->copyright; - break; - } - if( tagid2int(bp) == NAME_ATOM || - tagid2int(bp) == ARTIST_ATOM || - tagid2int(bp) == ALBUM_ATOM || - tagid2int(bp) == GENRE_ATOM || - tagid2int(bp) == YEAR_ATOM || - tagid2int(bp) == COPYRIGHT_ATOM) - { - bp += 4; - memcpy(cToInt, bp, 4); - meta_size = be2int(cToInt) - 16; - bp += 16; - *tag_data = realloc(*tag_data, meta_size + 1); - *(*tag_data + meta_size) = '\0'; - strncpy((char*)*tag_data, (char*)bp, meta_size); - bp += meta_size; - } - /* - * Track number is easier, but unverified. - * Disc number is similar. Doesn't skip at end though. - * - * Assuming max of what a char can hold. - */ - else if(tagid2int(bp) == TRACK_ATOM || - tagid2int(bp) == DISC_ATOM) - { - unsigned char *tag_num_data, *tag_num_max_data, skip; - if(tagid2int(bp) == TRACK_ATOM) - { - tag_num_data = &itunes->track; - tag_num_max_data = &itunes->maxtrack; - skip = 2; - } - else if(tagid2int(bp) == DISC_ATOM) - { - tag_num_data = &itunes->disc; - tag_num_max_data = &itunes->maxdisc; - skip = 0; - } - bp += 4; - memcpy(cToInt, bp, 4); - meta_size = be2int(cToInt) - 16; - bp += 19; - *tag_num_data = *bp; - bp += 2; - *tag_num_max_data = *bp; - bp += 1 + skip; - } - /* - * TODO: - * - * I'd like to handle rtng (Rating) but I don't know how. - * What are the xxIDs? aART? - * Where is Grouping, BPM, Composer? - * - * In any case, do not handle anything else. - */ - else - { - bp -= 4; - memcpy(cToInt, bp, 4); - meta_size = be2int(cToInt); - bp += meta_size; - } - bp += 4; - } - - free(tag_buffer); - - return itunes; -} - -int findiTunes(VFSFile *fp) -{ - unsigned char *tag_buffer, *bp, cToInt[4], *start_pos; - int parent_size, atom_size, pos = 0; - - /* - * Find the ILST atom and point the file pointer there and return - * the atom size. - * - * Please note that this could easily not work (especially when not - * encoded with iTunes) as this is mainly based off of a reference - * file encoded by iTunes and the QTFileFormat documentation released - * by Apple. It's not based off any official documentation of M4A. - * - * As a result of not being based off official documentation, this is - * EXTREMELY likely to return 0 (i.e. no data found). - * - * First we assume that ftyp is the first atom, and M4A is the type. - */ - vfs_fread(cToInt, 1, 4, fp); - atom_size = be2int(cToInt) - 4; - tag_buffer = malloc(8); - vfs_fread(tag_buffer, 1, 8, fp); - if(strncmp((char*)tag_buffer, "ftypM4A ", 8)) - { - free(tag_buffer); - return -1; - } - vfs_fseek(fp, -8, SEEK_CUR); - tag_buffer = realloc(tag_buffer, atom_size); - vfs_fread(tag_buffer, 1, atom_size, fp); - /* Now keep skipping until we hit a moov container atom */ - while(!vfs_feof(fp)) - { - vfs_fread(cToInt, 1, 4, fp); - atom_size = be2int(cToInt) - 4; - tag_buffer = realloc(tag_buffer, atom_size); - pos = vfs_ftell(fp); - vfs_fread(tag_buffer, 1, atom_size, fp); - if(!strncmp((char*)tag_buffer, "moov", 4)) - break; - } - if(vfs_feof(fp)) - { - free(tag_buffer); - return -1; - } - parent_size = atom_size; - /* Now looking for child udta atom (NOT in trak) */ - bp = tag_buffer + 4; - while(bp - tag_buffer < parent_size) - { - memcpy(cToInt, bp, 4); - atom_size = be2int(cToInt) - 4; - bp += 4; - if(!strncmp((char*)bp, "udta", 4)) - break; - bp += atom_size; - } - if(strncmp((char*)bp, "udta", 4)) - { - free(tag_buffer); - return -1; - } - parent_size = atom_size; - start_pos = bp; - bp += 4; - /* Now looking for child meta atom */ - while(bp - start_pos < parent_size) - { - memcpy(cToInt, bp, 4); - atom_size = be2int(cToInt) - 4; - bp += 4; - if(!strncmp((char*)bp, "meta", 4)) - break; - bp += atom_size; - } - if(strncmp((char*)bp, "meta", 4)) - { - free(tag_buffer); - return -1; - } - parent_size = atom_size; - start_pos = bp; - bp += 8; - /* Now looking for child ilst atom */ - while(bp - start_pos < parent_size) - { - memcpy(cToInt, bp, 4); - atom_size = be2int(cToInt) - 4; - bp += 4; - if(!strncmp((char*)bp, "ilst", 4)) - break; - bp += atom_size; - } - if(strncmp((char*)bp, "ilst", 4)) - { - free(tag_buffer); - return -1; - } - bp -= 4; - vfs_fseek(fp, bp - tag_buffer + pos, SEEK_SET); - - free(tag_buffer); - - return atom_size; -} - -itunes_t *readiTunes(char *filename) -{ - VFSFile *fp; - itunes_t *itunes; - int status; - - fp = vfs_fopen(filename, "r"); - - if(!fp) - { - pdebug("Couldn't open file!", META_DEBUG); - return NULL; - } - - vfs_fseek(fp, 0, SEEK_SET); - - pdebug("Searching for tag...", META_DEBUG); - status = findiTunes(fp); - if(status == -1) - { - vfs_fclose(fp); - return NULL; - } - itunes = readAtoms(fp); - - vfs_fclose(fp); - - return itunes; -} - -void freeiTunes(itunes_t *itunes) -{ - if(itunes->title != NULL) - free(itunes->title); - if(itunes->artist != NULL) - free(itunes->artist); - if(itunes->album != NULL) - free(itunes->album); - if(itunes->year != NULL) - free(itunes->year); - if(itunes->genre != NULL) - free(itunes->genre); - free(itunes); -}
--- a/Plugins/General/scrobbler/tags/tags.c Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,812 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "libaudacious/vfs.h" - -#include "../fmt.h" -#include "../config.h" -#include "include/unicode.h" -#include "include/tags.h" -#include "include/endian.h" - -void tag_exists(metatag_t *meta, char *filename) -{ - VFSFile *fp; - int status = 0; - - /* Check for CD Audio - if(findCDAudio(filename)) - { - pdebug("Found CD Audio...", META_DEBUG); - tags[0] = CD_AUDIO; - - return tags; - }*/ - - fp = vfs_fopen(filename, "r"); - if(!fp) - { - pdebug("Couldn't open file!", META_DEBUG); - - return; - } - - /* Check for ID3v1 */ - vfs_fseek(fp, -128, SEEK_END); - if(findID3v1(fp)) - { - pdebug("Found ID3v1 tag...", META_DEBUG); - meta->has_id3v1 = 1; - } - - /* Check for ID3v2 */ - vfs_fseek(fp, 0, SEEK_SET); - status = findID3v2(fp); - if(status > -1) - { - pdebug("Found ID3v2 tag...", META_DEBUG); - meta->has_id3v2 = 1; - } - status = 0; - - /* Check for Ogg Vorbis */ - vfs_fseek(fp, 0, SEEK_SET); - status = findVorbis(fp); - if(status > -1) - { - pdebug("Found Vorbis comment block...", META_DEBUG); - meta->has_vorbis = 1; - } - status = 0; - - /* Check for FLAC */ - vfs_fseek(fp, 0, SEEK_SET); - if(findFlac(fp)) - { - pdebug("Found FLAC tag...", META_DEBUG); - meta->has_flac = 1; - } - - /* Check for OggFLAC */ - vfs_fseek(fp, 0, SEEK_SET); - status = findOggFlac(fp); - if(status > -1) - { - pdebug("Found OggFLAC...", META_DEBUG); - meta->has_oggflac = 1; - } - status = 0; - - /* Check for Speex */ - vfs_fseek(fp, 0, SEEK_SET); - status = findSpeex(fp); - if(status > -1) - { - pdebug("Found Speex...", META_DEBUG); - meta->has_speex = 1; - } - status = 0; - - /* Check for APE */ - vfs_fseek(fp, 0, SEEK_SET); - status = findAPE(fp); - if(status > 0) - { - pdebug("Found APE tag...", META_DEBUG); - meta->has_ape = 1; - } - status = 0; - - /* Check for iTunes M4A */ - vfs_fseek(fp, 0, SEEK_SET); - status = findiTunes(fp); - if(status > -1) - { - pdebug("Found iTunes tag...", META_DEBUG); - meta->has_itunes = 1; - } - - /* Check for the devil tag: WMA */ - vfs_fseek(fp, 0, SEEK_SET); - status = findWMA(fp); - if(status > -1) - { - pdebug("Found WMA tag...", META_DEBUG); - meta->has_wma = 1; - } - - vfs_fclose(fp); - - return; -} - -void metaCD(metatag_t *meta, char *filename, int track) -{ - int tmp; - - pdebug("Getting CD Audio metadata...", META_DEBUG); - meta->cdaudio = readCDAudio(filename, track); - if(meta->cdaudio == NULL) - { - pdebug("Error getting metadata", META_DEBUG); - - return; - } - - meta->has_cdaudio = 1; - - pdebug("Reading metadata into structs...", META_DEBUG); - meta->artist = meta->cdaudio->artist; - meta->title = meta->cdaudio->title; - meta->mb = realloc(meta->mb, strlen((char*)meta->cdaudio->mbid) + 1); - strcpy((char*)meta->mb, (char*)meta->cdaudio->mbid); - meta->album = meta->cdaudio->album; - meta->year = NULL; - meta->genre = NULL; - /* Special track handling... Yay! */ - meta->track = realloc(meta->track, 4); - tmp = snprintf((char*)meta->track, 3, "%d", track); - *(meta->track + tmp) = '\0'; - - return; -} /* End CD Audio support */ - -static ape_t *fetchAPE(char *filename) -{ - ape_t *ape; - - pdebug("Getting APE tag metadata...", META_DEBUG); - ape = readAPE(filename); - - return ape; -} /* End APE read */ - -void metaAPE(metatag_t *meta) -{ - unsigned int i; - int t = 0; - size_t s; - ape_t *ape = meta->ape; - - for(i = 0; i < ape->numitems; i++) - { - apefielddata_t *item = ape->items[i]; - - if(!strcmp((char*)item->name, "Title")) - { - pdebug("Found Title!", META_DEBUG); - meta->title = item->data; - } - else if(!strcmp((char*)item->name, "Artist")) - { - pdebug("Found Artist!", META_DEBUG); - meta->artist = item->data; - } - else if(strcmp((char*)item->name, "Album") == 0) - { - pdebug("Found Album!", META_DEBUG); - meta->album = item->data; - } - else if(strcmp((char*)item->name, "Year") == 0) - { - pdebug("Found Year!", META_DEBUG); - meta->year = item->data; - } - else if(strcmp((char*)item->name, "Genre") == 0) - { - pdebug("Found Genre!", META_DEBUG); - s = strlen((char*)item->data) + 1; - meta->genre = realloc(meta->genre, s); - memcpy(meta->genre, item->data, s); - } - else if(strcmp((char*)item->name, "Track") == 0) - { - pdebug("Found Track!", META_DEBUG); - s = strlen((char*)item->data) + 1; - meta->track = realloc(meta->genre, s); - memcpy(meta->track, item->data, s); - } - else if(strcmp((char*)item->name, "Comment") == 0) - { - unsigned char *comment_value = NULL, *eq_pos, *sep_pos, - *subvalue; - - subvalue = item->data; - sep_pos = (unsigned char*)strchr((char*)subvalue, '|'); - while(sep_pos != NULL || t == 0) - { - t = 1; - if(sep_pos != NULL) - *sep_pos = '\0'; - s = strlen((char*)subvalue) + 1; - comment_value = realloc(comment_value, s); - memcpy(comment_value, subvalue, s); - if(sep_pos != NULL) - sep_pos++; - eq_pos = (unsigned char*)strchr((char*)comment_value, '='); - if(eq_pos != NULL) - { - *eq_pos = '\0'; - eq_pos++; - if(!strcmp((char*)comment_value, - "musicbrainz_trackid")) - { - /* ??? */ - pdebug("Found MusicBrainz Track ID!", META_DEBUG); - s = strlen((char*)eq_pos) + 1; - meta->mb = realloc(meta->mb, s); - memcpy(meta->mb, eq_pos, s); - break; - } - } - if(sep_pos != NULL) - { - t = 0; - subvalue = sep_pos; - sep_pos = (unsigned char*)strchr((char*)subvalue, '|'); - } - } - t = 0; - if(comment_value != NULL) - free(comment_value); - } - } -} /* End APE parsing */ - -static vorbis_t *fetchVorbis(char *filename, int tag_type) -{ - vorbis_t *comments = NULL; - - /* Several slightly different methods of getting the data... */ - if(tag_type == READ_VORBIS) - { - pdebug("Getting Vorbis comment metadata...", META_DEBUG); - comments = readVorbis(filename); - } - else if(tag_type == READ_FLAC) - { - pdebug("Getting FLAC tag metadata...", META_DEBUG); - comments = readFlac(filename); - } - else if(tag_type == READ_OGGFLAC) - { - pdebug("Getting OggFLAC tag metadata...", META_DEBUG); - comments = readOggFlac(filename); - } - else if(tag_type == READ_SPEEX) - { - pdebug("Getting Speex tag metadata...", META_DEBUG); - comments = readSpeex(filename); - } - if(comments == NULL) - pdebug("Error in Vorbis Comment read", META_DEBUG); - - return comments; -} /* End Vorbis/FLAC/OggFLAC/Speex read */ - -void metaVorbis(metatag_t *meta) -{ - unsigned int i; - vorbis_t *comments = NULL; - size_t s; - - /* I'm not expecting more than one vorbis tag */ - if(meta->has_vorbis) - comments = meta->vorbis; - else if(meta->has_flac) - comments = meta->flac; - else if(meta->has_oggflac) - comments = meta->oggflac; - else if(meta->has_speex) - comments = meta->speex; - if(comments == NULL) - return; - - for(i = 0; i < comments->numitems; i++) - { - vorbisfielddata_t *field = comments->items[i]; - if(!fmt_strcasecmp((char*)field->name, "TITLE")) - { - pdebug("Found Title!", META_DEBUG); - - meta->title = field->data; - } - /* Prefer PERFORMER to ARTIST */ - else if(!fmt_strcasecmp((char*)field->name, "PERFORMER")) - { - pdebug("Found Artist!", META_DEBUG); - - meta->artist = field->data; - } - else if(!fmt_strcasecmp((char*)field->name, "ARTIST") && meta->artist == NULL) - { - pdebug("Found Artist!", META_DEBUG); - - meta->artist = field->data; - } - else if(!fmt_strcasecmp((char*)field->name, "ALBUM")) - { - pdebug("Found Album!", META_DEBUG); - - meta->album = field->data; - } - else if(!fmt_strcasecmp((char*)field->name, "MUSICBRAINZ_TRACKID")) - { - pdebug("Found MusicBrainz Track ID!", META_DEBUG); - - s = strlen((char*)field->data) + 1; - meta->mb = realloc(meta->mb, s); - memcpy(meta->mb, field->data, s); - } - else if(!fmt_strcasecmp((char*)field->name, "GENRE")) - { - pdebug("Found Genre!", META_DEBUG); - - s = strlen((char*)field->data) + 1; - meta->genre = realloc(meta->genre, s); - memcpy(meta->genre, field->data, s); - } - else if(!fmt_strcasecmp((char*)field->name, "TRACKNUMBER")) - { - pdebug("Found Track!", META_DEBUG); - - s = strlen((char*)field->data) + 1; - meta->track = realloc(meta->track, s); - memcpy(meta->track, field->data, s); - } - } - - return; -} /* End Vorbis/FLAC/OggFLAC/Speex parsing */ - -static id3v2_t *fetchID3v2(char *filename) -{ - id3v2_t *id3v2; - - pdebug("Getting ID3v2 tag metadata...", META_DEBUG); - id3v2 = readID3v2(filename); - if(id3v2 == NULL) - pdebug("Error in readID3v2()", META_DEBUG); - - return id3v2; -} /* End ID3v2 read */ - -void metaID3v2(metatag_t *meta) -{ - int i; - id3v2_t *id3v2 = meta->id3v2; - - for(i = 0; i < id3v2->numitems; i++) - { - unsigned char *data = NULL, *utf = NULL; - framedata_t *frame = id3v2->items[i]; - if( (id3v2->version == 2 && frame->frameid == ID3V22_TT2) || - (id3v2->version == 3 && frame->frameid == ID3V23_TIT2) || - (id3v2->version == 4 && frame->frameid == ID3V24_TIT2)) - { - pdebug("Found Title!", META_DEBUG); - - meta->title = frame->data; - } - else if((id3v2->version == 2 && frame->frameid == ID3V22_TP1) || - (id3v2->version == 3 && frame->frameid == ID3V23_TPE1) || - (id3v2->version == 4 && frame->frameid == ID3V24_TPE1)) - { - pdebug("Found Artist!", META_DEBUG); - - meta->artist = frame->data; - } - else if((id3v2->version == 2 && frame->frameid == ID3V22_TAL) || - (id3v2->version == 3 && frame->frameid == ID3V23_TALB) || - (id3v2->version == 4 && frame->frameid == ID3V24_TALB)) - { - pdebug("Found Album!", META_DEBUG); - - meta->album = frame->data; - } - /* No strict year for ID3v2.4 */ - else if((id3v2->version == 2 && frame->frameid == ID3V22_TYE) || - (id3v2->version == 3 && frame->frameid == ID3V23_TYER)) - { - pdebug("Found Year!", META_DEBUG); - - meta->year = frame->data; - } - /* Won't translate ID3v1 genres yet */ - else if((id3v2->version == 2 && frame->frameid == ID3V22_TCO) || - (id3v2->version == 3 && frame->frameid == ID3V23_TCON) || - (id3v2->version == 4 && frame->frameid == ID3V24_TCON)) - { - pdebug("Found Genre!", META_DEBUG); - - meta->genre = realloc(meta->genre, frame->len); - memset(meta->genre, '\0', frame->len); - memcpy(meta->genre, frame->data, frame->len); - } - else if((id3v2->version == 2 && frame->frameid == ID3V22_TRK) || - (id3v2->version == 3 && frame->frameid == ID3V23_TRCK) || - (id3v2->version == 4 && frame->frameid == ID3V24_TRCK)) - { - pdebug("Found Track!", META_DEBUG); - - meta->track = realloc(meta->track, frame->len); - memset(meta->track, '\0', frame->len); - memcpy(meta->track, frame->data, frame->len); - } - else if((id3v2->version == 2 && frame->frameid == ID3V22_UFI) || - (id3v2->version == 3 && frame->frameid == ID3V23_UFID) || - (id3v2->version == 4 && frame->frameid == ID3V24_UFID)) - { - data = frame->data; - - if(!strcmp((char*)data, "http://musicbrainz.org")) - { - pdebug("Found MusicBrainz Track ID!", META_DEBUG); - - utf = data + 23; - - meta->mb = realloc(meta->mb, frame->len - 22); - memcpy(meta->mb, utf, frame->len - 23); - *(meta->mb + frame->len - 23) = 0; - } - } - } -} /* End ID3v2 parsing */ - -static itunes_t *fetchiTunes(char *filename) -{ - itunes_t *itunes; - - pdebug("Getting iTunes tag metadata...", META_DEBUG); - itunes = readiTunes(filename); - - return itunes; -} /* End M4A read */ - -void metaiTunes(metatag_t *meta) -{ - itunes_t *itunes = meta->itunes; - int tmp; - - if(itunes->title != NULL) - { - pdebug("Found Title!", META_DEBUG); - - meta->title = itunes->title; - } - if(itunes->artist != NULL) - { - pdebug("Found Artist!", META_DEBUG); - - meta->artist = itunes->artist; - } - if(itunes->album != NULL) - { - pdebug("Found Album!", META_DEBUG); - - meta->album = itunes->album; - } - /* I don't read genre (yet) and I won't read max track number. */ - if(itunes->track > 0 && itunes->track != 255) - { - pdebug("Found Track!", META_DEBUG); - - meta->track = realloc(meta->track, 4); - tmp = snprintf((char*)meta->track, 3, "%d", itunes->track); - *(meta->track + tmp) = '\0'; - } - if(itunes->year != NULL) - { - pdebug("Found Year!", META_DEBUG); - - meta->year = itunes->year; - } -} /* End M4A parsing */ - -static wma_t *fetchWMA(char *filename) -{ - wma_t *wma; - - pdebug("Getting WMA metadata...", META_DEBUG); - wma = readWMA(filename); - - return wma; -} /* End WMA read */ - -void metaWMA(metatag_t *meta) -{ - wma_t *wma = meta->wma; - unsigned int i; - int tmp; - - for(i = 0; i < wma->numitems; i++) - { - attribute_t *attribute = wma->items[i]; - - if(!strcmp((char*)attribute->name, "Title")) - { - pdebug("Found Title!", META_DEBUG); - - meta->title = attribute->data; - } - else if(!strcmp((char*)attribute->name, "Author")) - { - pdebug("Found Artist!", META_DEBUG); - - meta->artist = attribute->data; - } - else if(!strcmp((char*)attribute->name, "WM/AlbumTitle")) - { - pdebug("Found Album!", META_DEBUG); - - meta->album = attribute->data; - } - else if(!strcmp((char*)attribute->name, "WM/Year")) - { - pdebug("Found Year!", META_DEBUG); - - meta->year = attribute->data; - } - else if(!strcmp((char*)attribute->name, "WM/Genre")) - { - pdebug("Found Genre!", META_DEBUG); - - size_t s = strlen((char*)attribute->data) + 1; - meta->genre = realloc(meta->genre, s); - memcpy(meta->genre, attribute->data, s); - } - else if(!strcmp((char*)attribute->name, "WM/TrackNumber")) - { - pdebug("Found Track!", META_DEBUG); - - meta->track = realloc(meta->track, 4); - tmp = snprintf((char*)meta->track, 3, "%d", - le2int(attribute->data)); - *(meta->track + tmp) = '\0'; - } - } -} - -static id3v1_t *fetchID3v1(char *filename) -{ - id3v1_t *id3v1; - - pdebug("Getting ID3v1 tag metadata...", META_DEBUG); - id3v1 = readID3v1(filename); - - return id3v1; -} /* End ID3v1 read */ - -void metaID3v1(metatag_t *meta) -{ - int tmp; - id3v1_t *id3v1 = meta->id3v1; - - if(id3v1->title != NULL) - { - pdebug("Found Title!", META_DEBUG); - - meta->title = id3v1->title; - } - if(id3v1->artist != NULL) - { - pdebug("Found Artist!", META_DEBUG); - - meta->artist = id3v1->artist; - } - if(id3v1->album != NULL) - { - pdebug("Found Album!", META_DEBUG); - - meta->album = id3v1->album; - } - if(id3v1->year != NULL) - { - pdebug("Found Year!", META_DEBUG); - - meta->year = id3v1->year; - } - if(id3v1->track != 255) - { - pdebug("Found Track!", META_DEBUG); - - meta->track = realloc(meta->track, 4); - tmp = snprintf((char*)meta->track, 3, "%d", id3v1->track); - *(meta->track + tmp) = '\0'; - } - /* I assume unassigned genre's are 255 */ - if(id3v1->genre != 255 && id3v1->genre < sizeof(genre_list) - / sizeof(char *)) - { - pdebug("Found Genre!", META_DEBUG); - - size_t s = strlen(genre_list[id3v1->genre]) + 1; - meta->genre = realloc(meta->genre, s); - memcpy(meta->genre, genre_list[id3v1->genre], s); - } - /* - * This next one is unofficial, but maybe someone will use it. - * I don't think anyone's going to trigger this by accident. - * - * Specification: - * In comment field (ID3v1 or ID3v1.1): - * 1 byte: \0 - * 10 bytes: "MBTRACKID=" identifier - * 16 bytes: binary representation of Track ID - * 1 byte: \0 - * - * e.g. for "Missing" on Evanescence's "Bring Me to Life" single - * - * Track ID = 9c2567cb-4a8b-4096-b105-dada6b95a08b - * - * Therefore, comment field would equal: - * "MBID: \156%g\203J\139@\150\177\005\218\218k\149\160\139" - * in ASCII (with three digit decimal escape characters) - */ - if(!strncmp((char*)((id3v1->comment) + 1), "MBTRACKID=", 10)) - { - pdebug("Found MusicBrainz Track ID!", META_DEBUG); - - meta->mb = realloc(meta->mb, 37); - tmp = sprintf((char*)meta->mb, - "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - id3v1->comment[11], - id3v1->comment[12], - id3v1->comment[13], - id3v1->comment[14], - id3v1->comment[15], - id3v1->comment[16], - id3v1->comment[17], - id3v1->comment[18], - id3v1->comment[19], - id3v1->comment[20], - id3v1->comment[21], - id3v1->comment[22], - id3v1->comment[23], - id3v1->comment[24], - id3v1->comment[25], - id3v1->comment[26]); - *(meta->mb + tmp) = '\0'; - } -} /* End ID3v1 parsing */ - -void get_tag_data(metatag_t *meta, char *filename, int track) -{ - if(track > 0) - { - metaCD(meta, filename, track); - - return; - } - else - { - tag_exists(meta, filename); - if(meta->has_id3v1) - meta->id3v1 = fetchID3v1(filename); - if(meta->has_id3v2) - meta->id3v2 = fetchID3v2(filename); - if(meta->has_ape) - meta->ape = fetchAPE(filename); - if(meta->has_vorbis) - meta->vorbis = fetchVorbis(filename, READ_VORBIS); - if(meta->has_flac) - meta->flac = fetchVorbis(filename, READ_FLAC); - if(meta->has_oggflac) - meta->oggflac = fetchVorbis(filename, READ_OGGFLAC); - if(meta->has_speex) - meta->speex = fetchVorbis(filename, READ_SPEEX); - if(meta->has_itunes) - meta->itunes = fetchiTunes(filename); - if(meta->has_wma) - meta->wma = fetchWMA(filename); - } - - /* - * This order is rather arbitrary, but puts tags you'd EXPECT to - * be the exclusive tag in the file first (i.e. vorbis and itunes). - * Thus we return afterwards. - */ - - if(meta->has_vorbis || meta->has_flac || meta->has_oggflac || - meta->has_speex) - { - metaVorbis(meta); - - return; - } - else if(meta->has_itunes) - { - metaiTunes(meta); - - return; - } - else if(meta->has_wma) - { - metaWMA(meta); - - return; - } - /* - * OK, here's the trick: APE preferred to ID3v2? - * or ID3v2 preferred to APE? ID3v1 loses regardless. - * Thus it's put first to be overwritten. - */ - if(meta->has_id3v1) - metaID3v1(meta); - /* A little dirty for now, but it's not too difficult */ - if(!meta->prefer_ape) - { - if(meta->has_ape) - metaAPE(meta); - if(meta->has_id3v2) - metaID3v2(meta); - } - else if(meta->prefer_ape) - { - if(meta->has_id3v2) - metaID3v2(meta); - if(meta->has_ape) - metaAPE(meta); - } - - return; -} - -void metatag_delete(metatag_t *meta) -{ - if(meta->wma != NULL) - freeWMA(meta->wma); - if(meta->id3v1 != NULL) - freeID3v1(meta->id3v1); - if(meta->id3v2 != NULL) - freeID3v2(meta->id3v2); - if(meta->ape != NULL) - freeAPE(meta->ape); - if(meta->vorbis != NULL) - freeVorbis(meta->vorbis); - if(meta->flac != NULL) - freeVorbis(meta->flac); - if(meta->oggflac != NULL) - freeVorbis(meta->oggflac); - if(meta->speex != NULL) - freeVorbis(meta->speex); - if(meta->itunes != NULL) - freeiTunes(meta->itunes); - if(meta->cdaudio != NULL) - freeCDAudio(meta->cdaudio); - free(meta); -} - -metatag_t *metatag_new(void) -{ - metatag_t *ret; - - if(!(ret = calloc(sizeof(*ret), 1))) - return NULL; -#ifdef PREFER_APE - ret->prefer_ape = 1; -#endif - - return ret; -}
--- a/Plugins/General/scrobbler/tags/unicode.c Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,231 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include <stdlib.h> -#include <wchar.h> -#include <string.h> -#include "include/endian.h" -#include "include/unicode.h" -#include "audacious/util.h" - -wchar_t *utf8_to_wchar(unsigned char *utf, size_t memsize) -{ - size_t i; - int j = 0; - wchar_t *mem; - - if (utf == NULL) - return NULL; - - mem = calloc(sizeof(wchar_t) * (memsize + 1), 1); - - for(i = 0; i < memsize;) - { - if(utf[i] < 0x80) - mem[j++] = utf[i++]; - else if(utf[i] < 0xE0) - { - mem[j++] = ((utf[i] & 0x1F) << 6) | - (utf[i + 1] & 0x3F); - i += 2; - } - else if(utf[i] < 0xF0) - { - mem[j++] = ((utf[i] & 0x0F) << 12) | - ((utf[i + 1] & 0x3F) << 6) | - (utf[i + 2] & 0x3F); - i += 3; - } - else if(utf[i] < 0xF8) - { - mem[j++] = ((utf[i] & 0x07) << 18) | - ((utf[i + 1] & 0x3F) << 12) | - ((utf[i + 2] & 0x3F) << 6) | - (utf[i + 2] & 0x3F); - i += 4; - } - else if(utf[i] < 0xFC) - { - mem[j++] = ((utf[i] & 0x03) << 24) | - ((utf[i + 1] & 0x3F) << 18) | - ((utf[i + 2] & 0x3F) << 12) | - ((utf[i + 3] & 0x3F) << 6) | - (utf[i + 4] & 0x3F); - i += 5; - } - else if(utf[i] >= 0xFC) - { - mem[j++] = ((utf[i] & 0x01) << 30) | - ((utf[i + 1] & 0x3F) << 24) | - ((utf[i + 2] & 0x3F) << 18) | - ((utf[i + 3] & 0x3F) << 12) | - ((utf[i + 4] & 0x3F) << 6) | - (utf[i + 5] & 0x3F); - i += 6; - } - } - - mem = realloc(mem, sizeof(wchar_t) * (j + 1)); - - return mem; -} - -unsigned char *wchar_to_utf8(wchar_t *wchar, size_t memsize) -{ - size_t i; - unsigned char *mem, *ptr; - - if (wchar == NULL) - return NULL; - - mem = calloc(memsize * 6 + 1, 1); - ptr = mem; - - for(i = 0; i < memsize; i++) - { - if(wchar[i] < 0x80) - { - *ptr++ = wchar[i] & 0x7F; - } - else if(wchar[i] < 0x800) - { - *ptr++ = 0xC0 | ((wchar[i] >> 6) & 0x1F); - *ptr++ = 0x80 | (wchar[i] & 0x3F); - } - else if(wchar[i] < 0x10000) - { - *ptr++ = 0xE0 | ((wchar[i] >> 12) & 0x0F); - *ptr++ = 0x80 | ((wchar[i] >> 6) & 0x3F); - *ptr++ = 0x80 | (wchar[i] & 0x3F); - } - else if(wchar[i] < 0x200000) - { - *ptr++ = 0xF0 | ((wchar[i] >> 18) & 0x07); - *ptr++ = 0x80 | ((wchar[i] >> 12) & 0x3F); - *ptr++ = 0x80 | ((wchar[i] >> 6) & 0x3F); - *ptr++ = 0x80 | (wchar[i] & 0x3F); - } - else if(wchar[i] < 0x4000000) - { - *ptr++ = 0xF8 | ((wchar[i] >> 24) & 0x03); - *ptr++ = 0x80 | ((wchar[i] >> 18) & 0x3F); - *ptr++ = 0x80 | ((wchar[i] >> 12) & 0x3F); - *ptr++ = 0x80 | ((wchar[i] >> 6) & 0x3F); - *ptr++ = 0x80 | (wchar[i] & 0x3F); - } - else if((unsigned long)wchar[i] < 0x80000000) - { - *ptr++ = 0xFC | ((wchar[i] >> 30) & 0x01); - *ptr++ = 0x80 | ((wchar[i] >> 24) & 0x3F); - *ptr++ = 0x80 | ((wchar[i] >> 18) & 0x3F); - *ptr++ = 0x80 | ((wchar[i] >> 12) & 0x3F); - *ptr++ = 0x80 | ((wchar[i] >> 6) & 0x3F); - *ptr++ = 0x80 | (wchar[i] & 0x3F); - } - } - - mem = realloc(mem, ptr - mem + 1); - - return mem; -} - -void iso88591_to_utf8(unsigned char *iso, size_t memsize, - unsigned char **utf) -{ - *utf = str_to_utf8(iso); -} - -#if 0 -void iso88591_to_utf8(unsigned char *iso, size_t memsize, - unsigned char **utf) -{ - size_t i; - wchar_t *wchar; - - wchar = calloc(sizeof(wchar_t) * (memsize + 1), 1); - for(i = 0; i < memsize; i++) wchar[i] = iso[i]; - *utf = wchar_to_utf8(wchar, memsize); - free(wchar); -} -#endif - -void utf16bom_to_utf8(unsigned char *utf16, size_t memsize, - unsigned char **utf) -{ - wchar_t *wchar; - unsigned char utf16char[2]; - int endian = 0; - size_t i; - - wchar = calloc(sizeof(wchar_t) * memsize / 2 - 1, 1); - for(i = 0; i < memsize; i += 2) - { - if(i == 0) - { - if(utf16[i] == 0xFF) endian = 0; - else if(utf16[i] == 0xFE) endian = 1; - } - else - { - utf16char[0] = utf16[i]; - utf16char[1] = utf16[i + 1]; - if(endian == 1) wchar[i / 2 - 1] = be2short(utf16char); - else if(endian == 0) wchar[i / 2 - 1] = le2short(utf16char); - } - } - *utf = wchar_to_utf8(wchar, memsize / 2 - 1); - free(wchar); -} - -void utf16be_to_utf8(unsigned char *utf16, size_t memsize, - unsigned char **utf) -{ - wchar_t *wchar; - unsigned char utf16char[2]; - size_t i; - - wchar = calloc(sizeof(wchar_t) * (memsize / 2), 1); - for(i = 0; i < memsize; i += 2) - { - utf16char[0] = utf16[i]; - utf16char[1] = utf16[i + 1]; - wchar[i / 2] = be2short(utf16char); - } - *utf = wchar_to_utf8(wchar, memsize / 2); - free(wchar); -} - -void utf16le_to_utf8(unsigned char *utf16, size_t memsize, - unsigned char **utf) -{ - wchar_t *wchar; - unsigned char utf16char[2]; - size_t i; - - wchar = calloc(sizeof(wchar_t) * (memsize / 2), 1); - for(i = 0; i < memsize; i += 2) - { - utf16char[0] = utf16[i]; - utf16char[1] = utf16[i + 1]; - wchar[i / 2] = le2short(utf16char); - } - *utf = wchar_to_utf8(wchar, memsize / 2); - free(wchar); -}
--- a/Plugins/General/scrobbler/tags/vorbis.c Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,415 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2003, 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "include/vorbis.h" -#include "include/endian.h" -#include "../fmt.h" -#include "../config.h" -#include "include/unicode.h" -#define BUFFER_SIZE 4096 - -static vorbis_t *readComments(VFSFile *fp) -{ - vorbis_t *comments = calloc(sizeof(vorbis_t), 1); - unsigned char cToInt[4]; - int i, lines, j = 0; - - vfs_fread(cToInt, 1, 4, fp); - comments->vendorlen = le2int(cToInt); - comments->vendor = malloc(comments->vendorlen); - vfs_fread(comments->vendor, 1, comments->vendorlen, fp); - vfs_fread(cToInt, 1, 4, fp); - lines = comments->numitems = le2int(cToInt); - comments->items = realloc(comments->items, - (comments->numitems) * sizeof(vorbisfielddata_t *)); - for(i = 0; i < lines; i++) - { - unsigned char *data, *dp; - size_t datalen; - vorbisfielddata_t *fielddata = - calloc(sizeof(vorbisfielddata_t), 1); - - vfs_fread(cToInt, 1, 4, fp); - fielddata->len = le2int(cToInt); - data = malloc(fielddata->len); - vfs_fread(data, 1, fielddata->len, fp); - dp = (unsigned char*)strchr((char*)data, '='); - if(dp == NULL) - { - pdebug("No '=' in comment!", META_DEBUG); - comments->numitems--; - free(data); - continue; - } - *dp = '\0'; - dp++; - datalen = strlen((char*)data); - fielddata->name = malloc(datalen + 1); - fielddata->data = malloc(fielddata->len - datalen); - *(fielddata->data + fielddata->len - datalen - 1) = '\0'; - strcpy((char*)fielddata->name, (char*)data); - strncpy((char*)fielddata->data, (char*)dp, fielddata->len - datalen - 1); - - comments->items[j++] = fielddata; - - free(data); - } - - return comments; -} - -int findVorbis(VFSFile *fp) -{ - char tag_id[5] = ""; - unsigned char *tag_buffer, *bp, vorbis_type; - int status = 0, pos = -1; - - vfs_fread(tag_id, 1, 4, fp); - if(strcmp(tag_id, "OggS")) - return -1; - tag_buffer = malloc(23); - vfs_fread(tag_buffer, 1, 23, fp); - bp = tag_buffer; - while(status == 0) - { - unsigned char segments, *lacing; - unsigned int pagelen = 0, i; - bp += 22; - segments = *bp; - lacing = malloc(segments); - vfs_fread(lacing, 1, segments, fp); - for(i = 0; i < segments; i++) - pagelen += lacing[i]; - tag_buffer = realloc(tag_buffer, pagelen); - vfs_fread(tag_buffer, 1, pagelen, fp); - bp = tag_buffer; - for(i = 0; i < segments && status == 0;) - { - if(strncmp((char*)(bp + 1), "vorbis", 6) == 0) - { - vorbis_type = *bp; - if(vorbis_type == 0x03) - { - pos = vfs_ftell(fp) - pagelen + - (bp - tag_buffer); - status = 1; - } - } - bp += lacing[i++]; - } - if(status == 1 || vfs_feof(fp)) - { - free(lacing); - break; - } - tag_buffer = realloc(tag_buffer, 27); - vfs_fread(tag_buffer, 1, 27, fp); - bp = tag_buffer + 4; - free(lacing); - } - - free(tag_buffer); - - if(vfs_feof(fp)) - return -1; - else - return pos; -} - -int findFlac(VFSFile *fp) -{ - unsigned char tag_id[5] = ""; - int pos; - - vfs_fread(tag_id, 1, 4, fp); - if(strcmp((char*)tag_id, "fLaC")) - return 0; - while(1) - { - vfs_fread(tag_id, 1, 4, fp); - if((tag_id[0] & 0x7F) == 4) - return 1; - else if((tag_id[0] & 0x80) == 0x80) - return 0; - else if(vfs_feof(fp)) - return 0; - else - { - pos = flac2int(tag_id); - vfs_fseek(fp, pos, SEEK_CUR); - } - } -} - -int findOggFlac(VFSFile *fp) -{ - char tag_id[5] = ""; - unsigned char *tag_buffer, *bp; - int status = 0, pos = -1; - - vfs_fread(tag_id, 1, 4, fp); - if(strcmp(tag_id, "OggS")) - return -1; - /* I assume first page always has only "fLaC" */ - tag_buffer = malloc(28); - vfs_fread(tag_buffer, 1, 28, fp); - bp = tag_buffer + 24; - if(strncmp((char*)bp, "fLaC", 4)) - { - free(tag_buffer); - return -1; - } - tag_buffer = realloc(tag_buffer, 27); - vfs_fread(tag_buffer, 1, 27, fp); - bp = tag_buffer + 4; - while(status == 0) - { - unsigned char segments, *lacing = NULL; - unsigned int pagelen = 0, i; - bp += 22; - segments = *bp; - lacing = realloc(lacing, segments); - vfs_fread(lacing, 1, segments, fp); - for(i = 0; i < segments; i++) - pagelen += lacing[i]; - tag_buffer = realloc(tag_buffer, pagelen); - vfs_fread(tag_buffer, 1, pagelen, fp); - bp = tag_buffer; - for(i = 0; i < segments && status == 0;) - { - if((bp[0] & 0x7F) == 4) - { - pos = vfs_ftell(fp) - pagelen + - (bp - tag_buffer); - status = 1; - } - else if((tag_id[0] & 0x80) == 0x80) - { - free(tag_buffer); - free(lacing); - return -1; - } - else - bp += lacing[i++]; - } - if(status == 1 || vfs_feof(fp)) - break; - tag_buffer = realloc(tag_buffer, 27); - vfs_fread(tag_buffer, 1, 27, fp); - bp = tag_buffer + 4; - free(lacing); - } - - free(tag_buffer); - - if(vfs_feof(fp)) - return -1; - else - return pos; -} - -int findSpeex(VFSFile *fp) -{ - char tag_id[5] = ""; - unsigned char *tag_buffer, *bp, segments, *lacing = NULL; - unsigned int pagelen = 0, i; - int pos = -1; - - vfs_fread(tag_id, 1, 4, fp); - if(strcmp(tag_id, "OggS")) - return -1; - tag_buffer = malloc(23); - vfs_fread(tag_buffer, 1, 23, fp); - bp = tag_buffer + 22; - segments = *bp; - lacing = malloc(segments); - vfs_fread(lacing, 1, segments, fp); - for(i = 0; i < segments; i++) - pagelen += lacing[i]; - tag_buffer = realloc(tag_buffer, pagelen); - vfs_fread(tag_buffer, 1, pagelen, fp); - bp = tag_buffer; - if(strncmp((char*)bp, "Speex ", 8)) - { - free(lacing); - free(tag_buffer); - return -1; - } - tag_buffer = realloc(tag_buffer, 27); - vfs_fread(tag_buffer, 1, 27, fp); - bp = tag_buffer + 26; - segments = *bp; - lacing = realloc(lacing, segments); - vfs_fread(lacing, 1, segments, fp); - pos = vfs_ftell(fp); - - free(tag_buffer); - free(lacing); - - if(vfs_feof(fp)) - return -1; - else - return pos; -} - -vorbis_t *readVorbis(char *filename) -{ - VFSFile *fp; - vorbis_t *comments; - int pos; - - fp = vfs_fopen(filename, "r"); - - if(!fp) - { - pdebug("Couldn't open file!", META_DEBUG); - return NULL; - } - - vfs_fseek(fp, 0, SEEK_SET); - - pdebug("Searching for tag...", META_DEBUG); - pos = findVorbis(fp); - if(pos < 0) - { - vfs_fclose(fp); - return NULL; - } - vfs_fseek(fp, pos + 7, SEEK_SET); - comments = readComments(fp); - - vfs_fclose(fp); - - return comments; -} - -vorbis_t *readFlac(char *filename) -{ - VFSFile *fp; - vorbis_t *comments; - int status; - - fp = vfs_fopen(filename, "r"); - - if(!fp) - { - pdebug("Couldn't open file!", META_DEBUG); - return NULL; - } - - vfs_fseek(fp, 0, SEEK_SET); - - pdebug("Searching for tag...", META_DEBUG); - status = findFlac(fp); - if(!status) - { - vfs_fclose(fp); - return NULL; - } - comments = readComments(fp); - - vfs_fclose(fp); - - return comments; -} - -vorbis_t *readOggFlac(char *filename) -{ - VFSFile *fp; - vorbis_t *comments; - int pos; - - fp = vfs_fopen(filename, "r"); - - if(!fp) - { - pdebug("Couldn't open file!", META_DEBUG); - return NULL; - } - - vfs_fseek(fp, 0, SEEK_SET); - - pdebug("Searching for tag...", META_DEBUG); - pos = findOggFlac(fp); - if(pos < 0) - { - vfs_fclose(fp); - return NULL; - } - vfs_fseek(fp, pos + 4, SEEK_SET); - comments = readComments(fp); - - vfs_fclose(fp); - - return comments; -} - -vorbis_t *readSpeex(char *filename) -{ - VFSFile *fp; - vorbis_t *comments; - int pos; - - fp = vfs_fopen(filename, "r"); - - if(!fp) - { - pdebug("Couldn't open file!", META_DEBUG); - return NULL; - } - - vfs_fseek(fp, 0, SEEK_SET); - - pdebug("Searching for tag...", META_DEBUG); - pos = findSpeex(fp); - if(pos < 0) - { - vfs_fclose(fp); - return NULL; - } - vfs_fseek(fp, pos, SEEK_SET); - comments = readComments(fp); - - vfs_fclose(fp); - - return comments; -} - -void freeVorbis(vorbis_t *comments) -{ - unsigned int i; - - for(i = 0; i < comments->numitems; i++) - { - vorbisfielddata_t *field; - - field = comments->items[i]; - free(field->data); - free(field->name); - free(field); - } - free(comments->items); - free(comments->vendor); - free(comments); -}
--- a/Plugins/General/scrobbler/tags/wma.c Wed Jun 14 22:39:13 2006 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,301 +0,0 @@ -/* - * libmetatag - A media file tag-reader library - * Copyright (C) 2004 Pipian - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "include/wma.h" -#include "include/endian.h" -#include "../fmt.h" -#include "../config.h" -#include "include/unicode.h" -#define WMA_GUID (unsigned char [16]) \ - { 0x30, 0x26, 0xB2, 0x75, \ - 0x8E, 0x66, \ - 0xCF, 0x11, \ - 0xA6, 0xD9, \ - 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C } -#define CONTENT_GUID (unsigned char [16]) \ - { 0x33, 0x26, 0xB2, 0x75, \ - 0x8E, 0x66, \ - 0xCF, 0x11, \ - 0xA6, 0xD9, \ - 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C } -#define EXTENDED_GUID (unsigned char [16]) \ - { 0x40, 0xA4, 0xD0, 0xD2, \ - 0x07, 0xE3, \ - 0xD2, 0x11, \ - 0x97, 0xF0, \ - 0x00, 0xA0, 0xC9, 0x5E, 0xA8, 0x50 } -#define BUFFER_SIZE 4096 - -static wma_t *readAttributes(VFSFile *fp, int pos) -{ - wma_t *wma = calloc(sizeof(wma_t), 1); - attribute_t *attribute; - unsigned char *tag_buffer = NULL, *bp, cToInt[8], *data = NULL; - int title_size, author_size, copyright_size, desc_size, rating_size, - size, primary_items; - unsigned int i; - - vfs_fseek(fp, pos, SEEK_SET); - vfs_fread(cToInt, 1, 8, fp); - /* Yes, it's 64 bits in size, but I'm lazy and don't want to adjust. */ - size = le2int(cToInt); - tag_buffer = malloc(size - 24); - vfs_fread(tag_buffer, 1, size - 24, fp); - bp = tag_buffer; - title_size = le2short(bp); - bp += 2; - author_size = le2short(bp); - bp += 2; - copyright_size = le2short(bp); - bp += 2; - desc_size = le2short(bp); - bp += 2; - rating_size = le2short(bp); - bp += 2; - if(title_size > 0) - { - attribute = calloc(sizeof(attribute_t), 1); - wma->items = realloc(wma->items, - (wma->numitems + 1) * sizeof(attribute_t *)); - attribute->name = (unsigned char*)strdup("Title"); - data = malloc(title_size); - memcpy(data, bp, title_size); - bp += title_size; - utf16le_to_utf8(data, title_size, &attribute->data); - attribute->type = 0; - wma->items[wma->numitems++] = attribute; - free(data); - } - if(author_size > 0) - { - attribute = calloc(sizeof(attribute_t), 1); - wma->items = realloc(wma->items, - (wma->numitems + 1) * sizeof(attribute_t *)); - attribute->name = (unsigned char*)strdup("Author"); - data = malloc(author_size); - memcpy(data, bp, author_size); - bp += author_size; - utf16le_to_utf8(data, author_size, &attribute->data); - attribute->type = 0; - wma->items[wma->numitems++] = attribute; - free(data); - } - if(copyright_size > 0) - { - attribute = calloc(sizeof(attribute_t), 1); - wma->items = realloc(wma->items, - (wma->numitems + 1) * sizeof(attribute_t *)); - attribute->name = (unsigned char*)strdup("Copyright"); - data = malloc(copyright_size); - memcpy(data, bp, copyright_size); - bp += copyright_size; - utf16le_to_utf8(data, copyright_size, &attribute->data); - attribute->type = 0; - wma->items[wma->numitems++] = attribute; - free(data); - } - if(desc_size > 0) - { - attribute = calloc(sizeof(attribute_t), 1); - wma->items = realloc(wma->items, - (wma->numitems + 1) * sizeof(attribute_t *)); - attribute->name = (unsigned char*)strdup("Description"); - data = malloc(desc_size); - memcpy(data, bp, desc_size); - bp += desc_size; - utf16le_to_utf8(data, desc_size, &attribute->data); - attribute->type = 0; - wma->items[wma->numitems++] = attribute; - free(data); - } - if(rating_size > 0) - { - attribute = calloc(sizeof(attribute_t), 1); - wma->items = realloc(wma->items, - (wma->numitems + 1) * sizeof(attribute_t *)); - attribute->name = (unsigned char*)strdup("Rating"); - data = malloc(rating_size); - memcpy(data, bp, rating_size); - bp += rating_size; - utf16le_to_utf8(data, desc_size, &attribute->data); - attribute->type = 0; - wma->items[wma->numitems++] = attribute; - free(data); - } - primary_items = wma->numitems; - - vfs_fread(tag_buffer, 16, 1, fp); - if(memcmp(tag_buffer, EXTENDED_GUID, 16)) - { - free(tag_buffer); - return wma; - } - vfs_fread(cToInt, 8, 1, fp); - /* - * Another 64-bit breakage. If you've got that large an amount of - * metadata, you've got a problem. - */ - size = le2int(cToInt); - tag_buffer = realloc(tag_buffer, size); - vfs_fread(tag_buffer, size, 1, fp); - bp = tag_buffer; - memcpy(cToInt, bp, 2); - wma->numitems += le2short(cToInt); - wma->items = realloc(wma->items, - wma->numitems * sizeof(attribute_t *)); - bp += 2; - for(i = primary_items; i < wma->numitems; i++) - { - int type; - - attribute = calloc(sizeof(attribute_t), 1); - - memcpy(cToInt, bp, 2); - size = le2short(cToInt); - bp += 2; - data = malloc(size); - memcpy(data, bp, size); - utf16le_to_utf8(data, size, &attribute->name); - bp += size; - memcpy(cToInt, bp, 2); - type = le2short(cToInt); - attribute->type = type; - bp += 2; - memcpy(cToInt, bp, 2); - size = le2short(cToInt); - bp += 2; - data = realloc(data, size); - memcpy(data, bp, size); - switch(type) - { - /* Type 0 is Little-endian UTF16 */ - case 0: - utf16le_to_utf8(data, size, &attribute->data); - break; - /* - * Type 1 is binary - * Type 2 is boolean - * Type 3 is 32-bit integer (signed?) - * Type 4 is double - */ - case 1: - case 2: - case 3: - case 4: - default: - attribute->data = malloc(size); - memcpy(attribute->data, data, size); - } - bp += size; - - wma->items[i] = attribute; - } - - free(tag_buffer); - - return wma; -} - -int findWMA(VFSFile *fp) -{ - unsigned char *tag_buffer, *bp; - - tag_buffer = malloc(BUFFER_SIZE); - vfs_fread(tag_buffer, 1, BUFFER_SIZE, fp); - bp = tag_buffer; - if(memcmp(bp, WMA_GUID, 16)) - { - free(tag_buffer); - return -1; - } - bp += 30; - if(memcmp(bp, CONTENT_GUID, 16)) - { - free(tag_buffer); - return -1; - } - /* - * It's stupid to reject if no Extended Content GUID - * is found... This code is in here in case though... - * - bp += 16; - memcpy(cToInt, bp, 8); - size = le2long(cToInt); - bp += size - 16; - if(!memcmp(bp, EXTENDED_GUID, 16)) - { - free(tag_buffer); - return 0; - } - */ - free(tag_buffer); - return bp - tag_buffer + 16; -} - -wma_t *readWMA(char *filename) -{ - VFSFile *fp; - wma_t *wma; - int status; - - fp = vfs_fopen(filename, "r"); - - if(!fp) - { - pdebug("Couldn't open file!", META_DEBUG); - return NULL; - } - - vfs_fseek(fp, 0, SEEK_SET); - - pdebug("Searching for tag...", META_DEBUG); - status = findWMA(fp); - if(status == 0) - { - vfs_fclose(fp); - return NULL; - } - wma = readAttributes(fp, status); - - vfs_fclose(fp); - - return wma; -} - -void freeWMA(wma_t *wma) -{ - unsigned int i; - - for(i = 0; i < wma->numitems; i++) - { - attribute_t *attribute; - - attribute = wma->items[i]; - free(attribute->name); - free(attribute->data); - free(attribute); - } - free(wma->items); - free(wma); -}