1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
/*****************************************************************
* gmerlin-avdecoder - a general purpose multimedia decoding library
*
* Copyright (c) 2001 - 2012 Members of the Gmerlin project
* gmerlin-general@lists.sourceforge.net
* http://gmerlin.sourceforge.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* *****************************************************************/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <avdec_private.h>
struct bgav_id3v1_tag_s
{
char * title; /* Song title 30 characters */
char * artist; /* Artist 30 characters */
char * album; /* Album Album 30 characters */
char * year; /* Year 4 characters */
char * comment; /* Comment 30/28 characters */
uint8_t genre;
uint8_t track;
};
static char * get_string(bgav_charset_converter_t * cnv, char * ptr, int max_size)
{
char * end;
end = ptr + max_size - 1;
while(end > ptr)
{
if(!isspace(*end) && (*end != '\0'))
break;
end--;
}
if(end == ptr)
return NULL;
end++;
return bgav_convert_string(cnv, ptr, end - ptr, NULL);
// return gavl_strndup(ptr, end);
}
bgav_id3v1_tag_t * bgav_id3v1_read(bgav_input_context_t * input)
{
char buffer[128];
char * pos;
bgav_id3v1_tag_t * ret;
bgav_charset_converter_t * cnv;
if(bgav_input_read_data(input, (uint8_t*)buffer, 128) < 128)
return NULL;
cnv = bgav_charset_converter_create(input->opt, "ISO-8859-1", BGAV_UTF8);
ret = calloc(1, sizeof(*ret));
pos = buffer + 3;
ret->title = get_string(cnv, pos, 30);
pos = buffer + 33;
ret->artist = get_string(cnv, pos, 30);
pos = buffer + 63;
ret->album = get_string(cnv, pos, 30);
pos = buffer + 93;
ret->year = get_string(cnv, pos, 4);
pos = buffer + 97;
ret->comment = get_string(cnv, pos, 30);
if(ret->comment && strlen(ret->comment) <= 28)
ret->track = buffer[126];
ret->genre = buffer[127];
bgav_charset_converter_destroy(cnv);
return ret;
}
int bgav_id3v1_probe(bgav_input_context_t * input)
{
uint8_t probe_data[3];
if(bgav_input_get_data(input, probe_data, 3) < 3)
return 0;
if((probe_data[0] == 'T') &&
(probe_data[1] == 'A') &&
(probe_data[2] == 'G'))
return 1;
return 0;
}
#define FREE(s) if(s)free(s);
void bgav_id3v1_destroy(bgav_id3v1_tag_t * t)
{
FREE(t->title);
FREE(t->artist); /* Artist 30 characters */
FREE(t->album); /* Album Album 30 characters */
FREE(t->year); /* Year 4 characters */
FREE(t->comment); /* Comment 30/28 characters */
free(t);
}
#define GENRE_MAX 0x94
static char const * const id3_genres[GENRE_MAX] =
{
"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", "Alt",
"Bass", "Soul", "Punk", "Space",
"Meditative", "Instrumental Pop",
"Instrumental Rock", "Ethnic", "Gothic",
"Darkwave", "Techno-Industrial", "Electronic",
"Pop-Folk", "Eurodance", "Dream",
"Southern Rock", "Comedy", "Cult",
"Gangsta Rap", "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", "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", "Slow Jam", "Club", "Tango",
"Samba", "Folklore", "Ballad", "Power Ballad",
"Rhythmic Soul", "Freestyle", "Duet",
"Punk Rock", "Drum Solo", "A Cappella",
"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",
"Merengue", "Salsa", "Thrash Metal",
"Anime", "JPop", "Synthpop"
};
#define CS(src, gavl_name) \
if(t->src) gavl_dictionary_set_string(m, gavl_name, t->src);
const char * bgav_id3v1_get_genre(int id)
{
if(id < GENRE_MAX)
return id3_genres[id];
return NULL;
}
void bgav_id3v1_2_metadata(bgav_id3v1_tag_t * t, gavl_dictionary_t * m)
{
CS(title, GAVL_META_TITLE);
CS(artist, GAVL_META_ARTIST);
CS(album, GAVL_META_ALBUM);
CS(year, GAVL_META_YEAR);
CS(comment, GAVL_META_COMMENT);
if(t->genre < GENRE_MAX)
gavl_dictionary_set_string(m, GAVL_META_GENRE, bgav_id3v1_get_genre(t->genre));
if(t->track)
gavl_dictionary_set_int(m, GAVL_META_GENRE, t->track);
}
|