Mercurial > mplayer.hg
annotate stream/stream_cddb.c @ 25456:d7e586404846
Avoid some le2me_ASF_* stuff operating directly on buffer, should
simplify some future changes
author | reimar |
---|---|
date | Fri, 21 Dec 2007 11:46:58 +0000 |
parents | 454ab8a40f1c |
children | cf1d3164d30c |
rev | line source |
---|---|
6474 | 1 /* |
2 * CDDB HTTP protocol | |
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com> | |
4 * (C) 2002, MPlayer team. | |
5 * | |
6 * Implementation follow the freedb.howto1.06.txt specification | |
7 * from http://freedb.freedb.org | |
8 * | |
9 * discid computation by Jeremy D. Zawodny | |
10 * Copyright (c) 1998-2000 Jeremy D. Zawodny <Jeremy@Zawodny.com> | |
11 * Code release under GPL | |
12 * | |
13 */ | |
14 | |
15 #include "config.h" | |
16 | |
17 #include <stdio.h> | |
18 #include <stdlib.h> | |
19 #include <fcntl.h> | |
20 #include <stdarg.h> | |
21 #include <errno.h> | |
22 #include <unistd.h> | |
23 #include <string.h> | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
24 #ifdef WIN32 |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
25 #ifdef __MINGW32__ |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
26 #define mkdir(a,b) mkdir(a) |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
27 #endif |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
28 #include <windows.h> |
17446 | 29 #ifdef HAVE_WINSOCK2 |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
30 #include <winsock2.h> |
17446 | 31 #endif |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
32 #else |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
33 #include <netdb.h> |
6474 | 34 #include <sys/ioctl.h> |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
35 #endif |
6474 | 36 #include <sys/types.h> |
37 #include <sys/stat.h> | |
38 | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
39 #include "mp_msg.h" |
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
40 #include "help_mp.h" |
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
41 |
6474 | 42 #if defined(__linux__) |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
43 #include <linux/cdrom.h> |
21848 | 44 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
45 #include <sys/cdio.h> |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
46 #elif defined(WIN32) |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
47 #include <ddk/ntddcdrm.h> |
17044
cb84dbc30d7b
When it comes to CD/DVD handling bsdi has a linux CD/DVD compatibility
diego
parents:
17012
diff
changeset
|
48 #elif (__bsdi__) |
cb84dbc30d7b
When it comes to CD/DVD handling bsdi has a linux CD/DVD compatibility
diego
parents:
17012
diff
changeset
|
49 #include <dvd.h> |
25393 | 50 #elif defined(__APPLE__) || defined(__DARWIN__) |
51 #include <IOKit/storage/IOCDTypes.h> | |
52 #include <IOKit/storage/IOCDMediaBSDClient.h> | |
53 #include "mpbswap.h" | |
6474 | 54 #endif |
55 | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
56 #include "cdd.h" |
17012 | 57 #include "version.h" |
6474 | 58 #include "stream.h" |
59 #include "network.h" | |
60 | |
61 #define DEFAULT_FREEDB_SERVER "freedb.freedb.org" | |
62 #define DEFAULT_CACHE_DIR "/.cddb/" | |
63 | |
64 stream_t* open_cdda(char *dev, char *track); | |
65 | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
66 static cd_toc_t cdtoc[100]; |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
67 static int cdtoc_last_track; |
6474 | 68 |
69 int | |
8962 | 70 read_toc(const char *dev) { |
25393 | 71 int first = 0, last = -1; |
20581
bfcc98ad59ba
Factor out common code in stream_cddb read_toc function.
reimar
parents:
20579
diff
changeset
|
72 int i; |
20586
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
73 #ifdef WIN32 |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
74 HANDLE drive; |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
75 DWORD r; |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
76 CDROM_TOC toc; |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
77 char device[10]; |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
78 |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
79 sprintf(device, "\\\\.\\%s", dev); |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
80 drive = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
81 |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
82 if(!DeviceIoControl(drive, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(CDROM_TOC), &r, 0)) { |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
83 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToReadTOC); |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
84 return 0; |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
85 } |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
86 |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
87 first = toc.FirstTrack - 1; last = toc.LastTrack; |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
88 for (i = first; i <= last; i++) { |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
89 cdtoc[i].min = toc.TrackData[i].Address[1]; |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
90 cdtoc[i].sec = toc.TrackData[i].Address[2]; |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
91 cdtoc[i].frame = toc.TrackData[i].Address[3]; |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
92 } |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
93 CloseHandle(drive); |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
94 |
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
95 #else |
8962 | 96 int drive; |
97 drive = open(dev, O_RDONLY | O_NONBLOCK); | |
98 if( drive<0 ) { | |
99 return drive; | |
100 } | |
101 | |
20587 | 102 #if defined(__linux__) || defined(__bsdi__) |
103 { | |
104 struct cdrom_tochdr tochdr; | |
6474 | 105 ioctl(drive, CDROMREADTOCHDR, &tochdr); |
20581
bfcc98ad59ba
Factor out common code in stream_cddb read_toc function.
reimar
parents:
20579
diff
changeset
|
106 first = tochdr.cdth_trk0 - 1; last = tochdr.cdth_trk1; |
20587 | 107 } |
20583 | 108 for (i = first; i <= last; i++) { |
20587 | 109 struct cdrom_tocentry tocentry; |
23269
6606c4f5c78c
Fix track info being read for the wrong track introduced in r20598
reimar
parents:
23268
diff
changeset
|
110 tocentry.cdte_track = (i == last) ? 0xAA : i + 1; |
6474 | 111 tocentry.cdte_format = CDROM_MSF; |
112 ioctl(drive, CDROMREADTOCENTRY, &tocentry); | |
20582 | 113 cdtoc[i].min = tocentry.cdte_addr.msf.minute; |
114 cdtoc[i].sec = tocentry.cdte_addr.msf.second; | |
115 cdtoc[i].frame = tocentry.cdte_addr.msf.frame; | |
6474 | 116 } |
21848 | 117 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
20587 | 118 { |
6474 | 119 struct ioc_toc_header tochdr; |
120 ioctl(drive, CDIOREADTOCHEADER, &tochdr); | |
23268
686107ddaab5
Missing -1 in the FreeBSD code to get the first CD track number
reimar
parents:
21848
diff
changeset
|
121 first = tochdr.starting_track - 1; last = tochdr.ending_track; |
20587 | 122 } |
20583 | 123 for (i = first; i <= last; i++) { |
20587 | 124 struct ioc_read_toc_single_entry tocentry; |
23269
6606c4f5c78c
Fix track info being read for the wrong track introduced in r20598
reimar
parents:
23268
diff
changeset
|
125 tocentry.track = (i == last) ? 0xAA : i + 1; |
6474 | 126 tocentry.address_format = CD_MSF_FORMAT; |
127 ioctl(drive, CDIOREADTOCENTRY, &tocentry); | |
20582 | 128 cdtoc[i].min = tocentry.entry.addr.msf.minute; |
129 cdtoc[i].sec = tocentry.entry.addr.msf.second; | |
130 cdtoc[i].frame = tocentry.entry.addr.msf.frame; | |
6474 | 131 } |
8962 | 132 #elif defined(__NetBSD__) || defined(__OpenBSD__) |
20587 | 133 { |
8609
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
134 struct ioc_toc_header tochdr; |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
135 ioctl(drive, CDIOREADTOCHEADER, &tochdr); |
20581
bfcc98ad59ba
Factor out common code in stream_cddb read_toc function.
reimar
parents:
20579
diff
changeset
|
136 first = tochdr.starting_track - 1; last = tochdr.ending_track; |
20587 | 137 } |
20583 | 138 for (i = first; i <= last; i++) { |
20587 | 139 struct ioc_read_toc_entry tocentry; |
140 struct cd_toc_entry toc_buffer; | |
23269
6606c4f5c78c
Fix track info being read for the wrong track introduced in r20598
reimar
parents:
23268
diff
changeset
|
141 tocentry.starting_track = (i == last) ? 0xAA : i + 1; |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
142 tocentry.address_format = CD_MSF_FORMAT; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
143 tocentry.data = &toc_buffer; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
144 tocentry.data_len = sizeof(toc_buffer); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
145 ioctl(drive, CDIOREADTOCENTRYS, &tocentry); |
20582 | 146 cdtoc[i].min = toc_buffer.addr.msf.minute; |
147 cdtoc[i].sec = toc_buffer.addr.msf.second; | |
148 cdtoc[i].frame = toc_buffer.addr.msf.frame; | |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
149 } |
25393 | 150 #elif defined(__APPLE__) || defined(__DARWIN__) |
151 { | |
152 dk_cd_read_toc_t tochdr; | |
153 uint8_t buf[4]; | |
154 uint8_t buf2[100 * sizeof(CDTOCDescriptor) + sizeof(CDTOC)]; | |
155 memset(&tochdr, 0, sizeof(tochdr)); | |
156 tochdr.bufferLength = sizeof(buf); | |
157 tochdr.buffer = &buf; | |
158 if (!ioctl(drive, DKIOCCDREADTOC, &tochdr) | |
159 && tochdr.bufferLength == sizeof(buf)) { | |
160 first = buf[2] - 1; | |
161 last = buf[3]; | |
162 } | |
163 if (last >= 0) { | |
164 memset(&tochdr, 0, sizeof(tochdr)); | |
165 tochdr.bufferLength = sizeof(buf2); | |
166 tochdr.buffer = &buf2; | |
167 tochdr.format = kCDTOCFormatTOC; | |
168 if (ioctl(drive, DKIOCCDREADTOC, &tochdr) | |
169 || tochdr.bufferLength < sizeof(CDTOC)) | |
170 last = -1; | |
171 } | |
172 if (last >= 0) { | |
173 CDTOC *cdToc = (CDTOC *)buf2; | |
174 CDTrackInfo lastTrack; | |
175 dk_cd_read_track_info_t trackInfoParams; | |
176 for (i = first; i < last; ++i) { | |
177 CDMSF msf = CDConvertTrackNumberToMSF(i + 1, cdToc); | |
178 cdtoc[i].min = msf.minute; | |
179 cdtoc[i].sec = msf.second; | |
180 cdtoc[i].frame = msf.frame; | |
181 } | |
182 memset(&trackInfoParams, 0, sizeof(trackInfoParams)); | |
183 trackInfoParams.addressType = kCDTrackInfoAddressTypeTrackNumber; | |
184 trackInfoParams.bufferLength = sizeof(lastTrack); | |
185 trackInfoParams.address = last; | |
186 trackInfoParams.buffer = &lastTrack; | |
187 if (!ioctl(drive, DKIOCCDREADTRACKINFO, &trackInfoParams)) { | |
188 CDMSF msf = CDConvertLBAToMSF(be2me_32(lastTrack.trackStartAddress) | |
189 + be2me_32(lastTrack.trackSize)); | |
190 cdtoc[last].min = msf.minute; | |
191 cdtoc[last].sec = msf.second; | |
192 cdtoc[last].frame = msf.frame; | |
193 } | |
194 } | |
195 } | |
20587 | 196 #endif |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
197 close(drive); |
20581
bfcc98ad59ba
Factor out common code in stream_cddb read_toc function.
reimar
parents:
20579
diff
changeset
|
198 #endif |
bfcc98ad59ba
Factor out common code in stream_cddb read_toc function.
reimar
parents:
20579
diff
changeset
|
199 for (i = first; i <= last; i++) |
bfcc98ad59ba
Factor out common code in stream_cddb read_toc function.
reimar
parents:
20579
diff
changeset
|
200 cdtoc[i].frame += (cdtoc[i].min * 60 + cdtoc[i].sec) * 75; |
bfcc98ad59ba
Factor out common code in stream_cddb read_toc function.
reimar
parents:
20579
diff
changeset
|
201 return last; |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
202 } |
6474 | 203 |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
204 /** |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
205 \brief Reads TOC from CD in the given device and prints the number of tracks |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
206 and the length of each track in minute:second:frame format. |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
207 \param *dev the device to analyse |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
208 \return if the command line -identify is given, returns the last track of |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
209 the TOC or -1 if the TOC can't be read, |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
210 otherwise just returns 0 and let cddb_resolve the TOC |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
211 */ |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
212 int cdd_identify(const char *dev) |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
213 { |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
214 cdtoc_last_track = 0; |
18237
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
18176
diff
changeset
|
215 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
216 { |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
217 int i, min, sec, frame; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
218 cdtoc_last_track = read_toc(dev); |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
219 if (cdtoc_last_track < 0) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
220 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice, dev); |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
221 return -1; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
222 } |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
223 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_CDDA_TRACKS=%d\n", cdtoc_last_track); |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
224 for (i = 1; i <= cdtoc_last_track; i++) |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
225 { |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
226 frame = cdtoc[i].frame - cdtoc[i-1].frame; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
227 sec = frame / 75; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
228 frame -= sec * 75; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
229 min = sec / 60; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
230 sec -= min * 60; |
18237
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
18176
diff
changeset
|
231 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDA_TRACK_%d_MSF=%02d:%02d:%02d\n", i, min, sec, frame); |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
232 } |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
233 } |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
234 return cdtoc_last_track; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
235 } |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
236 |
6474 | 237 unsigned int |
238 cddb_sum(int n) { | |
239 unsigned int ret; | |
240 | |
241 ret = 0; | |
242 while (n > 0) { | |
243 ret += (n % 10); | |
244 n /= 10; | |
245 } | |
246 return ret; | |
247 } | |
248 | |
249 unsigned long | |
250 cddb_discid(int tot_trks) { | |
251 unsigned int i, t = 0, n = 0; | |
252 | |
253 i = 0; | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
254 while (i < (unsigned int)tot_trks) { |
6474 | 255 n = n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec); |
256 i++; | |
257 } | |
258 t = ((cdtoc[tot_trks].min * 60) + cdtoc[tot_trks].sec) - | |
259 ((cdtoc[0].min * 60) + cdtoc[0].sec); | |
260 return ((n % 0xff) << 24 | t << 8 | tot_trks); | |
261 } | |
262 | |
263 | |
264 | |
265 int | |
266 cddb_http_request(char *command, int (*reply_parser)(HTTP_header_t*,cddb_data_t*), cddb_data_t *cddb_data) { | |
267 char request[4096]; | |
268 int fd, ret = 0; | |
269 URL_t *url; | |
270 HTTP_header_t *http_hdr; | |
271 | |
272 if( reply_parser==NULL || command==NULL || cddb_data==NULL ) return -1; | |
273 | |
274 sprintf( request, "http://%s/~cddb/cddb.cgi?cmd=%s%s&proto=%d", cddb_data->freedb_server, command, cddb_data->cddb_hello, cddb_data->freedb_proto_level ); | |
18176
f72bc5754209
Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents:
17446
diff
changeset
|
275 mp_msg(MSGT_OPEN, MSGL_INFO,"Request[%s]\n", request ); |
6474 | 276 |
277 url = url_new(request); | |
278 if( url==NULL ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
279 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NotAValidURL); |
6474 | 280 return -1; |
281 } | |
282 | |
11965 | 283 fd = http_send_request(url,0); |
6474 | 284 if( fd<0 ) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
285 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToSendHTTPRequest); |
6474 | 286 return -1; |
287 } | |
288 | |
289 http_hdr = http_read_response( fd ); | |
290 if( http_hdr==NULL ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
291 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToReadHTTPResponse); |
6474 | 292 return -1; |
293 } | |
294 | |
295 http_debug_hdr(http_hdr); | |
18176
f72bc5754209
Part3 of Otvos Attila's oattila AT chello-hu mp_msg changes, with lots of modifications as usual
reynaldo
parents:
17446
diff
changeset
|
296 mp_msg(MSGT_OPEN, MSGL_INFO,"body=[%s]\n", http_hdr->body ); |
6474 | 297 |
298 switch(http_hdr->status_code) { | |
299 case 200: | |
300 ret = reply_parser(http_hdr, cddb_data); | |
301 break; | |
302 case 400: | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
303 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_HTTPErrorNOTFOUND); |
6474 | 304 break; |
305 default: | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
306 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_HTTPErrorUnknown); |
6474 | 307 } |
308 | |
309 http_free( http_hdr ); | |
310 url_free( url ); | |
311 | |
312 return ret; | |
313 } | |
314 | |
315 int | |
316 cddb_read_cache(cddb_data_t *cddb_data) { | |
317 char file_name[100]; | |
318 struct stat stats; | |
319 int file_fd, ret; | |
320 size_t file_size; | |
321 | |
322 if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1; | |
323 | |
324 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id); | |
325 | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
326 file_fd = open(file_name, O_RDONLY |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
327 #ifdef WIN32 |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
328 | O_BINARY |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
329 #endif |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
330 ); |
6474 | 331 if( file_fd<0 ) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
332 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NoCacheFound); |
6474 | 333 return -1; |
334 } | |
335 | |
336 ret = fstat( file_fd, &stats ); | |
337 if( ret<0 ) { | |
338 perror("fstat"); | |
339 file_size = 4096; | |
340 } else { | |
341 file_size = stats.st_size; | |
342 } | |
343 | |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18922
diff
changeset
|
344 cddb_data->xmcd_file = malloc(file_size); |
6474 | 345 if( cddb_data->xmcd_file==NULL ) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
346 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed); |
6474 | 347 close(file_fd); |
348 return -1; | |
349 } | |
350 cddb_data->xmcd_file_size = read(file_fd, cddb_data->xmcd_file, file_size); | |
351 if( cddb_data->xmcd_file_size!=file_size ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
352 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenRead); |
6474 | 353 close(file_fd); |
354 return -1; | |
355 } | |
356 | |
357 close(file_fd); | |
358 | |
359 return 0; | |
360 } | |
361 | |
362 int | |
363 cddb_write_cache(cddb_data_t *cddb_data) { | |
364 // We have the file, save it for cache. | |
7721 | 365 struct stat file_stat; |
6474 | 366 char file_name[100]; |
7721 | 367 int file_fd, ret; |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
368 int wrote=0; |
6474 | 369 |
370 if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1; | |
371 | |
7721 | 372 // Check if the CDDB cache dir exist |
373 ret = stat( cddb_data->cache_dir, &file_stat ); | |
374 if( ret<0 ) { | |
375 // Directory not present, create it. | |
376 ret = mkdir( cddb_data->cache_dir, 0755 ); | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
377 #ifdef __MINGW32__ |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
378 if( ret<0 && errno != EEXIST ) { |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
379 #else |
7721 | 380 if( ret<0 ) { |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
381 #endif |
7721 | 382 perror("mkdir"); |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
383 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToCreateDirectory, cddb_data->cache_dir); |
7721 | 384 return -1; |
385 } | |
386 } | |
387 | |
388 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id ); | |
6474 | 389 |
390 file_fd = creat(file_name, S_IREAD|S_IWRITE); | |
391 if( file_fd<0 ) { | |
7721 | 392 perror("create"); |
6474 | 393 return -1; |
394 } | |
395 | |
396 wrote = write(file_fd, cddb_data->xmcd_file, cddb_data->xmcd_file_size); | |
397 if( wrote<0 ) { | |
398 perror("write"); | |
399 close(file_fd); | |
400 return -1; | |
401 } | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
402 if( (unsigned int)wrote!=cddb_data->xmcd_file_size ) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
403 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenWritten); |
6474 | 404 close(file_fd); |
405 return -1; | |
406 } | |
407 | |
408 close(file_fd); | |
409 | |
410 return 0; | |
411 } | |
412 | |
413 int | |
414 cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { | |
415 unsigned long disc_id; | |
416 char category[100]; | |
417 char *ptr=NULL, *ptr2=NULL; | |
418 int ret, status; | |
419 | |
420 if( http_hdr==NULL || cddb_data==NULL ) return -1; | |
421 | |
422 ret = sscanf( http_hdr->body, "%d ", &status); | |
423 if( ret!=1 ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
424 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
6474 | 425 return -1; |
426 } | |
427 | |
428 switch(status) { | |
429 case 210: | |
23452
3e676c9e1e35
Avoiding sscanf in cddb support reading more data with %s than buffer size
reimar
parents:
23269
diff
changeset
|
430 ret = sscanf( http_hdr->body, "%d %99s %08lx", &status, category, &disc_id); |
6474 | 431 if( ret!=3 ) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
432 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
6474 | 433 return -1; |
434 } | |
435 // Check if it's a xmcd database file | |
436 ptr = strstr(http_hdr->body, "# xmcd"); | |
437 if( ptr==NULL ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
438 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_InvalidXMCDDatabaseReturned); |
6474 | 439 return -1; |
440 } | |
441 // Ok found the beginning of the file | |
442 // look for the end | |
443 ptr2 = strstr(ptr, "\r\n.\r\n"); | |
444 if( ptr2==NULL ) { | |
445 ptr2 = strstr(ptr, "\n.\n"); | |
446 if( ptr2==NULL ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
447 mp_msg(MSGT_DEMUX, MSGL_FIXME, "Unable to find '.'\n"); |
8557 | 448 ptr2=ptr+strlen(ptr); //return -1; |
6474 | 449 } |
450 } | |
451 // Ok found the end | |
452 // do a sanity check | |
7953 | 453 if( http_hdr->body_size<(unsigned int)(ptr2-ptr) ) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
454 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_UnexpectedFIXME); |
6474 | 455 return -1; |
456 } | |
457 cddb_data->xmcd_file = ptr; | |
458 cddb_data->xmcd_file_size = ptr2-ptr+2; | |
459 cddb_data->xmcd_file[cddb_data->xmcd_file_size] = '\0'; | |
460 // Avoid the http_free function to free the xmcd file...save a mempcy... | |
461 http_hdr->body = NULL; | |
462 http_hdr->body_size = 0; | |
463 return cddb_write_cache(cddb_data); | |
464 default: | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
465 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode); |
6474 | 466 } |
467 return 0; | |
468 } | |
469 | |
470 int | |
471 cddb_request_titles(cddb_data_t *cddb_data) { | |
472 char command[1024]; | |
473 sprintf( command, "cddb+read+%s+%08lx", cddb_data->category, cddb_data->disc_id); | |
474 return cddb_http_request(command, cddb_read_parse, cddb_data); | |
475 } | |
476 | |
477 int | |
8746 | 478 cddb_parse_matches_list(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { |
479 char album_title[100]; | |
480 char *ptr = NULL; | |
481 int ret; | |
482 | |
483 ptr = strstr(http_hdr->body, "\n"); | |
484 if( ptr==NULL ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
485 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_UnableToFindEOL); |
8746 | 486 return -1; |
487 } | |
488 ptr++; | |
489 // We have a list of exact/inexact matches, so which one do we use? | |
490 // So let's take the first one. | |
23452
3e676c9e1e35
Avoiding sscanf in cddb support reading more data with %s than buffer size
reimar
parents:
23269
diff
changeset
|
491 ret = sscanf(ptr, "%99s %08lx %99s", cddb_data->category, &(cddb_data->disc_id), album_title); |
8746 | 492 if( ret!=3 ) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
493 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
8746 | 494 return -1; |
495 } | |
496 ptr = strstr(http_hdr->body, album_title); | |
497 if( ptr!=NULL ) { | |
498 char *ptr2; | |
499 int len; | |
500 ptr2 = strstr(ptr, "\n"); | |
501 if( ptr2==NULL ) { | |
502 len = (http_hdr->body_size)-(ptr-(http_hdr->body)); | |
503 } else { | |
504 len = ptr2-ptr+1; | |
505 } | |
506 strncpy(album_title, ptr, len); | |
507 album_title[len-2]='\0'; | |
508 } | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
509 mp_msg(MSGT_DEMUX, MSGL_STATUS, MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle, album_title); |
8746 | 510 return 0; |
511 } | |
512 | |
513 int | |
6474 | 514 cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { |
515 char album_title[100]; | |
516 char *ptr = NULL; | |
517 int ret, status; | |
518 | |
519 ret = sscanf( http_hdr->body, "%d ", &status); | |
520 if( ret!=1 ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
521 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
6474 | 522 return -1; |
523 } | |
524 | |
525 switch(status) { | |
526 case 200: | |
527 // Found exact match | |
23452
3e676c9e1e35
Avoiding sscanf in cddb support reading more data with %s than buffer size
reimar
parents:
23269
diff
changeset
|
528 ret = sscanf(http_hdr->body, "%d %99s %08lx %99s", &status, cddb_data->category, &(cddb_data->disc_id), album_title); |
6474 | 529 if( ret!=4 ) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
530 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
6474 | 531 return -1; |
532 } | |
533 ptr = strstr(http_hdr->body, album_title); | |
534 if( ptr!=NULL ) { | |
535 char *ptr2; | |
536 int len; | |
537 ptr2 = strstr(ptr, "\n"); | |
538 if( ptr2==NULL ) { | |
539 len = (http_hdr->body_size)-(ptr-(http_hdr->body)); | |
540 } else { | |
541 len = ptr2-ptr+1; | |
542 } | |
543 strncpy(album_title, ptr, len); | |
544 album_title[len-2]='\0'; | |
545 } | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
546 mp_msg(MSGT_DEMUX, MSGL_STATUS, MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle, album_title); |
6474 | 547 return cddb_request_titles(cddb_data); |
548 case 202: | |
549 // No match found | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
550 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_AlbumNotFound); |
6474 | 551 break; |
552 case 210: | |
553 // Found exact matches, list follows | |
8746 | 554 cddb_parse_matches_list(http_hdr, cddb_data); |
6474 | 555 return cddb_request_titles(cddb_data); |
556 /* | |
557 body=[210 Found exact matches, list follows (until terminating `.') | |
558 misc c711930d Santana / Supernatural | |
559 rock c711930d Santana / Supernatural | |
560 blues c711930d Santana / Supernatural | |
561 .] | |
562 */ | |
563 case 211: | |
564 // Found inexact matches, list follows | |
8746 | 565 cddb_parse_matches_list(http_hdr, cddb_data); |
566 return cddb_request_titles(cddb_data); | |
8962 | 567 case 500: |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
568 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_ServerReturnsCommandSyntaxErr); |
8962 | 569 break; |
6474 | 570 default: |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
571 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode); |
6474 | 572 } |
573 return -1; | |
574 } | |
575 | |
576 int | |
577 cddb_proto_level_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { | |
578 int max; | |
579 int ret, status; | |
580 char *ptr; | |
581 | |
582 ret = sscanf( http_hdr->body, "%d ", &status); | |
583 if( ret!=1 ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
584 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
6474 | 585 return -1; |
586 } | |
587 | |
588 switch(status) { | |
589 case 210: | |
590 ptr = strstr(http_hdr->body, "max proto:"); | |
591 if( ptr==NULL ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
592 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
6474 | 593 return -1; |
594 } | |
595 ret = sscanf(ptr, "max proto: %d", &max); | |
596 if( ret!=1 ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
597 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
6474 | 598 return -1; |
599 } | |
600 cddb_data->freedb_proto_level = max; | |
601 return 0; | |
602 default: | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
603 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode); |
6474 | 604 } |
605 return -1; | |
606 } | |
607 | |
608 int | |
609 cddb_get_proto_level(cddb_data_t *cddb_data) { | |
610 return cddb_http_request("stat", cddb_proto_level_parse, cddb_data); | |
611 } | |
612 | |
613 int | |
614 cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { | |
615 int ret, status; | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
616 |
6474 | 617 ret = sscanf( http_hdr->body, "%d ", &status); |
618 if( ret!=1 ) { | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
619 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
6474 | 620 return -1; |
621 } | |
622 | |
623 switch(status) { | |
624 case 210: | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
625 // TODO: Parse the sites |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
626 ret = cddb_data->anonymous; // For gcc complaining about unused parameter. |
6474 | 627 return 0; |
628 case 401: | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
629 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_NoSitesInfoAvailable); |
6474 | 630 break; |
631 default: | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
632 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode); |
6474 | 633 } |
634 return -1; | |
635 } | |
636 | |
637 int | |
638 cddb_get_freedb_sites(cddb_data_t *cddb_data) { | |
639 return cddb_http_request("sites", cddb_freedb_sites_parse, cddb_data); | |
640 } | |
641 | |
642 void | |
643 cddb_create_hello(cddb_data_t *cddb_data) { | |
644 char host_name[51]; | |
645 char *user_name; | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
646 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
647 if( cddb_data->anonymous ) { // Default is anonymous |
23734 | 648 /* Note from Eduardo Pérez Ureta <eperez@it.uc3m.es> : |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
649 * We don't send current user/host name in hello to prevent spam. |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
650 * Software that sends this is considered spyware |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
651 * that most people don't like. |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
652 */ |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
653 user_name = "anonymous"; |
6474 | 654 strcpy(host_name, "localhost"); |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
655 } else { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
656 if( gethostname(host_name, 50)<0 ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
657 strcpy(host_name, "localhost"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
658 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
659 user_name = getenv("LOGNAME"); |
6474 | 660 } |
661 sprintf( cddb_data->cddb_hello, "&hello=%s+%s+%s+%s", user_name, host_name, "MPlayer", VERSION ); | |
662 } | |
663 | |
664 int | |
665 cddb_retrieve(cddb_data_t *cddb_data) { | |
666 char offsets[1024], command[1024]; | |
667 char *ptr; | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
668 unsigned int i, time_len; |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
669 int ret; |
6474 | 670 |
671 ptr = offsets; | |
672 for( i=0; i<cddb_data->tracks ; i++ ) { | |
673 ptr += sprintf(ptr, "%d+", cdtoc[i].frame ); | |
12289
e197979a0883
potentially exploitable buffer overflow with maliciously crafted cd toc
rfelker
parents:
11965
diff
changeset
|
674 if (ptr-offsets > sizeof offsets - 40) break; |
6474 | 675 } |
8557 | 676 ptr[0]=0; |
6474 | 677 time_len = (cdtoc[cddb_data->tracks].frame)/75; |
8557 | 678 |
6474 | 679 cddb_data->freedb_server = DEFAULT_FREEDB_SERVER; |
680 cddb_data->freedb_proto_level = 1; | |
681 cddb_data->xmcd_file = NULL; | |
682 | |
683 cddb_create_hello(cddb_data); | |
6475
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
684 if( cddb_get_proto_level(cddb_data)<0 ) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
685 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToGetProtocolLevel); |
6475
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
686 return -1; |
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
687 } |
6474 | 688 |
689 //cddb_get_freedb_sites(&cddb_data); | |
690 | |
691 sprintf(command, "cddb+query+%08lx+%d+%s%d", cddb_data->disc_id, cddb_data->tracks, offsets, time_len ); | |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
692 ret = cddb_http_request(command, cddb_query_parse, cddb_data); |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
693 if( ret<0 ) return -1; |
6474 | 694 |
695 if( cddb_data->cache_dir!=NULL ) { | |
696 free(cddb_data->cache_dir); | |
697 } | |
698 return 0; | |
699 } | |
700 | |
701 int | |
8962 | 702 cddb_resolve(const char *dev, char **xmcd_file) { |
6474 | 703 char cddb_cache_dir[] = DEFAULT_CACHE_DIR; |
704 char *home_dir = NULL; | |
705 cddb_data_t cddb_data; | |
706 | |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
707 if (cdtoc_last_track <= 0) |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
708 { |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
709 cdtoc_last_track = read_toc(dev); |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
710 if (cdtoc_last_track < 0) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
711 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice, dev); |
8962 | 712 return -1; |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
713 } |
8962 | 714 } |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
715 cddb_data.tracks = cdtoc_last_track; |
6474 | 716 cddb_data.disc_id = cddb_discid(cddb_data.tracks); |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
717 cddb_data.anonymous = 1; // Don't send user info by default |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
718 |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
719 // Check if there is a CD in the drive |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
720 // FIXME: That's not really a good way to check |
8962 | 721 if( cddb_data.disc_id==0 ) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
722 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NoCDInDrive); |
7746
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
723 return -1; |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
724 } |
6474 | 725 |
726 home_dir = getenv("HOME"); | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
727 #ifdef __MINGW32__ |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
728 if( home_dir==NULL ) home_dir = getenv("USERPROFILE"); |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
729 if( home_dir==NULL ) home_dir = getenv("HOMEPATH"); |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
730 // Last resort, store the cddb cache in the mplayer directory |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
731 if( home_dir==NULL ) home_dir = (char *)get_path(""); |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
732 #endif |
6474 | 733 if( home_dir==NULL ) { |
734 cddb_data.cache_dir = NULL; | |
735 } else { | |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18922
diff
changeset
|
736 cddb_data.cache_dir = malloc(strlen(home_dir)+strlen(cddb_cache_dir)+1); |
6474 | 737 if( cddb_data.cache_dir==NULL ) { |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
738 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed); |
6474 | 739 return -1; |
740 } | |
741 sprintf(cddb_data.cache_dir, "%s%s", home_dir, cddb_cache_dir ); | |
742 } | |
743 | |
744 // Check for a cached file | |
745 if( cddb_read_cache(&cddb_data)<0 ) { | |
746 // No Cache found | |
747 if( cddb_retrieve(&cddb_data)<0 ) { | |
748 return -1; | |
749 } | |
750 } | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
751 |
6474 | 752 if( cddb_data.xmcd_file!=NULL ) { |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
753 // printf("%s\n", cddb_data.xmcd_file ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
754 *xmcd_file = cddb_data.xmcd_file; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
755 return 0; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
756 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
757 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
758 return -1; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
759 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
760 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
761 /******************************************************************************************************************* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
762 * |
7431
e46eeafcd4df
Moved all the cdinfo specific from cddb to a standalone file(cdinfo.c), so
bertrand
parents:
7269
diff
changeset
|
763 * xmcd parser |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
764 * |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
765 *******************************************************************************************************************/ |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
766 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
767 xmcd_parse_dtitle(cd_info_t *cd_info, char *line) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
768 char *ptr, *album; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
769 ptr = strstr(line, "DTITLE="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
770 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
771 ptr += 7; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
772 album = strstr(ptr, "/"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
773 if( album==NULL ) return NULL; |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18922
diff
changeset
|
774 cd_info->album = malloc(strlen(album+2)+1); |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
775 if( cd_info->album==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
776 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
777 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
778 strcpy( cd_info->album, album+2 ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
779 album--; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
780 album[0] = '\0'; |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18922
diff
changeset
|
781 cd_info->artist = malloc(strlen(ptr)+1); |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
782 if( cd_info->artist==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
783 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
784 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
785 strcpy( cd_info->artist, ptr ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
786 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
787 return ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
788 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
789 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
790 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
791 xmcd_parse_dgenre(cd_info_t *cd_info, char *line) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
792 char *ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
793 ptr = strstr(line, "DGENRE="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
794 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
795 ptr += 7; |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18922
diff
changeset
|
796 cd_info->genre = malloc(strlen(ptr)+1); |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
797 if( cd_info->genre==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
798 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
799 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
800 strcpy( cd_info->genre, ptr ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
801 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
802 return ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
803 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
804 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
805 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
806 xmcd_parse_ttitle(cd_info_t *cd_info, char *line) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
807 unsigned int track_nb; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
808 unsigned long sec, off; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
809 char *ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
810 ptr = strstr(line, "TTITLE"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
811 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
812 ptr += 6; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
813 // Here we point to the track number |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
814 track_nb = atoi(ptr); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
815 ptr = strstr(ptr, "="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
816 if( ptr==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
817 ptr++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
818 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
819 sec = cdtoc[track_nb].frame; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
820 off = cdtoc[track_nb+1].frame-sec+1; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
821 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
822 cd_info_add_track( cd_info, ptr, track_nb+1, (unsigned int)(off/(60*75)), (unsigned int)((off/75)%60), (unsigned int)(off%75), sec, off ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
823 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
824 return ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
825 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
826 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
827 cd_info_t* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
828 cddb_parse_xmcd(char *xmcd_file) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
829 cd_info_t *cd_info = NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
830 int length, pos = 0; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
831 char *ptr, *ptr2; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
832 unsigned int audiolen; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
833 if( xmcd_file==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
834 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
835 cd_info = cd_info_new(); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
836 if( cd_info==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
837 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
838 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
839 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
840 length = strlen(xmcd_file); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
841 ptr = xmcd_file; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
842 while( ptr!=NULL && pos<length ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
843 // Read a line |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
844 ptr2 = ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
845 while( ptr2[0]!='\0' && ptr2[0]!='\r' && ptr2[0]!='\n' ) ptr2++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
846 if( ptr2[0]=='\0' ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
847 break; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
848 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
849 ptr2[0] = '\0'; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
850 // Ignore comments |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
851 if( ptr[0]!='#' ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
852 // Search for the album title |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
853 if( xmcd_parse_dtitle(cd_info, ptr) ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
854 // Search for the genre |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
855 else if( xmcd_parse_dgenre(cd_info, ptr) ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
856 // Search for a track title |
7953 | 857 else if( xmcd_parse_ttitle(cd_info, ptr) ) audiolen++; // <-- audiolen++ to shut up gcc warning |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
858 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
859 if( ptr2[1]=='\n' ) ptr2++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
860 pos = (ptr2+1)-ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
861 ptr = ptr2+1; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
862 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
863 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
864 audiolen = cdtoc[cd_info->nb_tracks].frame-cdtoc[0].frame; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
865 cd_info->min = (unsigned int)(audiolen/(60*75)); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
866 cd_info->sec = (unsigned int)((audiolen/75)%60); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
867 cd_info->msec = (unsigned int)(audiolen%75); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
868 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
869 return cd_info; |
6474 | 870 } |