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