annotate src/wavpack/tags.cxx @ 1737:b729c7a72c20

- remove get_song_info interface. - remove dependency to real_ip's get_song_info.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Wed, 19 Sep 2007 18:00:10 +0900
parents f6f5603a0954
children fa9f85cebade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
1 #include <stdlib.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
2 #include <stdio.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
3 #include <string.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
4 #include <unistd.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
5 #include <fcntl.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
6 #include <wchar.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
7 #include <audacious/util.h>
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
8 #include <audacious/vfs.h>
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
9 #include "tags.h"
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
10
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
11 struct APETagFooterStruct {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
12 unsigned char ID[8];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
13 unsigned char Version[4];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
14 unsigned char Length[4];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
15 unsigned char TagCount[4];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
16 unsigned char Flags[4];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
17 unsigned char Reserved[8];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
18 };
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
19
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
20 typedef struct {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
21 char *key;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
22 size_t keylen;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
23 unsigned char *value;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
24 size_t valuelen;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
25 unsigned int flags;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
26 } TagItem;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
27
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
28 unsigned long
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
29 Read_LE_Uint32(const unsigned char *p)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
30 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
31 return ((unsigned long) p[0] << 0) |
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
32 ((unsigned long) p[1] << 8) |
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
33 ((unsigned long) p[2] << 16) | ((unsigned long) p[3] << 24);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
34 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
35
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
36 // Convert UTF-8 coded string to UNICODE
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
37 // Return number of characters converted
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
38 int
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
39 utf8ToUnicode(const char *lpMultiByteStr, wchar_t * lpWideCharStr,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
40 int cmbChars)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
41 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
42 const unsigned char *pmb = (unsigned char *) lpMultiByteStr;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
43 unsigned short *pwc = (unsigned short *) lpWideCharStr;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
44 const unsigned char *pmbe;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
45 size_t cwChars = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
46
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
47 if (cmbChars >= 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
48 pmbe = pmb + cmbChars;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
49 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
50 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
51 pmbe = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
52 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
53
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
54 while ((pmbe == NULL) || (pmb < pmbe)) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
55 char mb = *pmb++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
56 unsigned int cc = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
57 unsigned int wc;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
58
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
59 while ((cc < 7) && (mb & (1 << (7 - cc)))) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
60 cc++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
61 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
62
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
63 if (cc == 1 || cc > 6) // illegal character combination for UTF-8
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
64 continue;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
65
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
66 if (cc == 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
67 wc = mb;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
68 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
69 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
70 wc = (mb & ((1 << (7 - cc)) - 1)) << ((cc - 1) * 6);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
71 while (--cc > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
72 if (pmb == pmbe) // reached end of the buffer
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
73 return cwChars;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
74 mb = *pmb++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
75 if (((mb >> 6) & 0x03) != 2) // not part of multibyte character
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
76 return cwChars;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
77 wc |= (mb & 0x3F) << ((cc - 1) * 6);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
78 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
79 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
80
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
81 if (wc & 0xFFFF0000)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
82 wc = L'?';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
83 *pwc++ = wc;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
84 cwChars++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
85 if (wc == L'\0')
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
86 return cwChars;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
87 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
88
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
89 return cwChars;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
90 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
91
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
92 void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
93 tag_insert(char *buffer, const char *value, long unsigned int len,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
94 long unsigned int maxlen, bool decode_utf8)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
95 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
96 char *p;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
97 wchar_t wValue[MAX_LEN];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
98 char temp[MAX_LEN];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
99 long unsigned int c;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
100 const wchar_t *src = wValue;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
101
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
102 if (len >= maxlen)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
103 len = maxlen - 1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
104 if (decode_utf8) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
105 if ((c = utf8ToUnicode(value, wValue, len)) <= 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
106 return;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
107 if (wValue[c] != L'\0')
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
108 wValue[c++] = L'\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
109 if ((c = wcsrtombs(temp, &src, MAX_LEN, NULL)) == 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
110 return;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
111 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
112 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
113 c = len;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
114 strncpy(temp, value, len);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
115 while (temp[len - 1] == 0x20 || len < 1) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
116 len--;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
117 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
118 temp[len] = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
119 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
120
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
121 //if ( *buffer == '\0' ) { // new value
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
122 p = buffer;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
123 //} else { // append to existing value
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
124 // p = strchr (buffer, '\0' );
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
125 // p += sprintf ( p, ", " );
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
126 //}
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
127
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
128 if ((p - buffer) + c >= maxlen)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
129 c = maxlen - (p - buffer) - 1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
130 strncpy(p, temp, c);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
131 p[c] = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
132 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
133
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
134 // Returns the Type of Tag (Ape or ID3)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
135 int
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
136 GetTageType(VFSFile * fp)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
137 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
138 struct APETagFooterStruct T;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
139 unsigned char tagheader[3];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
140 int size;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
141
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
142 if (fp == NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
143 return TAG_NONE;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
144 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
145
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
146 if (vfs_fseek(fp, 0, SEEK_END) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
147 return TAG_NONE;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
148 size = vfs_ftell(fp);
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
149 if (vfs_fseek(fp, size - sizeof T, SEEK_SET) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
150 return TAG_NONE;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
151 if (vfs_fread(&T, 1, sizeof T, fp) != sizeof T)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
152 return TAG_NONE;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
153 if (memcmp(T.ID, "APETAGEX", sizeof T.ID) == 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
154 return TAG_APE;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
155 if (vfs_fseek(fp, -128L, SEEK_END) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
156 return TAG_NONE;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
157 if (vfs_fread(tagheader, 1, 3, fp) != 3)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
158 return TAG_NONE;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
159 if (0 == memcmp(tagheader, "TAG", 3))
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
160 return TAG_ID3;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
161 return TAG_NONE;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
162 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
163
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
164
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
165 int
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
166 ReadID3Tag(VFSFile * fp, ape_tag * Tag)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
167 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
168 char *tag;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
169 char *buff;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
170 unsigned int genre;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
171
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
172 buff = (char *) malloc(128);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
173
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
174 *(Tag->title) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
175 *(Tag->artist) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
176 *(Tag->album) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
177 *(Tag->comment) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
178 *(Tag->genre) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
179 *(Tag->track) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
180 *(Tag->year) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
181
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
182 if (vfs_fseek(fp, -128L, SEEK_END) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
183 return 0;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
184 if (vfs_fread(buff, 1, 128, fp) != 128)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
185 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
186 tag = buff;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
187 tag_insert(Tag->title, (tag + 3), 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
188 tag_insert(Tag->artist, (tag + 33), 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
189 tag_insert(Tag->album, (tag + 63), 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
190 tag_insert(Tag->year, (tag + 93), 4, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
191 tag_insert(Tag->comment, (tag + 97), 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
192 genre = (unsigned char) tag[127];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
193 if (genre >= sizeof(GenreList) / sizeof(int))
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
194 genre = 12;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
195 tag_insert(Tag->genre, GenreList[genre], 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
196 sprintf(tag, "%u", tag[126]);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
197 tag_insert(Tag->track, tag, 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
198 free(buff);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
199 return 1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
200 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
201
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
202 // Reads APE v2.0 tag
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
203 int
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
204 ReadAPE2Tag(VFSFile * fp, ape_tag * Tag)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
205 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
206 unsigned long vsize;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
207 unsigned long isize;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
208 unsigned long flags;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
209 unsigned char *buff;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
210 unsigned char *p;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
211 unsigned char *end;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
212 struct APETagFooterStruct T;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
213 unsigned long TagLen;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
214 unsigned long TagCount;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
215 long size;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
216
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
217 *(Tag->title) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
218 *(Tag->artist) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
219 *(Tag->album) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
220 *(Tag->comment) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
221 *(Tag->genre) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
222 *(Tag->track) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
223 *(Tag->year) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
224
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
225 if (vfs_fseek(fp, 0, SEEK_END) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
226 return 0;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
227 size = vfs_ftell(fp);
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
228 if (vfs_fseek(fp, size - sizeof T, SEEK_SET) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
229 return 0;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
230 if (vfs_fread(&T, 1, sizeof T, fp) != sizeof T)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
231 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
232 if (memcmp(T.ID, "APETAGEX", sizeof T.ID) != 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
233 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
234 if (Read_LE_Uint32(T.Version) != 2000)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
235 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
236 TagLen = Read_LE_Uint32(T.Length);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
237 if (TagLen < sizeof T)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
238 return 0;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
239 if (vfs_fseek(fp, size - TagLen, SEEK_SET) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
240 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
241 if ((buff = (unsigned char *) malloc(TagLen)) == NULL)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
242 return 0;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
243 if (vfs_fread(buff, 1, TagLen - sizeof T, fp) != TagLen - sizeof T) {
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
244 free(buff);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
245 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
246 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
247
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
248 TagCount = Read_LE_Uint32(T.TagCount);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
249 end = buff + TagLen - sizeof(T);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
250 for (p = buff; p < end && TagCount--;) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
251 vsize = Read_LE_Uint32(p);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
252 p += 4;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
253 flags = Read_LE_Uint32(p);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
254 p += 4;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
255 isize = strlen((char *) p);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
256
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
257 if (isize > 0 && vsize > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
258 if (!(flags & 1 << 1)) { // insert UTF-8 string (skip binary values)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
259 if (!strcasecmp((char *) p, "Title")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
260 tag_insert(Tag->title, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
261 MAX_LEN, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
262 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
263 else if (!strcasecmp((char *) p, "Artist")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
264 tag_insert(Tag->artist, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
265 MAX_LEN, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
266 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
267 else if (!strcasecmp((char *) p, "Album")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
268 tag_insert(Tag->album, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
269 MAX_LEN, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
270 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
271 else if (!strcasecmp((char *) p, "Comment")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
272 tag_insert(Tag->comment, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
273 MAX_LEN, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
274 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
275 else if (!strcasecmp((char *) p, "Genre")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
276 tag_insert(Tag->genre, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
277 MAX_LEN, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
278 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
279 else if (!strcasecmp((char *) p, "Track")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
280 tag_insert(Tag->track, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
281 128, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
282 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
283 else if (!strcasecmp((char *) p, "Year")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
284 tag_insert(Tag->year, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
285 128, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
286 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
287 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
288 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
289 p += isize + 1 + vsize;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
290 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
291 free(buff);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
292 return 1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
293 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
294
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
295 int
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
296 DeleteTag(char *filename)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
297 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
298
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
299 VFSFile *fp = vfs_fopen(filename, "rb+");
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
300 int tagtype;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
301 int fd;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
302 long filelength = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
303 long dellength = -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
304 char *tagheader;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
305 unsigned long *apelength;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
306 int res = -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
307
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
308 if (fp == NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
309 char text[256];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
310
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
311 sprintf(text, "File \"%s\" not found or is read protected!\n",
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
312 filename);
1677
f6f5603a0954 xmms_show_message() changed to audacious_info_dialog()
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
313 audacious_info_dialog("File-Error", (gchar *) text, "Ok", FALSE, NULL,
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
314 NULL);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
315 return -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
316 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
317 tagtype = GetTageType(fp);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
318
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
319 // get Length of File
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
320 vfs_fseek(fp, 0L, SEEK_END);
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
321 filelength = vfs_ftell(fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
322
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
323 apelength = (unsigned long *) malloc(4);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
324 tagheader = (char *) malloc(9);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
325
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
326 if (tagtype == TAG_ID3) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
327 dellength = 128L;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
328 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
329 else if (tagtype == TAG_APE) {
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
330 vfs_fseek(fp, -32L, SEEK_END);
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
331 vfs_fread(tagheader, 8, 1, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
332 if (0 == memcmp(tagheader, "APETAGEX", 8)) {
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
333 vfs_fseek(fp, -20L, SEEK_END);
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
334 vfs_fread(apelength, 4, 1, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
335 dellength = *apelength + 32;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
336 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
337 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
338
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
339
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
340 if (dellength > -1) //if TAG was found, delete it
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
341 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
342 fd = open(filename, O_RDWR);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
343 res = ftruncate(fd, (off_t) (filelength - dellength));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
344 close(fd);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
345 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
346
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
347 free(tagheader);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
348 free(apelength);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
349
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
350 //returns 0 if everything is ok
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
351 return res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
352 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
353
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
354 // Returns bytes used in APE-Tag for this value
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
355 int
1044
b1128efde471 [svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents: 265
diff changeset
356 addValue(TagItem * item, const char *key, char *value)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
357 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
358 item->keylen = strlen(key);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
359 item->valuelen = strlen(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
360 item->key = (char *) malloc(item->keylen + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
361 item->value = (unsigned char *) malloc(item->valuelen + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
362 strcpy((char *) item->value, value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
363 strcpy(item->key, key);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
364 item->flags = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
365 return (9 + item->keylen + item->valuelen);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
366 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
367
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
368 int
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
369 WriteAPE2Tag(char *filename, ape_tag * Tag)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
370 {
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
371 VFSFile *fp;
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
372 unsigned char H[32] = "APETAGEX";
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
373 unsigned long Version = 2000;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
374 unsigned char dw[8];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
375 unsigned long estimatedbytes = 32; // 32 byte footer + all items, these are the 32 bytes footer, the items are added later
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
376 long writtenbytes = -32; // actually writtenbytes-32, which should be equal to estimatedbytes (= footer + all items)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
377 unsigned int TagCount = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
378 TagItem T[7];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
379
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
380
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
381 // Delete Tag if there is one
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
382 fp = vfs_fopen(filename, "rb+");
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
383 if (fp == NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
384 char text[256];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
385
1159
a03aec49af4d [svn] Replace sprintf with snprintf.
js
parents: 1044
diff changeset
386 snprintf(text, 256, "File \"%s\" not found or is read protected!\n",
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
387 filename);
1677
f6f5603a0954 xmms_show_message() changed to audacious_info_dialog()
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
388 audacious_info_dialog("File-Error", (gchar *) text, "Ok", FALSE, NULL,
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
389 NULL);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
390 return -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
391 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
392
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
393 int tagtype = GetTageType(fp);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
394
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
395 if (tagtype != TAG_NONE)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
396 if (DeleteTag(filename) != 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
397 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
398
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
399 // Produce TagItem-Array
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
400 if (strlen(Tag->title) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
401 char *value = (char *) malloc(strlen(Tag->title) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
402
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
403 strcpy(value, Tag->title);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
404 int res = addValue(&T[TagCount], "Title", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
405
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
406 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
407 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
408 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
409 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
410 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
411
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
412 if (strlen(Tag->artist) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
413 char *value = (char *) malloc(strlen(Tag->artist) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
414
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
415 strcpy(value, Tag->artist);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
416 int res = addValue(&T[TagCount], "Artist", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
417
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
418 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
419 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
420 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
421 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
422 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
423
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
424 if (strlen(Tag->album) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
425 char *value = (char *) malloc(strlen(Tag->album) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
426
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
427 strcpy(value, Tag->album);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
428 int res = addValue(&T[TagCount], "Album", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
429
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
430 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
431 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
432 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
433 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
434 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
435
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
436 if (strlen(Tag->comment) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
437 char *value = (char *) malloc(strlen(Tag->comment) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
438
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
439 strcpy(value, Tag->comment);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
440 int res = addValue(&T[TagCount], "Comment", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
441
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
442 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
443 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
444 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
445 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
446 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
447
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
448 if (strlen(Tag->genre) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
449 char *value = (char *) malloc(strlen(Tag->genre) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
450
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
451 strcpy(value, Tag->genre);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
452 int res = addValue(&T[TagCount], "Genre", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
453
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
454 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
455 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
456 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
457 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
458 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
459
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
460 if (strlen(Tag->track) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
461 char *value = (char *) malloc(strlen(Tag->track) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
462
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
463 strcpy(value, Tag->track);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
464 int res = addValue(&T[TagCount], "Track", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
465
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
466 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
467 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
468 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
469 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
470 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
471
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
472 if (strlen(Tag->year) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
473 char *value = (char *) malloc(strlen(Tag->year) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
474
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
475 strcpy(value, Tag->year);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
476 int res = addValue(&T[TagCount], "Year", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
477
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
478 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
479 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
480 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
481 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
482 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
483 // Start writing the new Ape2 Tag
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
484 vfs_fseek(fp, 0L, SEEK_END);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
485
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
486 if (TagCount == 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
487 printf("no tag to write");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
488 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
489 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
490
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
491 if (estimatedbytes >= 8192 + 103) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
492 printf
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
493 ("\nTag is %.1f Kbyte long. This is longer than the maximum recommended 8 KByte.\n\a",
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
494 estimatedbytes / 1024.);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
495 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
496 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
497
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
498 H[8] = Version >> 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
499 H[9] = Version >> 8;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
500 H[10] = Version >> 16;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
501 H[11] = Version >> 24;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
502 H[12] = estimatedbytes >> 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
503 H[13] = estimatedbytes >> 8;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
504 H[14] = estimatedbytes >> 16;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
505 H[15] = estimatedbytes >> 24;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
506 H[16] = TagCount >> 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
507 H[17] = TagCount >> 8;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
508 H[18] = TagCount >> 16;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
509 H[19] = TagCount >> 24;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
510
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
511 H[23] = 0x80 | 0x20;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
512 writtenbytes += vfs_fwrite(H, 1, 32, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
513
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
514 for (unsigned int i = 0; i < TagCount; i++) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
515 dw[0] = T[i].valuelen >> 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
516 dw[1] = T[i].valuelen >> 8;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
517 dw[2] = T[i].valuelen >> 16;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
518 dw[3] = T[i].valuelen >> 24;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
519 dw[4] = T[i].flags >> 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
520 dw[5] = T[i].flags >> 8;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
521 dw[6] = T[i].flags >> 16;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
522 dw[7] = T[i].flags >> 24;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
523 writtenbytes += vfs_fwrite(dw, 1, 8, fp);
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
524 writtenbytes += vfs_fwrite(T[i].key, 1, T[i].keylen, fp);
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
525 writtenbytes += vfs_fwrite("", 1, 1, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
526 if (T[i].valuelen > 0)
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
527 writtenbytes += vfs_fwrite(T[i].value, 1, T[i].valuelen, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
528 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
529
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
530 H[23] = 0x80;
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
531 writtenbytes += vfs_fwrite(H, 1, 32, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
532
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
533 if (estimatedbytes != (unsigned long) writtenbytes)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
534 printf("\nError writing APE tag.\n");
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
535 vfs_fclose(fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
536 TagCount = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
537 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
538 }