annotate src/tta/id3.c @ 439:84029a5250c1 trunk

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