| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifdef _MSC_VER |
| 18 |
#include "win32/zlib.h" |
| 19 |
#else |
| 20 |
#include <zlib.h> |
| 21 |
#endif |
| 22 |
|
| 23 |
#define ID3_BLOCK_SIZE 4096 |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#define ID3_FRAME_TITLE "TIT2" |
| 28 |
#define ID3_FRAME_ARTIST "TPE1" |
| 29 |
#define ID3_FRAME_ALBUM "TALB" |
| 30 |
#define ID3_FRAME_TRACK "TRCK" |
| 31 |
#define ID3_FRAME_YEAR "TDRC" |
| 32 |
#define ID3_FRAME_GENRE "TCON" |
| 33 |
#define ID3_FRAME_COMMENT "COMM" |
| 34 |
|
| 35 |
|
| 36 |
enum { |
| 37 |
ID3_TAG_FLAG_UNSYNCHRONISATION = 0x80, |
| 38 |
ID3_TAG_FLAG_EXTENDEDHEADER = 0x40, |
| 39 |
ID3_TAG_FLAG_EXPERIMENTALINDICATOR = 0x20, |
| 40 |
ID3_TAG_FLAG_FOOTERPRESENT = 0x10 |
| 41 |
}; |
| 42 |
|
| 43 |
|
| 44 |
enum { |
| 45 |
|
| 46 |
ID3_FRAME_FLAG_V23_COMPRESSION = 0x0080, |
| 47 |
ID3_FRAME_FLAG_V23_ENCRYPTION = 0x0040, |
| 48 |
ID3_FRAME_FLAG_V23_GROUPINGIDENTITY = 0x0020, |
| 49 |
|
| 50 |
|
| 51 |
ID3_FRAME_FLAG_V24_GROUPINGIDENTITY = 0x0040, |
| 52 |
ID3_FRAME_FLAG_V24_COMPRESSION = 0x0008, |
| 53 |
ID3_FRAME_FLAG_V24_ENCRYPTION = 0x0004, |
| 54 |
ID3_FRAME_FLAG_V24_UNSYNCHRONISATION = 0x0002, |
| 55 |
ID3_FRAME_FLAG_V24_DATALENGTHINDICATOR = 0x0001 |
| 56 |
}; |
| 57 |
|
| 58 |
enum id3_field_type { |
| 59 |
ID3_FIELD_TYPE_TEXTENCODING, |
| 60 |
ID3_FIELD_TYPE_LATIN1, |
| 61 |
ID3_FIELD_TYPE_LATIN1LIST, |
| 62 |
ID3_FIELD_TYPE_STRING, |
| 63 |
ID3_FIELD_TYPE_STRINGFULL, |
| 64 |
ID3_FIELD_TYPE_STRINGLIST, |
| 65 |
ID3_FIELD_TYPE_LANGUAGE, |
| 66 |
ID3_FIELD_TYPE_FRAMEID, |
| 67 |
ID3_FIELD_TYPE_DATE, |
| 68 |
ID3_FIELD_TYPE_INT8, |
| 69 |
ID3_FIELD_TYPE_INT16, |
| 70 |
ID3_FIELD_TYPE_INT24, |
| 71 |
ID3_FIELD_TYPE_INT32, |
| 72 |
ID3_FIELD_TYPE_INT32PLUS, |
| 73 |
ID3_FIELD_TYPE_BINARYDATA |
| 74 |
}; |
| 75 |
|
| 76 |
enum id3_field_textencoding { |
| 77 |
ISO_8859_1 = 0x00, |
| 78 |
UTF_16 = 0x01, |
| 79 |
UTF_16BE = 0x02, |
| 80 |
UTF_8 = 0x03 |
| 81 |
}; |
| 82 |
|
| 83 |
typedef struct id3info { |
| 84 |
PerlIO *infile; |
| 85 |
char *file; |
| 86 |
Buffer *buf; |
| 87 |
HV *info; |
| 88 |
HV *tags; |
| 89 |
|
| 90 |
|
| 91 |
Buffer *utf8; |
| 92 |
|
| 93 |
uint8_t version_major; |
| 94 |
uint8_t version_minor; |
| 95 |
uint8_t flags; |
| 96 |
uint8_t tag_data_safe; |
| 97 |
uint32_t size; |
| 98 |
uint32_t size_remain; |
| 99 |
off_t offset; |
| 100 |
} id3info; |
| 101 |
|
| 102 |
typedef struct id3_compat { |
| 103 |
char const *id; |
| 104 |
char const *equiv; |
| 105 |
} id3_compat; |
| 106 |
|
| 107 |
typedef struct id3_frametype { |
| 108 |
char const *id; |
| 109 |
unsigned int nfields; |
| 110 |
enum id3_field_type const *fields; |
| 111 |
char const *description; |
| 112 |
} id3_frametype; |
| 113 |
|
| 114 |
extern struct id3_frametype const id3_frametype_text; |
| 115 |
extern struct id3_frametype const id3_frametype_url; |
| 116 |
extern struct id3_frametype const id3_frametype_experimental; |
| 117 |
extern struct id3_frametype const id3_frametype_unknown; |
| 118 |
extern struct id3_frametype const id3_frametype_obsolete; |
| 119 |
|
| 120 |
int parse_id3(PerlIO *infile, char *file, HV *info, HV *tags, off_t seek, off_t file_size); |
| 121 |
int _id3_parse_v1(id3info *id3); |
| 122 |
int _id3_parse_v2(id3info *id3); |
| 123 |
int _id3_parse_v2_frame(id3info *id3); |
| 124 |
int _id3_parse_v2_frame_data(id3info *id3, char const *id, uint32_t size, id3_frametype const *frametype); |
| 125 |
void _id3_set_array_tag(id3info *id3, char const *id, AV *framedata); |
| 126 |
uint32_t _id3_get_v1_utf8_string(id3info *id3, SV **string, uint32_t len); |
| 127 |
uint32_t _id3_get_utf8_string(id3info *id3, SV **string, uint32_t len, uint8_t encoding); |
| 128 |
uint32_t _id3_parse_rvad(id3info *id3, char const *id, uint32_t size); |
| 129 |
uint32_t _id3_parse_rgad(id3info *id3); |
| 130 |
uint32_t _id3_parse_rva2(id3info *id3, uint32_t len, AV *framedata); |
| 131 |
uint32_t _id3_parse_sylt(id3info *id3, uint8_t encoding, uint32_t len, AV *framedata); |
| 132 |
uint32_t _id3_parse_etco(id3info *id3, uint32_t len, AV *framedata); |
| 133 |
void _id3_convert_tdrc(id3info *id3); |
| 134 |
uint32_t _id3_deunsync(unsigned char *data, uint32_t length); |
| 135 |
void _id3_skip(id3info *id3, uint32_t size); |
| 136 |
char const * _id3_genre_index(unsigned int index); |
| 137 |
char const * _id3_genre_name(char const *string); |
| 138 |
static id3_compat const * _id3_compat_lookup(register char const *, register unsigned int); |
| 139 |
const struct id3_frametype * _id3_frametype_lookup(register const char *, register size_t); |