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