annotate libmpdemux/cddb.c @ 11505:8de9dba0ffaa

Add detection of Real rtsp when there are queries in url. Patch by rgselk <rgselknospam(at)yahoo(dot)com>
author rtognimp
date Sun, 23 Nov 2003 13:31:44 +0000
parents d42177a0da2a
children 3d75bcc28231
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
1 /*
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
2 * CDDB HTTP protocol
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
4 * (C) 2002, MPlayer team.
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
5 *
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
6 * Implementation follow the freedb.howto1.06.txt specification
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
7 * from http://freedb.freedb.org
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
8 *
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
9 * discid computation by Jeremy D. Zawodny
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
10 * Copyright (c) 1998-2000 Jeremy D. Zawodny <Jeremy@Zawodny.com>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
11 * Code release under GPL
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
12 *
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
13 */
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
14
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
15 #include "config.h"
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
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
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
18
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
19 #include <stdio.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
20 #include <stdlib.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
21 #include <fcntl.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
22 #include <stdarg.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
23 #include <errno.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
24 #include <netdb.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
25 #include <unistd.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
26 #include <string.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
27 #include <sys/ioctl.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
28 #include <sys/types.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
29 #include <sys/stat.h>
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
30
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
31 #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
32 #include <linux/cdrom.h>
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
33 #elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__NetBSD__) || defined(__OpenBSD__)
7269
a5f1baaf7714 Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents: 6697
diff changeset
34 #include <sys/cdio.h>
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
35 #endif
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
36
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
37 #include "cdd.h"
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
38 #include "../version.h"
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
39 #include "stream.h"
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
40 #include "network.h"
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
41
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
42 #define DEFAULT_FREEDB_SERVER "freedb.freedb.org"
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
43 #define DEFAULT_CACHE_DIR "/.cddb/"
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
44
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
45 stream_t* open_cdda(char *dev, char *track);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
46
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
47 static cd_toc_t cdtoc[100];
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
48
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
49 #if defined(__linux__)
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
50 int
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
51 read_toc(const char *dev) {
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
52 int drive;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
53 struct cdrom_tochdr tochdr;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
54 struct cdrom_tocentry tocentry;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
55 int i;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
56
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
57 drive = open(dev, O_RDONLY | O_NONBLOCK);
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
58 if( drive<0 ) {
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
59 return drive;
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
60 }
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
61
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
62 ioctl(drive, CDROMREADTOCHDR, &tochdr);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
63 for (i = tochdr.cdth_trk0; i <= tochdr.cdth_trk1; i++) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
64 tocentry.cdte_track = i;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
65 tocentry.cdte_format = CDROM_MSF;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
66 ioctl(drive, CDROMREADTOCENTRY, &tocentry);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
67 cdtoc[i-1].min = tocentry.cdte_addr.msf.minute;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
68 cdtoc[i-1].sec = tocentry.cdte_addr.msf.second;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
69 cdtoc[i-1].frame = tocentry.cdte_addr.msf.frame;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
70 cdtoc[i-1].frame += cdtoc[i-1].min*60*75;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
71 cdtoc[i-1].frame += cdtoc[i-1].sec*75;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
72 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
73 tocentry.cdte_track = 0xAA;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
74 tocentry.cdte_format = CDROM_MSF;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
75 ioctl(drive, CDROMREADTOCENTRY, &tocentry);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
76 cdtoc[tochdr.cdth_trk1].min = tocentry.cdte_addr.msf.minute;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
77 cdtoc[tochdr.cdth_trk1].sec = tocentry.cdte_addr.msf.second;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
78 cdtoc[tochdr.cdth_trk1].frame = tocentry.cdte_addr.msf.frame;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
79 cdtoc[tochdr.cdth_trk1].frame += cdtoc[tochdr.cdth_trk1].min*60*75;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
80 cdtoc[tochdr.cdth_trk1].frame += cdtoc[tochdr.cdth_trk1].sec*75;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
81 close(drive);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
82 return tochdr.cdth_trk1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
83 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
84
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
85 #elif defined(__FreeBSD__) || defined(__bsdi__)
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
86 int
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
87 read_toc(const char *dev) {
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
88 int drive;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
89 struct ioc_toc_header tochdr;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
90 struct ioc_read_toc_single_entry tocentry;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
91 int i;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
92
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
93 drive = open(dev, O_RDONLY | O_NONBLOCK);
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
94 if( drive<0 ) {
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
95 return drive;
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
96 }
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
97
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
98 ioctl(drive, CDIOREADTOCHEADER, &tochdr);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
99 for (i = tochdr.starting_track; i <= tochdr.ending_track; i++) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
100 tocentry.track = i;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
101 tocentry.address_format = CD_MSF_FORMAT;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
102 ioctl(drive, CDIOREADTOCENTRY, &tocentry);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
103 cdtoc[i-1].min = tocentry.entry.addr.msf.minute;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
104 cdtoc[i-1].sec = tocentry.entry.addr.msf.second;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
105 cdtoc[i-1].frame = tocentry.entry.addr.msf.frame;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
106 cdtoc[i-1].frame += cdtoc[i-1].min*60*75;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
107 cdtoc[i-1].frame += cdtoc[i-1].sec*75;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
108 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
109 tocentry.track = 0xAA;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
110 tocentry.address_format = CD_MSF_FORMAT;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
111 ioctl(drive, CDIOREADTOCENTRY, &tocentry);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
112 cdtoc[tochdr.ending_track].min = tocentry.entry.addr.msf.minute;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
113 cdtoc[tochdr.ending_track].sec = tocentry.entry.addr.msf.second;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
114 cdtoc[tochdr.ending_track].frame = tocentry.entry.addr.msf.frame;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
115 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].min*60*75;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
116 cdtoc[tochdr.ending_track].frame += cdtoc[tochdr.ending_track].sec*75;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
117 close(drive);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
118 return tochdr.ending_track;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
119 }
7269
a5f1baaf7714 Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents: 6697
diff changeset
120
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
121 #elif defined(__NetBSD__) || defined(__OpenBSD__)
8609
1d98280b9ad1 The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents: 8557
diff changeset
122 int
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
123 read_toc(const char *dev) {
8609
1d98280b9ad1 The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents: 8557
diff changeset
124 int drive;
1d98280b9ad1 The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents: 8557
diff changeset
125 struct ioc_toc_header tochdr;
1d98280b9ad1 The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents: 8557
diff changeset
126 struct ioc_read_toc_entry tocentry;
1d98280b9ad1 The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents: 8557
diff changeset
127 int i;
1d98280b9ad1 The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents: 8557
diff changeset
128 struct cd_toc_entry toc_buffer;
1d98280b9ad1 The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents: 8557
diff changeset
129
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
130 drive = open(dev, O_RDONLY | O_NONBLOCK);
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
131 if( drive<0 ) {
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
132 return drive;
8609
1d98280b9ad1 The following patch allows the MPlayer "cdparanoia" support to work on
arpi
parents: 8557
diff changeset
133 }
7269
a5f1baaf7714 Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents: 6697
diff changeset
134
a5f1baaf7714 Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents: 6697
diff changeset
135 ioctl(drive, CDIOREADTOCHEADER, &tochdr);
a5f1baaf7714 Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents: 6697
diff changeset
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 }
a5f1baaf7714 Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents: 6697
diff changeset
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 close(drive);
a5f1baaf7714 Applied patch for OpenBDS from Marc Espie (submitted by Bj«Órn Sandell <biorn@dce.chalmers.se>)
bertrand
parents: 6697
diff changeset
157 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
158 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
159 #endif
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
160
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
161 unsigned int
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
162 cddb_sum(int n) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
163 unsigned int ret;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
164
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
165 ret = 0;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
166 while (n > 0) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
167 ret += (n % 10);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
168 n /= 10;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
169 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
170 return ret;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
171 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
172
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
173 unsigned long
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
174 cddb_discid(int tot_trks) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
175 unsigned int i, t = 0, n = 0;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
176
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
177 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
178 while (i < (unsigned int)tot_trks) {
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
179 n = n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
180 i++;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
181 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
182 t = ((cdtoc[tot_trks].min * 60) + cdtoc[tot_trks].sec) -
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
183 ((cdtoc[0].min * 60) + cdtoc[0].sec);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
184 return ((n % 0xff) << 24 | t << 8 | tot_trks);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
185 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
186
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
187
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
188
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
189 int
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
190 cddb_http_request(char *command, int (*reply_parser)(HTTP_header_t*,cddb_data_t*), cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
191 char request[4096];
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
192 int fd, ret = 0;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
193 URL_t *url;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
194 HTTP_header_t *http_hdr;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
195
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
196 if( reply_parser==NULL || command==NULL || cddb_data==NULL ) return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
197
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
198 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 );
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
199 printf("Request[%s]\n", request );
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
200
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
201 url = url_new(request);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
202 if( url==NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
203 printf("Not a valid URL\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
204 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
205 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
206
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
207 fd = http_send_request(url);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
208 if( fd<0 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
209 printf("failed to send the http request\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
210 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
211 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
212
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
213 http_hdr = http_read_response( fd );
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
214 if( http_hdr==NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
215 printf("Failed to read the http response\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
216 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
217 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
218
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
219 http_debug_hdr(http_hdr);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
220 printf("body=[%s]\n", http_hdr->body );
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
221
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
222 switch(http_hdr->status_code) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
223 case 200:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
224 ret = reply_parser(http_hdr, cddb_data);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
225 break;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
226 case 400:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
227 printf("Not Found\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
228 break;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
229 default:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
230 printf("Unknown Error code\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
231 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
232
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
233 http_free( http_hdr );
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
234 url_free( url );
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
235
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
236 return ret;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
237 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
238
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
239 int
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
240 cddb_read_cache(cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
241 char file_name[100];
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
242 struct stat stats;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
243 int file_fd, ret;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
244 size_t file_size;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
245
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
246 if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
247
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
248 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
249
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
250 file_fd = open(file_name, O_RDONLY);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
251 if( file_fd<0 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
252 printf("No cache found\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
253 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
254 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
255
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
256 ret = fstat( file_fd, &stats );
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
257 if( ret<0 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
258 perror("fstat");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
259 file_size = 4096;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
260 } else {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
261 file_size = stats.st_size;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
262 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
263
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
264 cddb_data->xmcd_file = (char*)malloc(file_size);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
265 if( cddb_data->xmcd_file==NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
266 printf("Memory allocation failed\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
267 close(file_fd);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
268 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
269 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
270 cddb_data->xmcd_file_size = read(file_fd, cddb_data->xmcd_file, file_size);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
271 if( cddb_data->xmcd_file_size!=file_size ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
272 printf("Not all the xmcd file has been read\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
273 close(file_fd);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
274 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
275 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
276
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
277 close(file_fd);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
278
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
279 return 0;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
280 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
281
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
282 int
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
283 cddb_write_cache(cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
284 // We have the file, save it for cache.
7721
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
285 struct stat file_stat;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
286 char file_name[100];
7721
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
287 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
288 int wrote=0;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
289
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
290 if( cddb_data==NULL || cddb_data->cache_dir==NULL ) return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
291
7721
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
292 // Check if the CDDB cache dir exist
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
293 ret = stat( cddb_data->cache_dir, &file_stat );
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
294 if( ret<0 ) {
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
295 // Directory not present, create it.
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
296 ret = mkdir( cddb_data->cache_dir, 0755 );
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
297 if( ret<0 ) {
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
298 perror("mkdir");
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
299 printf("Failed to create directory %s\n", cddb_data->cache_dir );
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
300 return -1;
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
301 }
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
302 }
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
303
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
304 sprintf( file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id );
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
305
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
306 file_fd = creat(file_name, S_IREAD|S_IWRITE);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
307 if( file_fd<0 ) {
7721
765afc1fcd67 Create the ~/.cddb directory if not present.
bertrand
parents: 7431
diff changeset
308 perror("create");
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
309 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
310 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
311
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
312 wrote = write(file_fd, cddb_data->xmcd_file, cddb_data->xmcd_file_size);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
313 if( wrote<0 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
314 perror("write");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
315 close(file_fd);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
316 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
317 }
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
318 if( (unsigned int)wrote!=cddb_data->xmcd_file_size ) {
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
319 printf("Not all the xmcd file has been written\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
320 close(file_fd);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
321 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
322 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
323
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
324 close(file_fd);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
325
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
326 return 0;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
327 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
328
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
329 int
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
330 cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
331 unsigned long disc_id;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
332 char category[100];
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
333 char *ptr=NULL, *ptr2=NULL;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
334 int ret, status;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
335
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
336 if( http_hdr==NULL || cddb_data==NULL ) return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
337
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
338 ret = sscanf( http_hdr->body, "%d ", &status);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
339 if( ret!=1 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
340 printf("Parse error\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
341 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
342 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
343
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
344 switch(status) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
345 case 210:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
346 ret = sscanf( http_hdr->body, "%d %s %08lx", &status, category, &disc_id);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
347 if( ret!=3 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
348 printf("Parse error\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
349 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
350 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
351 // Check if it's a xmcd database file
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
352 ptr = strstr(http_hdr->body, "# xmcd");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
353 if( ptr==NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
354 printf("Invalid xmcd database file returned\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
355 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
356 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
357 // Ok found the beginning of the file
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
358 // look for the end
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
359 ptr2 = strstr(ptr, "\r\n.\r\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
360 if( ptr2==NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
361 ptr2 = strstr(ptr, "\n.\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
362 if( ptr2==NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
363 printf("Unable to find '.'\n");
8557
97cf659a4c38 - fixed uninitialized offsets[]
arpi
parents: 7953
diff changeset
364 ptr2=ptr+strlen(ptr); //return -1;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
365 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
366 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
367 // Ok found the end
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
368 // do a sanity check
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7746
diff changeset
369 if( http_hdr->body_size<(unsigned int)(ptr2-ptr) ) {
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
370 printf("Unexpected fix me\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
371 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
372 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
373 cddb_data->xmcd_file = ptr;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
374 cddb_data->xmcd_file_size = ptr2-ptr+2;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
375 cddb_data->xmcd_file[cddb_data->xmcd_file_size] = '\0';
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
376 // Avoid the http_free function to free the xmcd file...save a mempcy...
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
377 http_hdr->body = NULL;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
378 http_hdr->body_size = 0;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
379 return cddb_write_cache(cddb_data);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
380 default:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
381 printf("Unhandled code\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
382 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
383 return 0;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
384 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
385
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
386 int
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
387 cddb_request_titles(cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
388 char command[1024];
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
389 sprintf( command, "cddb+read+%s+%08lx", cddb_data->category, cddb_data->disc_id);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
390 return cddb_http_request(command, cddb_read_parse, cddb_data);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
391 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
392
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
393 int
8746
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
394 cddb_parse_matches_list(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
395 char album_title[100];
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
396 char *ptr = NULL;
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
397 int ret;
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
398
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
399 ptr = strstr(http_hdr->body, "\n");
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
400 if( ptr==NULL ) {
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
401 printf("Unable to find end of line\n");
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
402 return -1;
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
403 }
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
404 ptr++;
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
405 // We have a list of exact/inexact matches, so which one do we use?
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
406 // So let's take the first one.
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
407 ret = sscanf(ptr, "%s %08lx %s", cddb_data->category, &(cddb_data->disc_id), album_title);
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
408 if( ret!=3 ) {
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
409 printf("Parse error\n");
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
410 return -1;
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
411 }
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
412 ptr = strstr(http_hdr->body, album_title);
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
413 if( ptr!=NULL ) {
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
414 char *ptr2;
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
415 int len;
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
416 ptr2 = strstr(ptr, "\n");
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
417 if( ptr2==NULL ) {
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
418 len = (http_hdr->body_size)-(ptr-(http_hdr->body));
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
419 } else {
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
420 len = ptr2-ptr+1;
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
421 }
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
422 strncpy(album_title, ptr, len);
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
423 album_title[len-2]='\0';
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
424 }
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
425 printf("Parse OK, found: %s\n", album_title);
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
426 return 0;
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
427 }
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
428
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
429 int
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
430 cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
431 char album_title[100];
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
432 char *ptr = NULL;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
433 int ret, status;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
434
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
435 ret = sscanf( http_hdr->body, "%d ", &status);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
436 if( ret!=1 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
437 printf("Parse error\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
438 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
439 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
440
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
441 switch(status) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
442 case 200:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
443 // Found exact match
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
444 ret = sscanf(http_hdr->body, "%d %s %08lx %s", &status, cddb_data->category, &(cddb_data->disc_id), album_title);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
445 if( ret!=4 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
446 printf("Parse error\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
447 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
448 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
449 ptr = strstr(http_hdr->body, album_title);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
450 if( ptr!=NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
451 char *ptr2;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
452 int len;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
453 ptr2 = strstr(ptr, "\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
454 if( ptr2==NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
455 len = (http_hdr->body_size)-(ptr-(http_hdr->body));
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
456 } else {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
457 len = ptr2-ptr+1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
458 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
459 strncpy(album_title, ptr, len);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
460 album_title[len-2]='\0';
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
461 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
462 printf("Parse OK, found: %s\n", album_title);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
463 return cddb_request_titles(cddb_data);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
464 case 202:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
465 // No match found
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
466 printf("Album not found\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
467 break;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
468 case 210:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
469 // Found exact matches, list follows
8746
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
470 cddb_parse_matches_list(http_hdr, cddb_data);
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
471 return cddb_request_titles(cddb_data);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
472 /*
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
473 body=[210 Found exact matches, list follows (until terminating `.')
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
474 misc c711930d Santana / Supernatural
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
475 rock c711930d Santana / Supernatural
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
476 blues c711930d Santana / Supernatural
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
477 .]
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
478 */
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
479 case 211:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
480 // Found inexact matches, list follows
8746
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
481 cddb_parse_matches_list(http_hdr, cddb_data);
f1fc23f6203b - If CDDB fail, try CDDA
bertrand
parents: 8609
diff changeset
482 return cddb_request_titles(cddb_data);
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
483 case 500:
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
484 printf("Server returns: Command syntax error\n");
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
485 break;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
486 default:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
487 printf("Unhandled code\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
488 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
489 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
490 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
491
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
492 int
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
493 cddb_proto_level_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
494 int max;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
495 int ret, status;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
496 char *ptr;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
497
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
498 ret = sscanf( http_hdr->body, "%d ", &status);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
499 if( ret!=1 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
500 printf("Parse error\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
501 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
502 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
503
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
504 switch(status) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
505 case 210:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
506 ptr = strstr(http_hdr->body, "max proto:");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
507 if( ptr==NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
508 printf("Parse error\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
509 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
510 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
511 ret = sscanf(ptr, "max proto: %d", &max);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
512 if( ret!=1 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
513 printf("Parse error\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
514 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
515 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
516 cddb_data->freedb_proto_level = max;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
517 return 0;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
518 default:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
519 printf("Unhandled code\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
520 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
521 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
522 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
523
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
524 int
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
525 cddb_get_proto_level(cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
526 return cddb_http_request("stat", cddb_proto_level_parse, cddb_data);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
527 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
528
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
529 int
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
530 cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
531 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
532
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
533 ret = sscanf( http_hdr->body, "%d ", &status);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
534 if( ret!=1 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
535 printf("Parse error\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
536 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
537 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
538
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
539 switch(status) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
540 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
541 // 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
542 ret = cddb_data->anonymous; // For gcc complaining about unused parameter.
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
543 return 0;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
544 case 401:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
545 printf("No sites information available\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
546 break;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
547 default:
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
548 printf("Unhandled code\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
549 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
550 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
551 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
552
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
553 int
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
554 cddb_get_freedb_sites(cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
555 return cddb_http_request("sites", cddb_freedb_sites_parse, cddb_data);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
556 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
557
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
558 void
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
559 cddb_create_hello(cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
560 char host_name[51];
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
561 char *user_name;
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
562
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
563 if( cddb_data->anonymous ) { // Default is anonymous
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
564 /* 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
565 * 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
566 * Software that sends this is considered spyware
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
567 * that most people don't like.
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
568 */
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
569 user_name = "anonymous";
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
570 strcpy(host_name, "localhost");
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
571 } else {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
572 if( gethostname(host_name, 50)<0 ) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
573 strcpy(host_name, "localhost");
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
574 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
575 user_name = getenv("LOGNAME");
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
576 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
577 sprintf( cddb_data->cddb_hello, "&hello=%s+%s+%s+%s", user_name, host_name, "MPlayer", VERSION );
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
578 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
579
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
580 int
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
581 cddb_retrieve(cddb_data_t *cddb_data) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
582 char offsets[1024], command[1024];
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
583 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
584 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
585 int ret;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
586
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
587 ptr = offsets;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
588 for( i=0; i<cddb_data->tracks ; i++ ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
589 ptr += sprintf(ptr, "%d+", cdtoc[i].frame );
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
590 }
8557
97cf659a4c38 - fixed uninitialized offsets[]
arpi
parents: 7953
diff changeset
591 ptr[0]=0;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
592 time_len = (cdtoc[cddb_data->tracks].frame)/75;
8557
97cf659a4c38 - fixed uninitialized offsets[]
arpi
parents: 7953
diff changeset
593
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
594 cddb_data->freedb_server = DEFAULT_FREEDB_SERVER;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
595 cddb_data->freedb_proto_level = 1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
596 cddb_data->xmcd_file = NULL;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
597
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
598 cddb_create_hello(cddb_data);
6475
837ca6fd4adf Checked the return value when retrieving the protocol level.
bertrand
parents: 6474
diff changeset
599 if( cddb_get_proto_level(cddb_data)<0 ) {
837ca6fd4adf Checked the return value when retrieving the protocol level.
bertrand
parents: 6474
diff changeset
600 printf("Failed to get the protocol level\n");
837ca6fd4adf Checked the return value when retrieving the protocol level.
bertrand
parents: 6474
diff changeset
601 return -1;
837ca6fd4adf Checked the return value when retrieving the protocol level.
bertrand
parents: 6474
diff changeset
602 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
603
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
604 //cddb_get_freedb_sites(&cddb_data);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
605
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
606 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
607 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
608 if( ret<0 ) return -1;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
609
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
610 if( cddb_data->cache_dir!=NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
611 free(cddb_data->cache_dir);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
612 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
613 return 0;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
614 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
615
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
616 int
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
617 cddb_resolve(const char *dev, char **xmcd_file) {
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
618 char cddb_cache_dir[] = DEFAULT_CACHE_DIR;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
619 char *home_dir = NULL;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
620 cddb_data_t cddb_data;
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
621 int ret;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
622
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
623 ret = read_toc(dev);
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
624 if( ret<0 ) {
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
625 printf("Failed to open %s device.\n", dev);
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
626 return -1;
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
627 }
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
628 cddb_data.tracks = ret;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
629 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
630 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
631
15ce89ba92cf Don't start a CDDB request to the CDDB server if there is no CD in the drive,
bertrand
parents: 7721
diff changeset
632 // 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
633 // FIXME: That's not really a good way to check
8962
c61e70388f6b Removed the hardcoded cdrom device.
bertrand
parents: 8746
diff changeset
634 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
635 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
636 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
637 }
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
638
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
639 home_dir = getenv("HOME");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
640 if( home_dir==NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
641 cddb_data.cache_dir = NULL;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
642 } else {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
643 cddb_data.cache_dir = (char*)malloc(strlen(home_dir)+strlen(cddb_cache_dir)+1);
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
644 if( cddb_data.cache_dir==NULL ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
645 printf("Memory allocation failed\n");
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
646 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
647 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
648 sprintf(cddb_data.cache_dir, "%s%s", home_dir, cddb_cache_dir );
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
649 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
650
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
651 // Check for a cached file
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
652 if( cddb_read_cache(&cddb_data)<0 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
653 // No Cache found
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
654 if( cddb_retrieve(&cddb_data)<0 ) {
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
655 return -1;
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
656 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
657 }
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
658
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
659 if( cddb_data.xmcd_file!=NULL ) {
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
660 // printf("%s\n", cddb_data.xmcd_file );
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
661 *xmcd_file = cddb_data.xmcd_file;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
662 return 0;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
663 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
664
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
665 return -1;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
666 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
667
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 *
7431
e46eeafcd4df Moved all the cdinfo specific from cddb to a standalone file(cdinfo.c), so
bertrand
parents: 7269
diff changeset
670 * xmcd parser
6697
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
671 *
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
672 *******************************************************************************************************************/
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
673 char*
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
674 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
675 char *ptr, *album;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
676 ptr = strstr(line, "DTITLE=");
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
677 if( ptr!=NULL ) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
678 ptr += 7;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
679 album = strstr(ptr, "/");
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
680 if( album==NULL ) return NULL;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
681 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
682 if( cd_info->album==NULL ) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
683 return NULL;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
684 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
685 strcpy( cd_info->album, album+2 );
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
686 album--;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
687 album[0] = '\0';
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
688 cd_info->artist = (char*)malloc(strlen(ptr)+1);
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
689 if( cd_info->artist==NULL ) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
690 return NULL;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
691 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
692 strcpy( cd_info->artist, ptr );
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
693 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
694 return ptr;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
695 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
696
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
697 char*
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
698 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
699 char *ptr;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
700 ptr = strstr(line, "DGENRE=");
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
701 if( ptr!=NULL ) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
702 ptr += 7;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
703 cd_info->genre = (char*)malloc(strlen(ptr)+1);
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
704 if( cd_info->genre==NULL ) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
705 return NULL;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
706 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
707 strcpy( cd_info->genre, ptr );
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
708 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
709 return ptr;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
710 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
711
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
712 char*
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
713 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
714 unsigned int track_nb;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
715 unsigned long sec, off;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
716 char *ptr;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
717 ptr = strstr(line, "TTITLE");
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
718 if( ptr!=NULL ) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
719 ptr += 6;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
720 // Here we point to the track number
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
721 track_nb = atoi(ptr);
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
722 ptr = strstr(ptr, "=");
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
723 if( ptr==NULL ) return NULL;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
724 ptr++;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
725
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
726 sec = cdtoc[track_nb].frame;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
727 off = cdtoc[track_nb+1].frame-sec+1;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
728
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
729 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
730 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
731 return ptr;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
732 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
733
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
734 cd_info_t*
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
735 cddb_parse_xmcd(char *xmcd_file) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
736 cd_info_t *cd_info = NULL;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
737 int length, pos = 0;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
738 char *ptr, *ptr2;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
739 unsigned int audiolen;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
740 if( xmcd_file==NULL ) return NULL;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
741
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
742 cd_info = cd_info_new();
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
743 if( cd_info==NULL ) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
744 return NULL;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
745 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
746
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
747 length = strlen(xmcd_file);
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
748 ptr = xmcd_file;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
749 while( ptr!=NULL && pos<length ) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
750 // Read a line
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
751 ptr2 = ptr;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
752 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
753 if( ptr2[0]=='\0' ) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
754 break;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
755 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
756 ptr2[0] = '\0';
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
757 // Ignore comments
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
758 if( ptr[0]!='#' ) {
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
759 // Search for the album title
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
760 if( xmcd_parse_dtitle(cd_info, ptr) );
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
761 // Search for the genre
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
762 else if( xmcd_parse_dgenre(cd_info, ptr) );
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
763 // Search for a track title
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7746
diff changeset
764 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
765 }
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
766 if( ptr2[1]=='\n' ) ptr2++;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
767 pos = (ptr2+1)-ptr;
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
768 ptr = ptr2+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 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
772 cd_info->min = (unsigned int)(audiolen/(60*75));
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
773 cd_info->sec = (unsigned int)((audiolen/75)%60);
4cade272ce2b Added a simple xmcd parser to retreive the tracks name.
bertrand
parents: 6475
diff changeset
774 cd_info->msec = (unsigned int)(audiolen%75);
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 return cd_info;
6474
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
777 }
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
778
654b26c941e5 CDDB support added.
bertrand
parents:
diff changeset
779 #endif