Mercurial > mplayer.hg
annotate stream/stream_cddb.c @ 30746:7092b8fc23f4
Add cddb:// support for OS/2
author | komh |
---|---|
date | Sun, 28 Feb 2010 03:26:18 +0000 |
parents | 9be8d71ca9a5 |
children | ce19feeb5cbb |
rev | line source |
---|---|
6474 | 1 /* |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
2 * CDDB HTTP protocol |
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
3 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
4 * Copyright (C) 2002 Bertrand Baudet <bertrand_baudet@yahoo.com> |
6474 | 5 * |
6 * Implementation follow the freedb.howto1.06.txt specification | |
7 * from http://freedb.freedb.org | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
8 * |
6474 | 9 * discid computation by Jeremy D. Zawodny |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
10 * Copyright (c) 1998-2000 Jeremy D. Zawodny <Jeremy@Zawodny.com> |
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
11 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
12 * This file is part of MPlayer. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
13 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
14 * MPlayer is free software; you can redistribute it and/or modify |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
15 * it under the terms of the GNU General Public License as published by |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
16 * the Free Software Foundation; either version 2 of the License, or |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
17 * (at your option) any later version. |
6474 | 18 * |
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
19 * MPlayer is distributed in the hope that it will be useful, |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
22 * GNU General Public License for more details. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
23 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
24 * You should have received a copy of the GNU General Public License along |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
25 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
6474 | 27 */ |
28 | |
29 #include "config.h" | |
30 | |
31 #include <stdio.h> | |
32 #include <stdlib.h> | |
33 #include <fcntl.h> | |
34 #include <stdarg.h> | |
35 #include <errno.h> | |
36 #include <unistd.h> | |
37 #include <string.h> | |
25792 | 38 #include <limits.h> |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
27461
diff
changeset
|
39 #if defined(__MINGW32__) || defined(__CYGWIN__) |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
40 #ifdef __MINGW32__ |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
41 #define mkdir(a,b) mkdir(a) |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
42 #endif |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
43 #include <windows.h> |
28402 | 44 #if HAVE_WINSOCK2_H |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
45 #include <winsock2.h> |
17446 | 46 #endif |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
47 #else |
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
48 #include <netdb.h> |
6474 | 49 #include <sys/ioctl.h> |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
50 #endif |
6474 | 51 #include <sys/types.h> |
52 #include <sys/stat.h> | |
53 | |
16967
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
54 #include "mp_msg.h" |
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
55 #include "help_mp.h" |
32e2c59c8e86
[TRIVIAL] More translatables to help_mp and printfs to mp_msg on libmpdemux
reynaldo
parents:
16935
diff
changeset
|
56 |
6474 | 57 #if defined(__linux__) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
58 #include <linux/cdrom.h> |
21848 | 59 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
60 #include <sys/cdio.h> |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
27461
diff
changeset
|
61 #elif defined(__MINGW32__) || defined(__CYGWIN__) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
62 #include <ddk/ntddcdrm.h> |
30613 | 63 #elif defined(__bsdi__) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
64 #include <dvd.h> |
25393 | 65 #elif defined(__APPLE__) || defined(__DARWIN__) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
66 #include <IOKit/storage/IOCDTypes.h> |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
67 #include <IOKit/storage/IOCDMediaBSDClient.h> |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
68 #include "mpbswap.h" |
6474 | 69 #endif |
70 | |
30746 | 71 #include "osdep/osdep.h" |
72 | |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
73 #include "cdd.h" |
17012 | 74 #include "version.h" |
6474 | 75 #include "stream.h" |
76 #include "network.h" | |
25948
e8945e43a36f
#include just libavutil/common.h, not all of libavutil/intreadwrite.h.
diego
parents:
25796
diff
changeset
|
77 #include "libavutil/common.h" |
6474 | 78 |
30685 | 79 #ifndef O_BINARY |
80 #define O_BINARY 0 | |
81 #endif | |
82 | |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
83 #define DEFAULT_FREEDB_SERVER "freedb.freedb.org" |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
84 #define DEFAULT_CACHE_DIR "/.cddb/" |
6474 | 85 |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
86 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
|
87 static int cdtoc_last_track; |
6474 | 88 |
30693 | 89 static int read_toc(const char *dev) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
90 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
91 int first = 0, last = -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
92 int i; |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
27461
diff
changeset
|
93 #if defined(__MINGW32__) || defined(__CYGWIN__) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
94 HANDLE drive; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
95 DWORD r; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
96 CDROM_TOC toc; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
97 char device[10]; |
20586
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
98 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
99 sprintf(device, "\\\\.\\%s", dev); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
100 drive = CreateFile(device, GENERIC_READ, FILE_SHARE_READ, NULL, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
101 OPEN_EXISTING, 0, 0); |
20586
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
102 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
103 if (!DeviceIoControl(drive, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
104 sizeof(CDROM_TOC), &r, 0)) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
105 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToReadTOC); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
106 return 0; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
107 } |
20586
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
108 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
109 first = toc.FirstTrack - 1; last = toc.LastTrack; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
110 for (i = first; i <= last; i++) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
111 cdtoc[i].min = toc.TrackData[i].Address[1]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
112 cdtoc[i].sec = toc.TrackData[i].Address[2]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
113 cdtoc[i].frame = toc.TrackData[i].Address[3]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
114 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
115 CloseHandle(drive); |
20586
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
116 |
30746 | 117 #elif defined(__OS2__) |
118 UCHAR auchParamDisk[4] = {'C', 'D', '0', '1'}; | |
119 | |
120 struct { | |
121 BYTE bFirstTrack; | |
122 BYTE bLastTrack; | |
123 BYTE bLeadOutF; | |
124 BYTE bLeadOutS; | |
125 BYTE bLeadOutM; | |
126 BYTE bLeadOutReserved; | |
127 } __attribute__((packed)) sDataDisk; | |
128 | |
129 struct { | |
130 UCHAR auchSign[4]; | |
131 BYTE bTrack; | |
132 } __attribute__((packed)) sParamTrack = {{'C', 'D', '0', '1'},}; | |
133 | |
134 struct { | |
135 BYTE bStartF; | |
136 BYTE bStartS; | |
137 BYTE bStartM; | |
138 BYTE bStartReserved; | |
139 BYTE bControlInfo; | |
140 } __attribute__((packed)) sDataTrack; | |
141 | |
142 HFILE hcd; | |
143 ULONG ulAction; | |
144 ULONG ulParamLen; | |
145 ULONG ulDataLen; | |
146 ULONG rc; | |
147 | |
148 rc = DosOpen(dev, &hcd, &ulAction, 0, FILE_NORMAL, | |
149 OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW, | |
150 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE | OPEN_FLAGS_DASD, | |
151 NULL); | |
152 if (rc) { | |
153 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToReadTOC); | |
154 return -1; | |
155 } | |
156 | |
157 rc = DosDevIOCtl(hcd, IOCTL_CDROMAUDIO, CDROMAUDIO_GETAUDIODISK, | |
158 auchParamDisk, sizeof(auchParamDisk), &ulParamLen, | |
159 &sDataDisk, sizeof(sDataDisk), &ulDataLen); | |
160 if (!rc) { | |
161 first = sDataDisk.bFirstTrack - 1; | |
162 last = sDataDisk.bLastTrack; | |
163 for (i = first; i <= last; i++) { | |
164 if (i == last) { | |
165 sDataTrack.bStartM = sDataDisk.bLeadOutM; | |
166 sDataTrack.bStartS = sDataDisk.bLeadOutS; | |
167 sDataTrack.bStartF = sDataDisk.bLeadOutF; | |
168 } else { | |
169 sParamTrack.bTrack = i + 1; | |
170 rc = DosDevIOCtl(hcd, IOCTL_CDROMAUDIO, CDROMAUDIO_GETAUDIOTRACK, | |
171 &sParamTrack, sizeof(sParamTrack), &ulParamLen, | |
172 &sDataTrack, sizeof(sDataTrack), &ulDataLen); | |
173 if (rc) | |
174 break; | |
175 } | |
176 | |
177 cdtoc[i].min = sDataTrack.bStartM; | |
178 cdtoc[i].sec = sDataTrack.bStartS; | |
179 cdtoc[i].frame = sDataTrack.bStartF; | |
180 } | |
181 } | |
182 | |
183 DosClose(hcd); | |
184 | |
185 if (rc) { | |
186 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToReadTOC); | |
187 return -1; | |
188 } | |
20586
d9558d78179d
cosmetics: move WIN32 read_toc code to allow for summarizing more common
reimar
parents:
20583
diff
changeset
|
189 #else |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
190 int drive; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
191 drive = open(dev, O_RDONLY | O_NONBLOCK); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
192 if (drive < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
193 return drive; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
194 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
195 |
20587 | 196 #if defined(__linux__) || defined(__bsdi__) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
197 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
198 struct cdrom_tochdr tochdr; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
199 ioctl(drive, CDROMREADTOCHDR, &tochdr); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
200 first = tochdr.cdth_trk0 - 1; last = tochdr.cdth_trk1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
201 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
202 for (i = first; i <= last; i++) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
203 struct cdrom_tocentry tocentry; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
204 tocentry.cdte_track = (i == last) ? 0xAA : i + 1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
205 tocentry.cdte_format = CDROM_MSF; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
206 ioctl(drive, CDROMREADTOCENTRY, &tocentry); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
207 cdtoc[i].min = tocentry.cdte_addr.msf.minute; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
208 cdtoc[i].sec = tocentry.cdte_addr.msf.second; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
209 cdtoc[i].frame = tocentry.cdte_addr.msf.frame; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
210 } |
21848 | 211 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
212 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
213 struct ioc_toc_header tochdr; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
214 ioctl(drive, CDIOREADTOCHEADER, &tochdr); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
215 first = tochdr.starting_track - 1; last = tochdr.ending_track; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
216 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
217 for (i = first; i <= last; i++) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
218 struct ioc_read_toc_single_entry tocentry; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
219 tocentry.track = (i == last) ? 0xAA : i + 1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
220 tocentry.address_format = CD_MSF_FORMAT; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
221 ioctl(drive, CDIOREADTOCENTRY, &tocentry); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
222 cdtoc[i].min = tocentry.entry.addr.msf.minute; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
223 cdtoc[i].sec = tocentry.entry.addr.msf.second; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
224 cdtoc[i].frame = tocentry.entry.addr.msf.frame; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
225 } |
8962 | 226 #elif defined(__NetBSD__) || defined(__OpenBSD__) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
227 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
228 struct ioc_toc_header tochdr; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
229 ioctl(drive, CDIOREADTOCHEADER, &tochdr); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
230 first = tochdr.starting_track - 1; last = tochdr.ending_track; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
231 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
232 for (i = first; i <= last; i++) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
233 struct ioc_read_toc_entry tocentry; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
234 struct cd_toc_entry toc_buffer; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
235 tocentry.starting_track = (i == last) ? 0xAA : i + 1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
236 tocentry.address_format = CD_MSF_FORMAT; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
237 tocentry.data = &toc_buffer; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
238 tocentry.data_len = sizeof(toc_buffer); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
239 ioctl(drive, CDIOREADTOCENTRYS, &tocentry); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
240 cdtoc[i].min = toc_buffer.addr.msf.minute; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
241 cdtoc[i].sec = toc_buffer.addr.msf.second; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
242 cdtoc[i].frame = toc_buffer.addr.msf.frame; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
243 } |
25393 | 244 #elif defined(__APPLE__) || defined(__DARWIN__) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
245 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
246 dk_cd_read_toc_t tochdr; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
247 uint8_t buf[4]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
248 uint8_t buf2[100 * sizeof(CDTOCDescriptor) + sizeof(CDTOC)]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
249 memset(&tochdr, 0, sizeof(tochdr)); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
250 tochdr.bufferLength = sizeof(buf); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
251 tochdr.buffer = &buf; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
252 if (!ioctl(drive, DKIOCCDREADTOC, &tochdr) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
253 && tochdr.bufferLength == sizeof(buf)) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
254 first = buf[2] - 1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
255 last = buf[3]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
256 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
257 if (last >= 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
258 memset(&tochdr, 0, sizeof(tochdr)); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
259 tochdr.bufferLength = sizeof(buf2); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
260 tochdr.buffer = &buf2; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
261 tochdr.format = kCDTOCFormatTOC; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
262 if (ioctl(drive, DKIOCCDREADTOC, &tochdr) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
263 || tochdr.bufferLength < sizeof(CDTOC)) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
264 last = -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
265 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
266 if (last >= 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
267 CDTOC *cdToc = (CDTOC *)buf2; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
268 CDTrackInfo lastTrack; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
269 dk_cd_read_track_info_t trackInfoParams; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
270 for (i = first; i < last; ++i) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
271 CDMSF msf = CDConvertTrackNumberToMSF(i + 1, cdToc); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
272 cdtoc[i].min = msf.minute; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
273 cdtoc[i].sec = msf.second; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
274 cdtoc[i].frame = msf.frame; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
275 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
276 memset(&trackInfoParams, 0, sizeof(trackInfoParams)); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
277 trackInfoParams.addressType = kCDTrackInfoAddressTypeTrackNumber; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
278 trackInfoParams.bufferLength = sizeof(lastTrack); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
279 trackInfoParams.address = last; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
280 trackInfoParams.buffer = &lastTrack; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
281 if (!ioctl(drive, DKIOCCDREADTRACKINFO, &trackInfoParams)) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
282 CDMSF msf = CDConvertLBAToMSF(be2me_32(lastTrack.trackStartAddress) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
283 + be2me_32(lastTrack.trackSize)); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
284 cdtoc[last].min = msf.minute; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
285 cdtoc[last].sec = msf.second; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
286 cdtoc[last].frame = msf.frame; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
287 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
288 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
289 } |
20587 | 290 #endif |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
291 close(drive); |
20581
bfcc98ad59ba
Factor out common code in stream_cddb read_toc function.
reimar
parents:
20579
diff
changeset
|
292 #endif |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
293 for (i = first; i <= last; i++) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
294 cdtoc[i].frame += (cdtoc[i].min * 60 + cdtoc[i].sec) * 75; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
295 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
|
296 } |
6474 | 297 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
298 /** |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
299 \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
|
300 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
|
301 \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
|
302 \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
|
303 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
|
304 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
|
305 */ |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
306 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
|
307 { |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
308 cdtoc_last_track = 0; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
309 if (mp_msg_test(MSGT_IDENTIFY, MSGL_INFO)) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
310 int i, min, sec, frame; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
311 cdtoc_last_track = read_toc(dev); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
312 if (cdtoc_last_track < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
313 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
314 dev); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
315 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
316 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
317 mp_msg(MSGT_GLOBAL, MSGL_INFO, "ID_CDDA_TRACKS=%d\n", cdtoc_last_track); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
318 for (i = 1; i <= cdtoc_last_track; i++) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
319 frame = cdtoc[i].frame - cdtoc[i-1].frame; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
320 sec = frame / 75; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
321 frame -= sec * 75; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
322 min = sec / 60; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
323 sec -= min * 60; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
324 mp_msg(MSGT_IDENTIFY, MSGL_INFO, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
325 "ID_CDDA_TRACK_%d_MSF=%02d:%02d:%02d\n", i, min, sec, frame); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
326 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
327 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
328 return cdtoc_last_track; |
16524
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
329 } |
83d101e1bedb
Prints the number of tracks and MSF length for each track of an audio CD,
gpoirier
parents:
15566
diff
changeset
|
330 |
30693 | 331 static unsigned int cddb_sum(int n) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
332 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
333 unsigned int ret; |
6474 | 334 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
335 ret = 0; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
336 while (n > 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
337 ret += (n % 10); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
338 n /= 10; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
339 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
340 return ret; |
6474 | 341 } |
342 | |
30693 | 343 static unsigned long cddb_discid(int tot_trks) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
344 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
345 unsigned int i, t = 0, n = 0; |
6474 | 346 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
347 i = 0; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
348 while (i < (unsigned int)tot_trks) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
349 n = n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
350 i++; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
351 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
352 t = ((cdtoc[tot_trks].min * 60) + cdtoc[tot_trks].sec) - |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
353 ((cdtoc[0].min * 60) + cdtoc[0].sec); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
354 return (n % 0xff) << 24 | t << 8 | tot_trks; |
6474 | 355 } |
356 | |
357 | |
358 | |
30693 | 359 static int cddb_http_request(char *command, |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
360 int (*reply_parser)(HTTP_header_t*, cddb_data_t*), |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
361 cddb_data_t *cddb_data) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
362 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
363 char request[4096]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
364 int fd, ret = 0; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
365 URL_t *url; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
366 HTTP_header_t *http_hdr; |
6474 | 367 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
368 if (reply_parser == NULL || command == NULL || cddb_data == NULL) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
369 return -1; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
370 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
371 sprintf(request, "http://%s/~cddb/cddb.cgi?cmd=%s%s&proto=%d", |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
372 cddb_data->freedb_server, command, cddb_data->cddb_hello, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
373 cddb_data->freedb_proto_level); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
374 mp_msg(MSGT_OPEN, MSGL_INFO,"Request[%s]\n", request); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
375 |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
376 url = url_new(request); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
377 if (url == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
378 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NotAValidURL); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
379 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
380 } |
6474 | 381 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
382 fd = http_send_request(url,0); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
383 if (fd < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
384 mp_msg(MSGT_DEMUX, MSGL_ERR, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
385 MSGTR_MPDEMUX_CDDB_FailedToSendHTTPRequest); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
386 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
387 } |
6474 | 388 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
389 http_hdr = http_read_response(fd); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
390 if (http_hdr == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
391 mp_msg(MSGT_DEMUX, MSGL_ERR, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
392 MSGTR_MPDEMUX_CDDB_FailedToReadHTTPResponse); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
393 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
394 } |
6474 | 395 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
396 http_debug_hdr(http_hdr); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
397 mp_msg(MSGT_OPEN, MSGL_INFO,"body=[%s]\n", http_hdr->body); |
6474 | 398 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
399 switch (http_hdr->status_code) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
400 case 200: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
401 ret = reply_parser(http_hdr, cddb_data); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
402 break; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
403 case 400: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
404 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_HTTPErrorNOTFOUND); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
405 break; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
406 default: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
407 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_HTTPErrorUnknown); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
408 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
409 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
410 http_free(http_hdr); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
411 url_free(url); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
412 |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
413 return ret; |
6474 | 414 } |
415 | |
30693 | 416 static int cddb_read_cache(cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
417 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
418 char file_name[100]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
419 struct stat stats; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
420 int file_fd, ret; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
421 size_t file_size; |
6474 | 422 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
423 if (cddb_data == NULL || cddb_data->cache_dir == NULL) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
424 return -1; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
425 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
426 sprintf(file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
427 |
30685 | 428 file_fd = open(file_name, O_RDONLY | O_BINARY); |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
429 if (file_fd < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
430 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NoCacheFound); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
431 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
432 } |
6474 | 433 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
434 ret = fstat(file_fd, &stats); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
435 if (ret < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
436 perror("fstat"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
437 file_size = 4096; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
438 } else { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
439 file_size = stats.st_size < UINT_MAX ? stats.st_size : UINT_MAX - 1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
440 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
441 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
442 cddb_data->xmcd_file = malloc(file_size + 1); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
443 if (cddb_data->xmcd_file == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
444 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
445 close(file_fd); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
446 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
447 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
448 cddb_data->xmcd_file_size = read(file_fd, cddb_data->xmcd_file, file_size); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
449 if (cddb_data->xmcd_file_size != file_size) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
450 mp_msg(MSGT_DEMUX, MSGL_WARN, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
451 MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenRead); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
452 close(file_fd); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
453 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
454 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
455 cddb_data->xmcd_file[cddb_data->xmcd_file_size] = 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
456 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
457 close(file_fd); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
458 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
459 return 0; |
6474 | 460 } |
461 | |
30693 | 462 static int cddb_write_cache(cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
463 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
464 // We have the file, save it for cache. |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
465 struct stat file_stat; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
466 char file_name[100]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
467 int file_fd, ret; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
468 int wrote = 0; |
6474 | 469 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
470 if (cddb_data == NULL || cddb_data->cache_dir == NULL) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
471 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
472 |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
473 // Check if the CDDB cache dir exist |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
474 ret = stat(cddb_data->cache_dir, &file_stat); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
475 if (ret < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
476 // Directory not present, create it. |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
477 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
|
478 #ifdef __MINGW32__ |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
479 if (ret < 0 && errno != EEXIST) { |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
480 #else |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
481 if (ret < 0) { |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
482 #endif |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
483 perror("mkdir"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
484 mp_msg(MSGT_DEMUX, MSGL_ERR, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
485 MSGTR_MPDEMUX_CDDB_FailedToCreateDirectory, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
486 cddb_data->cache_dir); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
487 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
488 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
489 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
490 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
491 sprintf(file_name, "%s%08lx", cddb_data->cache_dir, cddb_data->disc_id); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
492 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
493 file_fd = creat(file_name, S_IRUSR | S_IWUSR); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
494 if (file_fd < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
495 perror("create"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
496 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
497 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
498 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
499 wrote = write(file_fd, cddb_data->xmcd_file, cddb_data->xmcd_file_size); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
500 if (wrote < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
501 perror("write"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
502 close(file_fd); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
503 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
504 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
505 if ((unsigned int) wrote != cddb_data->xmcd_file_size) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
506 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenWritten); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
507 close(file_fd); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
508 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
509 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
510 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
511 close(file_fd); |
6474 | 512 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
513 return 0; |
6474 | 514 } |
515 | |
30693 | 516 static int cddb_read_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
517 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
518 unsigned long disc_id; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
519 char category[100]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
520 char *ptr = NULL, *ptr2 = NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
521 int ret, status; |
6474 | 522 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
523 if (http_hdr == NULL || cddb_data == NULL) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
524 return -1; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
525 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
526 ret = sscanf(http_hdr->body, "%d ", &status); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
527 if (ret != 1) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
528 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
529 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
530 } |
6474 | 531 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
532 switch (status) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
533 case 210: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
534 ret = sscanf(http_hdr->body, "%d %99s %08lx", &status, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
535 category, &disc_id); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
536 if (ret != 3) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
537 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
538 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
539 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
540 // Check if it's a xmcd database file |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
541 ptr = strstr(http_hdr->body, "# xmcd"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
542 if (ptr == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
543 mp_msg(MSGT_DEMUX, MSGL_ERR, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
544 MSGTR_MPDEMUX_CDDB_InvalidXMCDDatabaseReturned); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
545 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
546 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
547 ptr = strdup(ptr); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
548 // Ok found the beginning of the file |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
549 // look for the end |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
550 ptr2 = strstr(ptr, "\n.\r\n"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
551 if (!ptr2) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
552 ptr2 = strstr(ptr, "\n.\n"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
553 if (ptr2) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
554 ptr2++; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
555 } else { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
556 mp_msg(MSGT_DEMUX, MSGL_FIXME, "Unable to find '.'\n"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
557 ptr2 = ptr + strlen(ptr); //return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
558 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
559 // Ok found the end |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
560 // do a sanity check |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
561 if (http_hdr->body_size < (unsigned int)(ptr2 - ptr)) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
562 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_UnexpectedFIXME); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
563 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
564 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
565 cddb_data->xmcd_file = ptr; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
566 cddb_data->xmcd_file_size = ptr2 - ptr; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
567 cddb_data->xmcd_file[cddb_data->xmcd_file_size] = '\0'; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
568 return cddb_write_cache(cddb_data); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
569 default: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
570 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
571 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
572 return 0; |
6474 | 573 } |
574 | |
30693 | 575 static int cddb_request_titles(cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
576 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
577 char command[1024]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
578 sprintf(command, "cddb+read+%s+%08lx", |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
579 cddb_data->category, cddb_data->disc_id); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
580 return cddb_http_request(command, cddb_read_parse, cddb_data); |
6474 | 581 } |
582 | |
30693 | 583 static int cddb_parse_matches_list(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
584 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
585 char album_title[100]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
586 char *ptr = NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
587 int ret; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
588 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
589 ptr = strstr(http_hdr->body, "\n"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
590 if (ptr == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
591 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_UnableToFindEOL); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
592 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
593 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
594 ptr++; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
595 // We have a list of exact/inexact matches, so which one do we use? |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
596 // So let's take the first one. |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
597 ret = sscanf(ptr, "%99s %08lx %99s", cddb_data->category, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
598 &(cddb_data->disc_id), album_title); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
599 if (ret != 3) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
600 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
601 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
602 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
603 ptr = strstr(http_hdr->body, album_title); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
604 if (ptr != NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
605 char *ptr2; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
606 int len; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
607 ptr2 = strstr(ptr, "\n"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
608 if (ptr2 == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
609 len = (http_hdr->body_size)-(ptr-(http_hdr->body)); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
610 } else { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
611 len = ptr2-ptr+1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
612 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
613 len = FFMIN(sizeof(album_title) - 1, len); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
614 strncpy(album_title, ptr, len); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
615 album_title[len]='\0'; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
616 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
617 mp_msg(MSGT_DEMUX, MSGL_STATUS, MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
618 album_title); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
619 return 0; |
8746 | 620 } |
621 | |
30693 | 622 static int cddb_query_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
623 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
624 char album_title[100]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
625 char *ptr = NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
626 int ret, status; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
627 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
628 ret = sscanf(http_hdr->body, "%d ", &status); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
629 if (ret != 1) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
630 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
631 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
632 } |
6474 | 633 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
634 switch (status) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
635 case 200: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
636 // Found exact match |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
637 ret = sscanf(http_hdr->body, "%d %99s %08lx %99s", &status, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
638 cddb_data->category, &(cddb_data->disc_id), album_title); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
639 if (ret != 4) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
640 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
641 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
642 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
643 ptr = strstr(http_hdr->body, album_title); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
644 if (ptr != NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
645 char *ptr2; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
646 int len; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
647 ptr2 = strstr(ptr, "\n"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
648 if (ptr2 == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
649 len = (http_hdr->body_size)-(ptr-(http_hdr->body)); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
650 } else { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
651 len = ptr2-ptr+1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
652 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
653 len = FFMIN(sizeof(album_title) - 1, len); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
654 strncpy(album_title, ptr, len); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
655 album_title[len]='\0'; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
656 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
657 mp_msg(MSGT_DEMUX, MSGL_STATUS, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
658 MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle, album_title); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
659 return cddb_request_titles(cddb_data); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
660 case 202: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
661 // No match found |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
662 mp_msg(MSGT_DEMUX, MSGL_WARN, MSGTR_MPDEMUX_CDDB_AlbumNotFound); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
663 break; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
664 case 210: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
665 // Found exact matches, list follows |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
666 cddb_parse_matches_list(http_hdr, cddb_data); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
667 return cddb_request_titles(cddb_data); |
6474 | 668 /* |
669 body=[210 Found exact matches, list follows (until terminating `.') | |
670 misc c711930d Santana / Supernatural | |
671 rock c711930d Santana / Supernatural | |
672 blues c711930d Santana / Supernatural | |
673 .] | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
674 */ |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
675 case 211: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
676 // Found inexact matches, list follows |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
677 cddb_parse_matches_list(http_hdr, cddb_data); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
678 return cddb_request_titles(cddb_data); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
679 case 500: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
680 mp_msg(MSGT_DEMUX, MSGL_FIXME, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
681 MSGTR_MPDEMUX_CDDB_ServerReturnsCommandSyntaxErr); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
682 break; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
683 default: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
684 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
685 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
686 return -1; |
6474 | 687 } |
688 | |
30693 | 689 static int cddb_proto_level_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
690 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
691 int max; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
692 int ret, status; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
693 char *ptr; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
694 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
695 ret = sscanf(http_hdr->body, "%d ", &status); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
696 if (ret != 1) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
697 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
698 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
699 } |
6474 | 700 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
701 switch (status) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
702 case 210: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
703 ptr = strstr(http_hdr->body, "max proto:"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
704 if (ptr == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
705 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
706 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
707 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
708 ret = sscanf(ptr, "max proto: %d", &max); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
709 if (ret != 1) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
710 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
711 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
712 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
713 cddb_data->freedb_proto_level = max; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
714 return 0; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
715 default: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
716 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
717 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
718 return -1; |
6474 | 719 } |
720 | |
30693 | 721 static int cddb_get_proto_level(cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
722 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
723 return cddb_http_request("stat", cddb_proto_level_parse, cddb_data); |
6474 | 724 } |
725 | |
30693 | 726 static int cddb_freedb_sites_parse(HTTP_header_t *http_hdr, cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
727 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
728 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
|
729 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
730 ret = sscanf(http_hdr->body, "%d ", &status); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
731 if (ret != 1) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
732 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_ParseError); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
733 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
734 } |
6474 | 735 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
736 switch (status) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
737 case 210: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
738 // TODO: Parse the sites |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
739 ret = cddb_data->anonymous; // For gcc complaining about unused parameter. |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
740 return 0; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
741 case 401: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
742 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_NoSitesInfoAvailable); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
743 break; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
744 default: |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
745 mp_msg(MSGT_DEMUX, MSGL_FIXME, MSGTR_MPDEMUX_CDDB_UnhandledCode); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
746 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
747 return -1; |
6474 | 748 } |
749 | |
30693 | 750 static int cddb_get_freedb_sites(cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
751 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
752 return cddb_http_request("sites", cddb_freedb_sites_parse, cddb_data); |
6474 | 753 } |
754 | |
30693 | 755 static void cddb_create_hello(cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
756 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
757 char host_name[51]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
758 char *user_name; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
759 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
760 if (cddb_data->anonymous) { // Default is anonymous |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
761 /* Note from Eduardo Pérez Ureta <eperez@it.uc3m.es> : |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
762 * We don't send current user/host name in hello to prevent spam. |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
763 * Software that sends this is considered spyware |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
764 * that most people don't like. |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
765 */ |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
766 user_name = "anonymous"; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
767 strcpy(host_name, "localhost"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
768 } else { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
769 if (gethostname(host_name, 50) < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
770 strcpy(host_name, "localhost"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
771 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
772 user_name = getenv("LOGNAME"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
773 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
774 sprintf(cddb_data->cddb_hello, "&hello=%s+%s+%s+%s", |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
775 user_name, host_name, "MPlayer", VERSION); |
6474 | 776 } |
777 | |
30693 | 778 static int cddb_retrieve(cddb_data_t *cddb_data) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
779 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
780 char offsets[1024], command[1024]; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
781 char *ptr; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
782 unsigned int i, time_len; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
783 int ret; |
6474 | 784 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
785 ptr = offsets; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
786 for (i = 0; i < cddb_data->tracks ; i++) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
787 ptr += sprintf(ptr, "%d+", cdtoc[i].frame); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
788 if (ptr-offsets > sizeof offsets - 40) break; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
789 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
790 ptr[0] = 0; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
791 time_len = (cdtoc[cddb_data->tracks].frame)/75; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
792 |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
793 cddb_data->freedb_server = DEFAULT_FREEDB_SERVER; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
794 cddb_data->freedb_proto_level = 1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
795 cddb_data->xmcd_file = NULL; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
796 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
797 cddb_create_hello(cddb_data); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
798 if (cddb_get_proto_level(cddb_data) < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
799 mp_msg(MSGT_DEMUX, MSGL_ERR, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
800 MSGTR_MPDEMUX_CDDB_FailedToGetProtocolLevel); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
801 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
802 } |
6474 | 803 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
804 //cddb_get_freedb_sites(&cddb_data); |
6474 | 805 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
806 sprintf(command, "cddb+query+%08lx+%d+%s%d", cddb_data->disc_id, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
807 cddb_data->tracks, offsets, time_len); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
808 ret = cddb_http_request(command, cddb_query_parse, cddb_data); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
809 if (ret < 0) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
810 return -1; |
6474 | 811 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
812 if (cddb_data->cache_dir != NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
813 free(cddb_data->cache_dir); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
814 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
815 return 0; |
6474 | 816 } |
817 | |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
818 int cddb_resolve(const char *dev, char **xmcd_file) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
819 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
820 char cddb_cache_dir[] = DEFAULT_CACHE_DIR; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
821 char *home_dir = NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
822 cddb_data_t cddb_data; |
6474 | 823 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
824 if (cdtoc_last_track <= 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
825 cdtoc_last_track = read_toc(dev); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
826 if (cdtoc_last_track < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
827 mp_msg(MSGT_OPEN, MSGL_ERR, MSGTR_MPDEMUX_CDDB_FailedToOpenDevice, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
828 dev); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
829 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
830 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
831 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
832 cddb_data.tracks = cdtoc_last_track; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
833 cddb_data.disc_id = cddb_discid(cddb_data.tracks); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
834 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
|
835 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
836 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDB_DISCID=%08lx\n", |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
837 cddb_data.disc_id); |
27174 | 838 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
839 // Check if there is a CD in the drive |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
840 // FIXME: That's not really a good way to check |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
841 if (cddb_data.disc_id == 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
842 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MPDEMUX_CDDB_NoCDInDrive); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
843 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
844 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
845 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
846 home_dir = getenv("HOME"); |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
847 #ifdef __MINGW32__ |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
848 if (home_dir == NULL) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
849 home_dir = getenv("USERPROFILE"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
850 if (home_dir == NULL) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
851 home_dir = getenv("HOMEPATH"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
852 // Last resort, store the cddb cache in the mplayer directory |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
853 if (home_dir == NULL) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
854 home_dir = (char *)get_path(""); |
16935
60bd6aeed405
make it optionally possible to compile MPlayer with libcdio instead of libcdparanoia
faust3
parents:
16524
diff
changeset
|
855 #endif |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
856 if (home_dir == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
857 cddb_data.cache_dir = NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
858 } else { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
859 cddb_data.cache_dir = malloc(strlen(home_dir) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
860 + strlen(cddb_cache_dir) + 1); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
861 if (cddb_data.cache_dir == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
862 mp_msg(MSGT_DEMUX, MSGL_ERR, MSGTR_MemAllocFailed); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
863 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
864 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
865 sprintf(cddb_data.cache_dir, "%s%s", home_dir, cddb_cache_dir); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
866 } |
6474 | 867 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
868 // Check for a cached file |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
869 if (cddb_read_cache(&cddb_data) < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
870 // No Cache found |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
871 if (cddb_retrieve(&cddb_data) < 0) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
872 return -1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
873 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
874 } |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
875 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
876 if (cddb_data.xmcd_file != NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
877 // printf("%s\n", cddb_data.xmcd_file); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
878 *xmcd_file = cddb_data.xmcd_file; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
879 return 0; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
880 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
881 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
882 return -1; |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
883 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
884 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
885 /*************** |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
886 * xmcd parser * |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
887 ***************/ |
30693 | 888 static char *xmcd_parse_dtitle(cd_info_t *cd_info, char *line) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
889 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
890 char *ptr, *album; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
891 ptr = strstr(line, "DTITLE="); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
892 if (ptr != NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
893 ptr += 7; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
894 album = strstr(ptr, "/"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
895 if (album == NULL) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
896 return NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
897 cd_info->album = malloc(strlen(album + 2) + 1); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
898 if (cd_info->album == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
899 return NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
900 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
901 strcpy(cd_info->album, album + 2); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
902 album--; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
903 album[0] = '\0'; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
904 cd_info->artist = malloc(strlen(ptr) + 1); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
905 if (cd_info->artist == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
906 return NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
907 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
908 strcpy(cd_info->artist, ptr); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
909 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
910 return ptr; |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
911 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
912 |
30693 | 913 static char *xmcd_parse_dgenre(cd_info_t *cd_info, char *line) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
914 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
915 char *ptr; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
916 ptr = strstr(line, "DGENRE="); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
917 if (ptr != NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
918 ptr += 7; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
919 cd_info->genre = malloc(strlen(ptr)+1); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
920 if (cd_info->genre == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
921 return NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
922 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
923 strcpy(cd_info->genre, ptr); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
924 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
925 return ptr; |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
926 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
927 |
30693 | 928 static char *xmcd_parse_ttitle(cd_info_t *cd_info, char *line) |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
929 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
930 unsigned int track_nb; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
931 unsigned long sec, off; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
932 char *ptr; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
933 ptr = strstr(line, "TTITLE"); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
934 if (ptr != NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
935 ptr += 6; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
936 // Here we point to the track number |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
937 track_nb = atoi(ptr); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
938 ptr = strstr(ptr, "="); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
939 if (ptr == NULL) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
940 return NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
941 ptr++; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
942 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
943 sec = cdtoc[track_nb].frame; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
944 off = cdtoc[track_nb + 1].frame - sec + 1; |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
945 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
946 cd_info_add_track(cd_info, ptr, track_nb + 1, |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
947 (unsigned int) (off / (60 * 75)), |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
948 (unsigned int) ((off / 75) % 60), |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
949 (unsigned int) (off % 75), |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
950 sec, off); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
951 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
952 return ptr; |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
953 } |
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
954 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
955 cd_info_t *cddb_parse_xmcd(char *xmcd_file) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
956 { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
957 cd_info_t *cd_info = NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
958 int length, pos = 0; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
959 char *ptr, *ptr2; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
960 unsigned int audiolen; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
961 if (xmcd_file == NULL) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
962 return NULL; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
963 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
964 cd_info = cd_info_new(); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
965 if (cd_info == NULL) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
966 return NULL; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
967 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
968 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
969 length = strlen(xmcd_file); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
970 ptr = xmcd_file; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
971 while (ptr != NULL && pos < length) { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
972 // Read a line |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
973 ptr2 = ptr; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
974 while(ptr2[0] != '\0' && ptr2[0] != '\r' && ptr2[0] != '\n') |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
975 ptr2++; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
976 if (ptr2[0] == '\0') { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
977 break; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
978 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
979 ptr2[0] = '\0'; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
980 // Ignore comments |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
981 if (ptr[0] != '#') { |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
982 // Search for the album title |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
983 if (xmcd_parse_dtitle(cd_info, ptr)) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
984 ; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
985 // Search for the genre |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
986 else if (xmcd_parse_dgenre(cd_info, ptr)) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
987 ; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
988 // Search for a track title |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
989 else if (xmcd_parse_ttitle(cd_info, ptr)) |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
990 audiolen++; // <-- audiolen++ to shut up gcc warning |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
991 } |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
992 if (ptr2[1] == '\n') |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
993 ptr2++; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
994 pos = (ptr2 + 1) - ptr; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
995 ptr = ptr2 + 1; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
996 } |
6697
4cade272ce2b
Added a simple xmcd parser to retreive the tracks name.
bertrand
parents:
6475
diff
changeset
|
997 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
998 audiolen = cdtoc[cd_info->nb_tracks].frame-cdtoc[0].frame; |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
999 cd_info->min = (unsigned int) (audiolen / (60 * 75)); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
1000 cd_info->sec = (unsigned int) ((audiolen / 75) % 60); |
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
1001 cd_info->msec = (unsigned int) (audiolen % 75); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
1002 |
30629
16d7ef2f04e5
cosmetics: K&R coding style, indent with 4 spaces, no tabs
diego
parents:
30613
diff
changeset
|
1003 return cd_info; |
6474 | 1004 } |