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