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