290
|
1 #include <stdio.h>
|
|
2 #include <malloc.h>
|
|
3 #include <string.h>
|
|
4 #include "ttalib.h"
|
|
5 #include "id3genre.h"
|
|
6 #include "audacious/util.h"
|
|
7 #include <stdlib.h>
|
|
8 #include <audacious/titlestring.h>
|
|
9
|
|
10 /***********************************************************************
|
|
11 * ID3 tags manipulation routines
|
|
12 *
|
|
13 * Provides read access to ID3v1 tags v1.1, ID3v2 tags v2.3.x and above
|
|
14 * Supported ID3v2 frames: Title, Artist, Album, Track, Year,
|
|
15 * Genre, Comment.
|
|
16 *
|
|
17 **********************************************************************/
|
|
18
|
|
19 static unsigned int unpack_sint28 (const char *ptr) {
|
|
20 unsigned int value = 0;
|
|
21
|
|
22 if (ptr[0] & 0x80) return 0;
|
|
23
|
|
24 value = value | (ptr[0] & 0x7f);
|
|
25 value = (value << 7) | (ptr[1] & 0x7f);
|
|
26 value = (value << 7) | (ptr[2] & 0x7f);
|
|
27 value = (value << 7) | (ptr[3] & 0x7f);
|
|
28
|
|
29 return value;
|
|
30 }
|
|
31
|
|
32 static unsigned int unpack_sint32 (const char *ptr) {
|
|
33 unsigned int value = 0;
|
|
34
|
|
35 if (ptr[0] & 0x80) return 0;
|
|
36
|
|
37 value = (value << 8) | ptr[0];
|
|
38 value = (value << 8) | ptr[1];
|
|
39 value = (value << 8) | ptr[2];
|
|
40 value = (value << 8) | ptr[3];
|
|
41
|
|
42 return value;
|
|
43 }
|
|
44
|
|
45 static int get_frame_id (const char *id) {
|
|
46 if (!memcmp(id, "TIT2", 4)) return TIT2; // Title
|
|
47 if (!memcmp(id, "TPE1", 4)) return TPE1; // Artist
|
|
48 if (!memcmp(id, "TALB", 4)) return TALB; // Album
|
|
49 if (!memcmp(id, "TRCK", 4)) return TRCK; // Track
|
|
50 if (!memcmp(id, "TYER", 4)) return TYER; // Year
|
|
51 if (!memcmp(id, "TCON", 4)) return TCON; // Genre
|
|
52 if (!memcmp(id, "COMM", 4)) return COMM; // Comment
|
|
53 return 0;
|
|
54 }
|
|
55
|
|
56 int skip_v2_header(tta_info *ttainfo) {
|
|
57 id3v2_tag id3v2;
|
|
58 id3v2_frame frame_header;
|
|
59 int id3v2_size;
|
|
60 unsigned char *buffer, *ptr;
|
|
61 gchar *utf;
|
|
62 gchar tmp[MAX_LINE];
|
|
63 gchar *tmpptr;
|
|
64 int tmplen;
|
|
65
|
|
66 if (!fread(&id3v2, 1, sizeof (id3v2_tag), ttainfo->HANDLE) ||
|
|
67 memcmp(id3v2.id, "ID3", 3))
|
|
68 {
|
|
69 fseek (ttainfo->HANDLE, 0, SEEK_SET);
|
|
70 return 0;
|
|
71 }
|
|
72
|
|
73 id3v2_size = unpack_sint28(id3v2.size) + 10;
|
|
74
|
|
75 fseek (ttainfo->HANDLE, id3v2_size, SEEK_SET);
|
|
76 ttainfo->id3v2.size = id3v2_size;
|
|
77
|
|
78 return id3v2_size;
|
|
79 }
|
|
80
|
|
81 /* eof */
|