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