Mercurial > mplayer.hg
annotate libmpdemux/cddb.c @ 16935:60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
patch by Erik Lunchpail <erik_27can at yahoo.com>
base on patch by Rocky Bernstein <rocky at panix.com>
minor modification by myself
author | faust3 |
---|---|
date | Sun, 06 Nov 2005 17:42:20 +0000 |
parents | 83d101e1bedb |
children | 32e2c59c8e86 |
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 | |
10121
d42177a0da2a
Changed the STREAMING defines to MPLAYER_NETWORK to avoid name definition clash.
bertrand
parents:
9801
diff
changeset
|
17 #if defined(HAVE_CDDA) && defined(MPLAYER_NETWORK) |
6474 | 18 |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <fcntl.h> | |
22 #include <stdarg.h> | |
23 #include <errno.h> | |
24 #include <unistd.h> | |
25 #include <string.h> | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
26 #ifdef WIN32 |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
27 #ifdef __MINGW32__ |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
28 #define mkdir(a,b) mkdir(a) |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
29 #endif |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
30 #include <windows.h> |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
31 #include <winsock2.h> |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
32 #else |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
33 #include <netdb.h> |
6474 | 34 #include <sys/ioctl.h> |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
35 #endif |
6474 | 36 #include <sys/types.h> |
37 #include <sys/stat.h> | |
38 | |
39 #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
|
40 #include <linux/cdrom.h> |
15566 | 41 #elif defined(__FreeBSD__) || defined(__bsdi__) || 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
|
42 #include <sys/cdio.h> |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
43 #elif defined(WIN32) |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
44 #include <ddk/ntddcdrm.h> |
6474 | 45 #endif |
46 | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
47 #include "cdd.h" |
6474 | 48 #include "../version.h" |
49 #include "stream.h" | |
50 #include "network.h" | |
51 | |
52 #define DEFAULT_FREEDB_SERVER "freedb.freedb.org" | |
53 #define DEFAULT_CACHE_DIR "/.cddb/" | |
54 | |
55 stream_t* open_cdda(char *dev, char *track); | |
56 | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
57 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
|
58 static int cdtoc_last_track; |
6474 | 59 |
60 #if defined(__linux__) | |
61 int | |
8962 | 62 read_toc(const char *dev) { |
63 int drive; | |
6474 | 64 struct cdrom_tochdr tochdr; |
65 struct cdrom_tocentry tocentry; | |
66 int i; | |
67 | |
8962 | 68 drive = open(dev, O_RDONLY | O_NONBLOCK); |
69 if( drive<0 ) { | |
70 return drive; | |
71 } | |
72 | |
6474 | 73 ioctl(drive, CDROMREADTOCHDR, &tochdr); |
74 for (i = tochdr.cdth_trk0; i <= tochdr.cdth_trk1; i++) { | |
75 tocentry.cdte_track = i; | |
76 tocentry.cdte_format = CDROM_MSF; | |
77 ioctl(drive, CDROMREADTOCENTRY, &tocentry); | |
78 cdtoc[i-1].min = tocentry.cdte_addr.msf.minute; | |
79 cdtoc[i-1].sec = tocentry.cdte_addr.msf.second; | |
80 cdtoc[i-1].frame = tocentry.cdte_addr.msf.frame; | |
81 cdtoc[i-1].frame += cdtoc[i-1].min*60*75; | |
82 cdtoc[i-1].frame += cdtoc[i-1].sec*75; | |
83 } | |
84 tocentry.cdte_track = 0xAA; | |
85 tocentry.cdte_format = CDROM_MSF; | |
86 ioctl(drive, CDROMREADTOCENTRY, &tocentry); | |
87 cdtoc[tochdr.cdth_trk1].min = tocentry.cdte_addr.msf.minute; | |
88 cdtoc[tochdr.cdth_trk1].sec = tocentry.cdte_addr.msf.second; | |
89 cdtoc[tochdr.cdth_trk1].frame = tocentry.cdte_addr.msf.frame; | |
90 cdtoc[tochdr.cdth_trk1].frame += cdtoc[tochdr.cdth_trk1].min*60*75; | |
91 cdtoc[tochdr.cdth_trk1].frame += cdtoc[tochdr.cdth_trk1].sec*75; | |
92 close(drive); | |
93 return tochdr.cdth_trk1; | |
94 } | |
95 | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
96 #elif defined(WIN32) |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
97 int |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
98 read_toc(const char *dev) { |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
99 HANDLE drive; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
100 DWORD r; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
101 CDROM_TOC toc; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
102 char device[10]; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
103 int i; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
104 |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
105 sprintf(device, "\\\\.\\%s", dev); |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
106 drive = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
107 |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
108 if(!DeviceIoControl(drive, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(CDROM_TOC), &r, 0)) { |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
109 mp_msg(MSGT_OPEN, MSGL_ERR, "Failed to read TOC.\n"); |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
110 return 0; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
111 } |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
112 |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
113 for (i = toc.FirstTrack; i <= toc.LastTrack; i++) { |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
114 toc.FirstTrack = i; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
115 cdtoc[i-1].min = toc.TrackData[i - 1].Address[1]; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
116 cdtoc[i-1].sec = toc.TrackData[i - 1].Address[2]; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
117 cdtoc[i-1].frame = toc.TrackData[i - 1].Address[3]; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
118 cdtoc[i-1].frame += cdtoc[i-1].min*60*75; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
119 cdtoc[i-1].frame += cdtoc[i-1].sec*75; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
120 } |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
121 toc.FirstTrack = 0xAA; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
122 cdtoc[toc.LastTrack].min = toc.TrackData[toc.LastTrack].Address[1]; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
123 cdtoc[toc.LastTrack].sec = toc.TrackData[toc.LastTrack].Address[2]; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
124 cdtoc[toc.LastTrack].frame = toc.TrackData[toc.LastTrack].Address[3]; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
125 cdtoc[toc.LastTrack].frame += cdtoc[toc.LastTrack].min*60*75; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
126 cdtoc[toc.LastTrack].frame += cdtoc[toc.LastTrack].sec*75; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
127 CloseHandle(drive); |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
128 return toc.LastTrack; |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
129 } |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
130 |
15566 | 131 #elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__DragonFly__) |
6474 | 132 int |
8962 | 133 read_toc(const char *dev) { |
134 int drive; | |
6474 | 135 struct ioc_toc_header tochdr; |
136 struct ioc_read_toc_single_entry tocentry; | |
137 int i; | |
138 | |
8962 | 139 drive = open(dev, O_RDONLY | O_NONBLOCK); |
140 if( drive<0 ) { | |
141 return drive; | |
142 } | |
143 | |
6474 | 144 ioctl(drive, CDIOREADTOCHEADER, &tochdr); |
145 for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) { | |
146 tocentry.track = i; | |
147 tocentry.address_format = CD_MSF_FORMAT; | |
148 ioctl(drive, CDIOREADTOCENTRY, &tocentry); | |
149 cdtoc[i-1].min = tocentry.entry.addr.msf.minute; | |
150 cdtoc[i-1].sec = tocentry.entry.addr.msf.second; | |
151 cdtoc[i-1].frame = tocentry.entry.addr.msf.frame; | |
152 cdtoc[i-1].frame += cdtoc[i-1].min*60*75; | |
153 cdtoc[i-1].frame += cdtoc[i-1].sec*75; | |
154 } | |
155 tocentry.track = 0xAA; | |
156 tocentry.address_format = CD_MSF_FORMAT; | |
157 ioctl(drive, CDIOREADTOCENTRY, &tocentry); | |
158 cdtoc[tochdr.ending_track].min = tocentry.entry.addr.msf.minute; | |
159 cdtoc[tochdr.ending_track].sec = tocentry.entry.addr.msf.second; | |
160 cdtoc[tochdr.ending_track].frame = tocentry.entry.addr.msf.frame; | |
161 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].min*60*75; | |
162 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].sec*75; | |
163 close(drive); | |
164 return tochdr.ending_track; | |
165 } | |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
166 |
8962 | 167 #elif defined(__NetBSD__) || defined(__OpenBSD__) |
8609
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
168 int |
8962 | 169 read_toc(const char *dev) { |
8609
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
170 int drive; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
171 struct ioc_toc_header tochdr; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
172 struct ioc_read_toc_entry tocentry; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
173 int i; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
174 struct cd_toc_entry toc_buffer; |
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
175 |
8962 | 176 drive = open(dev, O_RDONLY | O_NONBLOCK); |
177 if( drive<0 ) { | |
178 return drive; | |
8609
1d98280b9ad1
The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents:
8557
diff
changeset
|
179 } |
7269
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
180 |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
181 ioctl(drive, CDIOREADTOCHEADER, &tochdr); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
182 for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) { |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
183 tocentry.starting_track = i; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 ioctl(drive, CDIOREADTOCENTRYS, &tocentry); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
188 cdtoc[i-1].min = toc_buffer.addr.msf.minute; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
189 cdtoc[i-1].sec = toc_buffer.addr.msf.second; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
190 cdtoc[i-1].frame = toc_buffer.addr.msf.frame; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
191 cdtoc[i-1].frame += cdtoc[i-1].min*60*75; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
192 cdtoc[i-1].frame += cdtoc[i-1].sec*75; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
193 } |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
194 tocentry.starting_track = 0xAA; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
195 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
|
196 ioctl(drive, CDIOREADTOCENTRYS, &tocentry); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
197 cdtoc[tochdr.ending_track].min = toc_buffer.addr.msf.minute; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
198 cdtoc[tochdr.ending_track].sec = toc_buffer.addr.msf.second; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
199 cdtoc[tochdr.ending_track].frame = toc_buffer.addr.msf.frame; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
200 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].min*60*75; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
201 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].sec*75; |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
202 close(drive); |
a5f1baaf7714
Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents:
6697
diff
changeset
|
203 return tochdr.ending_track; |
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 #endif |
206 | |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
207 /** |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
208 \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
|
209 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
|
210 \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
|
211 \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
|
212 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
|
213 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
|
214 */ |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
215 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
|
216 { |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
217 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
|
218 if (identify) |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
219 { |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
220 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
|
221 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
|
222 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
|
223 mp_msg(MSGT_OPEN, MSGL_ERR, "Failed to open %s device.\n", dev); |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
224 return -1; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
225 } |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
226 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
|
227 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
|
228 { |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
229 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
|
230 sec = frame / 75; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
231 frame -= sec * 75; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
232 min = sec / 60; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
233 sec -= min * 60; |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
234 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_CDDA_TRACK_%d_MSF=%02d:%02d:%02d\n", 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
|
235 } |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
236 } |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
237 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
|
238 } |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
239 |
6474 | 240 unsigned int |
241 cddb_sum(int n) { | |
242 unsigned int ret; | |
243 | |
244 ret = 0; | |
245 while (n > 0) { | |
246 ret += (n % 10); | |
247 n /= 10; | |
248 } | |
249 return ret; | |
250 } | |
251 | |
252 unsigned long | |
253 cddb_discid(int tot_trks) { | |
254 unsigned int i, t = 0, n = 0; | |
255 | |
256 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
|
257 while (i < (unsigned int)tot_trks) { |
6474 | 258 n = n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec); |
259 i++; | |
260 } | |
261 t = ((cdtoc[tot_trks].min * 60) + cdtoc[tot_trks].sec) - | |
262 ((cdtoc[0].min * 60) + cdtoc[0].sec); | |
263 return ((n % 0xff) << 24 | t << 8 | tot_trks); | |
264 } | |
265 | |
266 | |
267 | |
268 int | |
269 cddb_http_request(char *command, int (*reply_parser)(HTTP_header_t*,cddb_data_t*), cddb_data_t *cddb_data) { | |
270 char request[4096]; | |
271 int fd, ret = 0; | |
272 URL_t *url; | |
273 HTTP_header_t *http_hdr; | |
274 | |
275 if( reply_parser==NULL || command==NULL || cddb_data==NULL ) return -1; | |
276 | |
277 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 ); | |
278 printf("Request[%s]\n", request ); | |
279 | |
280 url = url_new(request); | |
281 if( url==NULL ) { | |
282 printf("Not a valid URL\n"); | |
283 return -1; | |
284 } | |
285 | |
11965 | 286 fd = http_send_request(url,0); |
6474 | 287 if( fd<0 ) { |
288 printf("failed to send the http request\n"); | |
289 return -1; | |
290 } | |
291 | |
292 http_hdr = http_read_response( fd ); | |
293 if( http_hdr==NULL ) { | |
294 printf("Failed to read the http response\n"); | |
295 return -1; | |
296 } | |
297 | |
298 http_debug_hdr(http_hdr); | |
299 printf("body=[%s]\n", http_hdr->body ); | |
300 | |
301 switch(http_hdr->status_code) { | |
302 case 200: | |
303 ret = reply_parser(http_hdr, cddb_data); | |
304 break; | |
305 case 400: | |
306 printf("Not Found\n"); | |
307 break; | |
308 default: | |
309 printf("Unknown Error code\n"); | |
310 } | |
311 | |
312 http_free( http_hdr ); | |
313 url_free( url ); | |
314 | |
315 return ret; | |
316 } | |
317 | |
318 int | |
319 cddb_read_cache(cddb_data_t *cddb_data) { | |
320 char file_name[100]; | |
321 struct stat stats; | |
322 int file_fd, ret; | |
323 size_t file_size; | |
324 | |
325 if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1; | |
326 | |
327 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id); | |
328 | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
329 file_fd = open(file_name, O_RDONLY |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
330 #ifdef WIN32 |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
331 | O_BINARY |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
332 #endif |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
333 ); |
6474 | 334 if( file_fd<0 ) { |
335 printf("No cache found\n"); | |
336 return -1; | |
337 } | |
338 | |
339 ret = fstat( file_fd, &stats ); | |
340 if( ret<0 ) { | |
341 perror("fstat"); | |
342 file_size = 4096; | |
343 } else { | |
344 file_size = stats.st_size; | |
345 } | |
346 | |
347 cddb_data->xmcd_file = (char*)malloc(file_size); | |
348 if( cddb_data->xmcd_file==NULL ) { | |
349 printf("Memory allocation failed\n"); | |
350 close(file_fd); | |
351 return -1; | |
352 } | |
353 cddb_data->xmcd_file_size = read(file_fd, cddb_data->xmcd_file, file_size); | |
354 if( cddb_data->xmcd_file_size!=file_size ) { | |
355 printf("Not all the xmcd file has been read\n"); | |
356 close(file_fd); | |
357 return -1; | |
358 } | |
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"); |
386 printf("Failed to create directory %s\n", cddb_data->cache_dir ); | |
387 return -1; | |
388 } | |
389 } | |
390 | |
391 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id ); | |
6474 | 392 |
393 file_fd = creat(file_name, S_IREAD|S_IWRITE); | |
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 ) { |
6474 | 406 printf("Not all the xmcd file has been written\n"); |
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 ) { | |
427 printf("Parse error\n"); | |
428 return -1; | |
429 } | |
430 | |
431 switch(status) { | |
432 case 210: | |
433 ret = sscanf( http_hdr->body, "%d %s %08lx", &status, category, &disc_id); | |
434 if( ret!=3 ) { | |
435 printf("Parse error\n"); | |
436 return -1; | |
437 } | |
438 // Check if it's a xmcd database file | |
439 ptr = strstr(http_hdr->body, "# xmcd"); | |
440 if( ptr==NULL ) { | |
441 printf("Invalid xmcd database file returned\n"); | |
442 return -1; | |
443 } | |
444 // Ok found the beginning of the file | |
445 // look for the end | |
446 ptr2 = strstr(ptr, "\r\n.\r\n"); | |
447 if( ptr2==NULL ) { | |
448 ptr2 = strstr(ptr, "\n.\n"); | |
449 if( ptr2==NULL ) { | |
450 printf("Unable to find '.'\n"); | |
8557 | 451 ptr2=ptr+strlen(ptr); //return -1; |
6474 | 452 } |
453 } | |
454 // Ok found the end | |
455 // do a sanity check | |
7953 | 456 if( http_hdr->body_size<(unsigned int)(ptr2-ptr) ) { |
6474 | 457 printf("Unexpected fix me\n"); |
458 return -1; | |
459 } | |
460 cddb_data->xmcd_file = ptr; | |
461 cddb_data->xmcd_file_size = ptr2-ptr+2; | |
462 cddb_data->xmcd_file[cddb_data->xmcd_file_size] = '\0'; | |
463 // Avoid the http_free function to free the xmcd file...save a mempcy... | |
464 http_hdr->body = NULL; | |
465 http_hdr->body_size = 0; | |
466 return cddb_write_cache(cddb_data); | |
467 default: | |
468 printf("Unhandled code\n"); | |
469 } | |
470 return 0; | |
471 } | |
472 | |
473 int | |
474 cddb_request_titles(cddb_data_t *cddb_data) { | |
475 char command[1024]; | |
476 sprintf( command, "cddb+read+%s+%08lx", cddb_data->category, cddb_data->disc_id); | |
477 return cddb_http_request(command, cddb_read_parse, cddb_data); | |
478 } | |
479 | |
480 int | |
8746 | 481 cddb_parse_matches_list(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { |
482 char album_title[100]; | |
483 char *ptr = NULL; | |
484 int ret; | |
485 | |
486 ptr = strstr(http_hdr->body, "\n"); | |
487 if( ptr==NULL ) { | |
488 printf("Unable to find end of line\n"); | |
489 return -1; | |
490 } | |
491 ptr++; | |
492 // We have a list of exact/inexact matches, so which one do we use? | |
493 // So let's take the first one. | |
494 ret = sscanf(ptr, "%s %08lx %s", cddb_data->category, &(cddb_data->disc_id), album_title); | |
495 if( ret!=3 ) { | |
496 printf("Parse error\n"); | |
497 return -1; | |
498 } | |
499 ptr = strstr(http_hdr->body, album_title); | |
500 if( ptr!=NULL ) { | |
501 char *ptr2; | |
502 int len; | |
503 ptr2 = strstr(ptr, "\n"); | |
504 if( ptr2==NULL ) { | |
505 len = (http_hdr->body_size)-(ptr-(http_hdr->body)); | |
506 } else { | |
507 len = ptr2-ptr+1; | |
508 } | |
509 strncpy(album_title, ptr, len); | |
510 album_title[len-2]='\0'; | |
511 } | |
512 printf("Parse OK, found: %s\n", album_title); | |
513 return 0; | |
514 } | |
515 | |
516 int | |
6474 | 517 cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) { |
518 char album_title[100]; | |
519 char *ptr = NULL; | |
520 int ret, status; | |
521 | |
522 ret = sscanf( http_hdr->body, "%d ", &status); | |
523 if( ret!=1 ) { | |
524 printf("Parse error\n"); | |
525 return -1; | |
526 } | |
527 | |
528 switch(status) { | |
529 case 200: | |
530 // Found exact match | |
531 ret = sscanf(http_hdr->body, "%d %s %08lx %s", &status, cddb_data->category, &(cddb_data->disc_id), album_title); | |
532 if( ret!=4 ) { | |
533 printf("Parse error\n"); | |
534 return -1; | |
535 } | |
536 ptr = strstr(http_hdr->body, album_title); | |
537 if( ptr!=NULL ) { | |
538 char *ptr2; | |
539 int len; | |
540 ptr2 = strstr(ptr, "\n"); | |
541 if( ptr2==NULL ) { | |
542 len = (http_hdr->body_size)-(ptr-(http_hdr->body)); | |
543 } else { | |
544 len = ptr2-ptr+1; | |
545 } | |
546 strncpy(album_title, ptr, len); | |
547 album_title[len-2]='\0'; | |
548 } | |
549 printf("Parse OK, found: %s\n", album_title); | |
550 return cddb_request_titles(cddb_data); | |
551 case 202: | |
552 // No match found | |
553 printf("Album not found\n"); | |
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: |
571 printf("Server returns: Command syntax error\n"); | |
572 break; | |
6474 | 573 default: |
574 printf("Unhandled code\n"); | |
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 ) { | |
587 printf("Parse error\n"); | |
588 return -1; | |
589 } | |
590 | |
591 switch(status) { | |
592 case 210: | |
593 ptr = strstr(http_hdr->body, "max proto:"); | |
594 if( ptr==NULL ) { | |
595 printf("Parse error\n"); | |
596 return -1; | |
597 } | |
598 ret = sscanf(ptr, "max proto: %d", &max); | |
599 if( ret!=1 ) { | |
600 printf("Parse error\n"); | |
601 return -1; | |
602 } | |
603 cddb_data->freedb_proto_level = max; | |
604 return 0; | |
605 default: | |
606 printf("Unhandled code\n"); | |
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 ) { | |
622 printf("Parse error\n"); | |
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: | |
632 printf("No sites information available\n"); | |
633 break; | |
634 default: | |
635 printf("Unhandled code\n"); | |
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 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
651 /* Note from Eduardo Pérez Ureta <eperez@it.uc3m.es> : |
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 ) { |
837ca6fd4adf
Checked the return value when retrieving the protocol level.
bertrand
parents:
6474
diff
changeset
|
688 printf("Failed to get the protocol level\n"); |
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) { |
8962 | 714 printf("Failed to open %s device.\n", dev); |
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 |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
722 // 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
|
723 // FIXME: That's not really a good way to check |
8962 | 724 if( cddb_data.disc_id==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
|
725 printf("No CD in the drive\n"); |
15ce89ba92cf
Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents:
7721
diff
changeset
|
726 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
|
727 } |
6474 | 728 |
729 home_dir = getenv("HOME"); | |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
730 #ifdef __MINGW32__ |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
731 if( home_dir==NULL ) home_dir = getenv("USERPROFILE"); |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
732 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
|
733 // 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
|
734 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
|
735 #endif |
6474 | 736 if( home_dir==NULL ) { |
737 cddb_data.cache_dir = NULL; | |
738 } else { | |
739 cddb_data.cache_dir = (char*)malloc(strlen(home_dir)+strlen(cddb_cache_dir)+1); | |
740 if( cddb_data.cache_dir==NULL ) { | |
741 printf("Memory allocation failed\n"); | |
742 return -1; | |
743 } | |
744 sprintf(cddb_data.cache_dir, "%s%s", home_dir, cddb_cache_dir ); | |
745 } | |
746 | |
747 // Check for a cached file | |
748 if( cddb_read_cache(&cddb_data)<0 ) { | |
749 // No Cache found | |
750 if( cddb_retrieve(&cddb_data)<0 ) { | |
751 return -1; | |
752 } | |
753 } | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
754 |
6474 | 755 if( cddb_data.xmcd_file!=NULL ) { |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
756 // printf("%s\n", cddb_data.xmcd_file ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
757 *xmcd_file = cddb_data.xmcd_file; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
758 return 0; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
759 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
760 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
761 return -1; |
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 |
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 * |
7431
e46eeafcd4df
Moved all the cdinfo specific from cddb to a standalone file(cdinfo.c), so
bertrand
parents:
7269
diff
changeset
|
766 * xmcd parser |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
767 * |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
768 *******************************************************************************************************************/ |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
769 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
770 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
|
771 char *ptr, *album; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
772 ptr = strstr(line, "DTITLE="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
773 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
774 ptr += 7; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
775 album = strstr(ptr, "/"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
776 if( album==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
777 cd_info->album = (char*)malloc(strlen(album+2)+1); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
778 if( cd_info->album==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
779 return NULL; |
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 strcpy( cd_info->album, album+2 ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
782 album--; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
783 album[0] = '\0'; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
784 cd_info->artist = (char*)malloc(strlen(ptr)+1); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
785 if( cd_info->artist==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
786 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
787 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
788 strcpy( cd_info->artist, ptr ); |
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 return 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 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
793 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
794 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
|
795 char *ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
796 ptr = strstr(line, "DGENRE="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
797 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
798 ptr += 7; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
799 cd_info->genre = (char*)malloc(strlen(ptr)+1); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
800 if( cd_info->genre==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
801 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
802 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
803 strcpy( cd_info->genre, ptr ); |
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 return 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 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
808 char* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
809 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
|
810 unsigned int track_nb; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
811 unsigned long sec, off; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
812 char *ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
813 ptr = strstr(line, "TTITLE"); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
814 if( ptr!=NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
815 ptr += 6; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
816 // Here we point to the track number |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
817 track_nb = atoi(ptr); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
818 ptr = strstr(ptr, "="); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
819 if( ptr==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
820 ptr++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
821 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
822 sec = cdtoc[track_nb].frame; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
823 off = cdtoc[track_nb+1].frame-sec+1; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
824 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
825 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
|
826 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
827 return ptr; |
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 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
830 cd_info_t* |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
831 cddb_parse_xmcd(char *xmcd_file) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
832 cd_info_t *cd_info = NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
833 int length, pos = 0; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
834 char *ptr, *ptr2; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
835 unsigned int audiolen; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
836 if( xmcd_file==NULL ) return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
837 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
838 cd_info = cd_info_new(); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
839 if( cd_info==NULL ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
840 return NULL; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
841 } |
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 length = strlen(xmcd_file); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
844 ptr = xmcd_file; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
845 while( ptr!=NULL && pos<length ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
846 // Read a line |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
847 ptr2 = ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
848 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
|
849 if( ptr2[0]=='\0' ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
850 break; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
851 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
852 ptr2[0] = '\0'; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
853 // Ignore comments |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
854 if( ptr[0]!='#' ) { |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
855 // Search for the album title |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
856 if( xmcd_parse_dtitle(cd_info, ptr) ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
857 // Search for the genre |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
858 else if( xmcd_parse_dgenre(cd_info, ptr) ); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
859 // Search for a track title |
7953 | 860 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
|
861 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
862 if( ptr2[1]=='\n' ) ptr2++; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
863 pos = (ptr2+1)-ptr; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
864 ptr = ptr2+1; |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
865 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
866 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
867 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
|
868 cd_info->min = (unsigned int)(audiolen/(60*75)); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
869 cd_info->sec = (unsigned int)((audiolen/75)%60); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
870 cd_info->msec = (unsigned int)(audiolen%75); |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
871 |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
872 return cd_info; |
6474 | 873 } |
874 | |
875 #endif |