00001
00007 #include <id3tag.h>
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011
00012 #include "check.h"
00013 #include "mp3_id3.h"
00014 #include "wstring.h"
00015
00016 #ifndef id3_field_getlatin1s
00017
00023 id3_latin1_t const *id3_field_getlatin1s(union id3_field const *field, unsigned int index)
00024 {
00025 return field->latin1list.strings[index];
00026 }
00027 #endif
00028
00034 id3_latin1_t *id3_latin1duplicate(id3_latin1_t const *source)
00035 {
00036 size_t size;
00037 id3_latin1_t *result;
00038
00039 check(source != NULL);
00040
00041 size = sizeof(char) * strlen((char *)source);
00042 result = (id3_latin1_t *)malloc(size);
00043 if (result != NULL)
00044 {
00045 memcpy(result, source, size);
00046 }
00047
00048 check(result != NULL);
00049 return result;
00050 }
00051
00052
00054 const char *id3_genres[] = { "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop",
00055 "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap",
00056 "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks",
00057 "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance",
00058 "Classical", "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise",
00059 "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock",
00060 "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream",
00061 "Southern Rock", "Comedy", "Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle",
00062 "Native American", "Cabaret", "New Wave", "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi",
00063 "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock",
00064 "Folk", "Folk-Rock", "National Folk", "Swing", "Fast Fusion", "Bebob", "Latin", "Revival",
00065 "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock",
00066 "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson", "Opera",
00067 "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", "Porn Groove", "Satire", "Slow Jam",
00068 "Club", "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle",
00069 "Duet", "Punk Rock", "Drum Solo", "A capella", "Euro-House", "Dance Hall" };
00070
00071 char *id3_get_string(struct id3_tag *tag, char const *frameid)
00072 {
00073 struct id3_frame *frame;
00074 union id3_field *field;
00075 unsigned int i;
00076
00077 check(tag != NULL);
00078 check(frameid != NULL);
00079
00080 frame = id3_tag_findframe(tag, frameid, 0);
00081 if (frame == NULL)
00082 {
00083 return ID3_STRING_ERROR;
00084 }
00085
00086 for(i=0; i < frame->nfields; i++)
00087 {
00088 field = id3_frame_field(frame, i);
00089 if (field == NULL)
00090 {
00091 return ID3_STRING_ERROR;
00092 }
00093
00094 switch(id3_field_type(field))
00095 {
00096 case ID3_FIELD_TYPE_TEXTENCODING:
00097 case ID3_FIELD_TYPE_BINARYDATA:
00098 case ID3_FIELD_TYPE_LANGUAGE:
00099 case ID3_FIELD_TYPE_FRAMEID:
00100 case ID3_FIELD_TYPE_DATE:
00101
00102 break;
00103 case ID3_FIELD_TYPE_INT8:
00104 case ID3_FIELD_TYPE_INT16:
00105 case ID3_FIELD_TYPE_INT24:
00106 case ID3_FIELD_TYPE_INT32:
00107 case ID3_FIELD_TYPE_INT32PLUS:
00108
00109 break;
00110 case ID3_FIELD_TYPE_LATIN1:
00111 return (char *)id3_latin1duplicate(id3_field_getlatin1(field));
00112 break;
00113 case ID3_FIELD_TYPE_LATIN1FULL:
00114 return (char *)id3_latin1duplicate(id3_field_getfulllatin1(field));
00115 break;
00116 case ID3_FIELD_TYPE_LATIN1LIST:
00117 return (char *)id3_latin1duplicate(id3_field_getlatin1s(field, 0));
00118 break;
00119 case ID3_FIELD_TYPE_STRING:
00120 return (char *)id3_ucs4_latin1duplicate(id3_field_getstring(field));
00121 break;
00122 case ID3_FIELD_TYPE_STRINGFULL:
00123 return (char *)id3_ucs4_latin1duplicate(id3_field_getfullstring(field));
00124 break;
00125 case ID3_FIELD_TYPE_STRINGLIST:
00126 return (char *)id3_ucs4_latin1duplicate(id3_field_getstrings(field, 0));
00127 break;
00128 }
00129 }
00130
00131 return ID3_STRING_ERROR;
00132 }
00133
00134 unsigned long id3_get_int(struct id3_tag *tag, char const *frameid)
00135 {
00136 struct id3_frame *frame;
00137 union id3_field *field;
00138 char *string_int;
00139 unsigned int i;
00140 unsigned long result;
00141
00142 check(tag != NULL);
00143 check(frameid != NULL);
00144
00145 frame = id3_tag_findframe(tag, frameid, 0);
00146 if (frame == NULL)
00147 {
00148 return ID3_INT_ERROR;
00149 }
00150
00151 for(i=0; i < frame->nfields; i++)
00152 {
00153 field = id3_frame_field(frame, i);
00154 if (field == NULL)
00155 {
00156 return ID3_INT_ERROR;
00157 }
00158
00159 switch(id3_field_type(field))
00160 {
00161 case ID3_FIELD_TYPE_TEXTENCODING:
00162 case ID3_FIELD_TYPE_BINARYDATA:
00163 case ID3_FIELD_TYPE_LANGUAGE:
00164 case ID3_FIELD_TYPE_FRAMEID:
00165 case ID3_FIELD_TYPE_DATE:
00166
00167 break;
00168 case ID3_FIELD_TYPE_INT8:
00169 case ID3_FIELD_TYPE_INT16:
00170 case ID3_FIELD_TYPE_INT24:
00171 case ID3_FIELD_TYPE_INT32:
00172 case ID3_FIELD_TYPE_INT32PLUS:
00173 return id3_field_getint(field);
00174 break;
00175 case ID3_FIELD_TYPE_LATIN1:
00176 case ID3_FIELD_TYPE_LATIN1FULL:
00177 case ID3_FIELD_TYPE_LATIN1LIST:
00178 case ID3_FIELD_TYPE_STRING:
00179 case ID3_FIELD_TYPE_STRINGFULL:
00180 case ID3_FIELD_TYPE_STRINGLIST:
00181
00182 break;
00183 }
00184 }
00185
00186
00187 string_int = id3_get_string(tag, frameid);
00188 if (string_int != NULL)
00189 {
00190 result = atol(string_int);
00191 free(string_int);
00192
00193 return result;
00194 }
00195
00196 return ID3_INT_ERROR;
00197 }