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