1 Index: libcdio-0.80/src/cdtextinfo.c
2 ===================================================================
3 --- libcdio-0.80/src/cdtextinfo.c
4 +++ libcdio-0.80/src/cdtextinfo.c
7 + This program is free software; you can redistribute it and/or modify
8 + it under the terms of the GNU General Public License as published by
9 + the Free Software Foundation; either version 2 of the License, or
10 + (at your option) any later version.
12 + This program is distributed in the hope that it will be useful,
13 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 + GNU General Public License for more details.
17 + You should have received a copy of the GNU General Public License
18 + along with this program; if not, write to the Free Software
19 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 + cdtextinfo, 2008-07-25 by fraxinas <andreas.frisch@multimedia-labs.de>
28 +#include <cddb/cddb.h>
29 +#include <cdio/cdio.h>
30 +#include <cdio/cdtext.h>
43 +/* Configuration option codes */
55 + /* These are the remaining configuration options */
60 +static bool parse_options (int argc, char *argv[])
62 + int opt; /* used for argument parsing */
64 + const char* helpText =
65 + "Usage: %s [OPTION...]\n"
66 + " -a, --album Print audio CD album info\n"
67 + " -l, --listing Print title info for all tracks\n"
68 + " -T, --cdtext Use CD-Text\n"
69 + " -D, --cddb Use CDDB\n"
70 + " -x, --xml XML output\n"
73 + " -P, --cddb-port=INT CDDB port number to use (default 8880)\n"
74 + " --cddb-server=STRING CDDB server to contact for information\n"
75 + " (default: freedb.freedb.org)\n"
76 + " --cddb-cache=STRING Location of CDDB cache directory\n"
77 + " (default ~/.cddbclient)\n"
78 + " --cddb-email=STRING Email address to give CDDB server\n"
79 + " (default me@dreambox)\n"
80 + " --no-cddb-cache Disable caching of CDDB entries\n"
81 + " locally (default caches)\n"
82 + " --cddb-timeout=INT CDDB timeout value in seconds\n"
83 + " (default 10 seconds)\n"
86 + " -?, --help Show this help message\n"
87 + " --usage Display brief usage message\n"
89 + "Example: %s -xalDT\n"
90 + " Will query album info and track listing from both CD-Text and CDDB and display as XML\n";
92 + const char* usageText =
93 + "Usage: %s [-a|--album] [-l|--listing]\n"
94 + " [-T|--cdtext] [-D|--cddb] [-x|--xml]\n"
95 + " [-P|--cddb-port INT] [--cddb-server=STRING]\n"
96 + " [--cddb-cache=STRING] [--cddb-email=STRING]\n"
97 + " [--no-cddb-cache] [--cddb-timeout=INT]\n"
98 + " [-?|--help] [--usage]\n";
100 + const char* optionsString = "alTDP:x?";
101 + struct option optionsTable[] = {
102 + {"album", no_argument, NULL, 'a' },
103 + {"listing", no_argument, NULL, 'l' },
104 + {"cdtext", no_argument, NULL, 'T' },
105 + {"cddb", no_argument, NULL, 'D' },
106 + {"cddb-port", required_argument, NULL, 'P' },
107 + {"cddb-server", required_argument, NULL, OP_CDDB_SERVER },
108 + {"cddb-cache", required_argument, NULL, OP_CDDB_CACHE },
109 + {"cddb-email", required_argument, NULL, OP_CDDB_EMAIL },
110 + {"no-cddb-cache", no_argument, NULL, OP_CDDB_NOCACHE },
111 + {"cddb-timeout", required_argument, NULL, OP_CDDB_TIMEOUT },
112 + {"help", no_argument, NULL, '?' },
113 + {"usage", no_argument, NULL, OP_USAGE },
114 + { NULL, 0, NULL, 0 }
117 + while ((opt = getopt_long(argc, argv, optionsString, optionsTable, NULL)) >= 0) {
119 + case 'a': options.album = true; break;
120 + case 'l': options.listing = true; break;
121 + case 'T': options.cdtext = true; break;
122 + case 'D': options.cddb = true; break;
123 + case 'x': options.xml = true; break;
124 + case 'P': cddb_opts.port = atoi(optarg); break;
125 + case OP_CDDB_SERVER: cddb_opts.server = strdup(optarg); break;
126 + case OP_CDDB_CACHE: cddb_opts.cachedir = strdup(optarg); break;
127 + case OP_CDDB_EMAIL: cddb_opts.email = strdup(optarg); break;
128 + case OP_CDDB_NOCACHE: cddb_opts.disable_cache = 1; break;
129 + case OP_CDDB_TIMEOUT: cddb_opts.timeout = atoi(optarg); break;
131 + fprintf(stdout, helpText, argv[0], argv[0]);
135 + fprintf(stderr, usageText, argv[0]);
145 +static void cddb_errmsg(const char *msg)
148 + printf("<error msg=\"%s\" />\n", msg);
150 + printf("%s\n", msg);
153 +int print_cddb_info(CdIo_t *p_cdio, track_t i_tracks, track_t i_first_track)
155 + int i_cddb_matches = 0, i_cddb_currentmatch = 1;
157 + cddb_conn_t *p_conn = NULL;
158 + cddb_disc_t *p_cddb_disc = NULL;
160 + if ( init_cddb(p_cdio, &p_conn, &p_cddb_disc, cddb_errmsg, i_first_track, i_tracks, &i_cddb_matches) )
162 + while ( i_cddb_currentmatch <= i_cddb_matches )
164 + cddb_read(p_conn, p_cddb_disc);
167 + printf("\t<query source=\"CDDB\" match=\"%i\" num_matches=\"%i\">\n",i_cddb_currentmatch,i_cddb_matches);
172 + printf("\t\t<albuminfo>\n");
174 + if ( cddb_disc_get_title(p_cddb_disc) )
177 + printf("\t\t\t\t<title>%s</title>\n",cddb_disc_get_title(p_cddb_disc));
179 + printf("TITLE:%s\n",cddb_disc_get_title(p_cddb_disc));
181 + if ( cddb_disc_get_artist(p_cddb_disc) )
184 + printf("\t\t\t\t<artist>%s</artist>\n",cddb_disc_get_artist(p_cddb_disc));
186 + printf("ARTIST:%s\n",cddb_disc_get_artist(p_cddb_disc));
188 + if ( cddb_disc_get_genre(p_cddb_disc) )
191 + printf("\t\t\t\t<genre>%s</genre>\n",cddb_disc_get_genre(p_cddb_disc));
193 + printf("GENRE:%s\n",cddb_disc_get_genre(p_cddb_disc));
195 + if ( cddb_disc_get_category_str(p_cddb_disc) )
198 + printf("\t\t\t\t<category>%s</category>\n",cddb_disc_get_category_str(p_cddb_disc));
200 + printf("CATEGORY:%s\n",cddb_disc_get_category_str(p_cddb_disc));
202 + if ( cddb_disc_get_year(p_cddb_disc) )
205 + printf("\t\t\t\t<year>%i</year>\n",cddb_disc_get_year(p_cddb_disc));
207 + printf("YEAR:%i\n",cddb_disc_get_year(p_cddb_disc));
209 + if ( cddb_disc_get_ext_data(p_cddb_disc) )
212 + printf("\t\t\t\t<extra_data>%s</extra_data>\n",cddb_disc_get_ext_data(p_cddb_disc));
214 + printf("EXTDATA:%s\n",cddb_disc_get_ext_data(p_cddb_disc));
217 + printf("\t\t</albuminfo>\n");
219 + if (options.listing)
222 + printf("\t\t<tracklisting>\n");
224 + cddb_track_t *p_cddb_track = cddb_disc_get_track_first(p_cddb_disc);
225 + while ( p_cddb_track != NULL )
229 + printf("\t\t\t\t<track number=\"%i\">\n",cddb_track_get_number(p_cddb_track));
230 + if (cddb_track_get_length(p_cddb_track))
231 + printf("\t\t\t\t\t\t<length>%i</length>\n",cddb_track_get_length(p_cddb_track));
232 + if (cddb_track_get_title(p_cddb_track))
233 + printf("\t\t\t\t\t\t<title>%s</title>\n",cddb_track_get_title(p_cddb_track));
234 + if (cddb_track_get_artist(p_cddb_track))
235 + printf("\t\t\t\t\t\t<artist>%s</artist>\n",cddb_track_get_artist(p_cddb_track));
236 + if (cddb_track_get_ext_data(p_cddb_track))
237 + printf("\t\t\t\t\t\t<extra_data>%s</extra_data>\n",cddb_track_get_ext_data(p_cddb_track));
238 + printf("\t\t\t\t</track>\n");
241 + printf("%i:%s\n",cddb_track_get_number(p_cddb_track),cddb_track_get_title(p_cddb_track));
243 + p_cddb_track = cddb_disc_get_track_next(p_cddb_disc);
247 + printf("\t\t</tracklisting>\n");
250 + printf("\t</query>\n");
252 + cddb_query_next(p_conn, p_cddb_disc);
253 + i_cddb_currentmatch++;
255 + if ( i_cddb_currentmatch < 1 && options.xml )
256 + printf("\t<query source=\"CDDB\" num_matches=\"%i\" />\n",i_cddb_matches);
258 + cddb_disc_destroy(p_cddb_disc);
259 + cddb_destroy(p_conn);
260 + libcddb_shutdown();
264 +int print_cdtext_info(CdIo_t *p_cdio, track_t i_tracks, track_t i_track)
266 + const cdtext_t *cdtext = cdio_get_cdtext(p_cdio, 0);
268 + if ( cdtext == NULL || cdtext && !cdtext->field[9] )
271 + printf("\t<query source=\"CD-TEXT\" num_matches=\"0\" />\n");
276 + printf("\t<query source=\"CD-TEXT\" match=\"1\" num_matches=\"1\">\n");
278 + if ( options.album )
281 + printf("\t\t<albuminfo>\n");
283 + for (i=0; i < MAX_CDTEXT_FIELDS; i++)
285 + if (cdtext->field[i])
288 + printf("\t\t\t\t<%s>%s</%s>\n",cdtext_field2str(i),cdtext->field[i],cdtext_field2str(i));
290 + printf("%s:%s\n", cdtext_field2str(i), cdtext->field[i]);
294 + printf("\t\t</albuminfo>\n");
297 + if ( options.listing )
300 + printf("\t\t<tracklisting>\n");
302 + for ( ; i_track < i_tracks; i_track++ )
304 + const cdtext_t *cdtext = cdio_get_cdtext(p_cdio, i_track);
310 + printf("\t\t\t\t<track number=\"%i\">\n",i_track);
313 + for (i=0; i < MAX_CDTEXT_FIELDS; i++)
315 + if (cdtext->field[i])
318 + printf("\t\t\t\t\t\t<%s>%s</%s>\n",cdtext_field2str(i),cdtext->field[i],cdtext_field2str(i));
321 + printf("\t\t\t\t</track>\n");
324 + else if (cdtext->field[9])
325 + printf("%d:%s\n", i_track, cdtext->field[9]);
329 + printf("\t\t</tracklisting>\n");
333 + printf("\t</query>\n");
338 +int main(int argc, char *argv[])
340 + cddb_opts.port = 8880;
341 + cddb_opts.server = NULL;
342 + cddb_opts.timeout = 10;
343 + cddb_opts.disable_cache = false;
344 + cddb_opts.cachedir = NULL;
345 + cddb_opts.email = strdup("me@dreambox");
347 + parse_options(argc, argv);
351 + CdIo_t *p_cdio = cdio_open (NULL, DRIVER_DEVICE);
352 + i_tracks = cdio_get_num_tracks(p_cdio);
356 + printf("<?xml version=\"1.0\" ?>\n");
357 + printf("<cdinfo>\n");
360 + if (NULL == p_cdio)
363 + i_track = cdio_get_first_track_num(p_cdio);
364 + if ( options.cdtext )
365 + print_cdtext_info(p_cdio, i_tracks, i_track);
367 + i_track = cdio_get_first_track_num(p_cdio);
368 + if ( options.cddb )
369 + print_cddb_info(p_cdio, i_tracks, i_track);
371 + cdio_destroy(p_cdio);
374 + printf("</cdinfo>\n");
378 Index: libcdio-0.80/src/Makefile.am
379 ===================================================================
380 --- libcdio-0.80/src/Makefile.am
381 +++ libcdio-0.80/src/Makefile.am 2008-07-29 09:56:06.000000000 +0000
383 #mmc_tool_LDADD = $(LIBISO9660_LIBS) $(LIBCDIO_LIBS) $(LIBICONV)
384 #bin_mmc_tool = mmc-tool
386 -bin_PROGRAMS = $(bin_cd_drive) $(bin_cd_info) $(bin_cdinfo_linux) $(bin_cd_read) $(bin_iso_info) $(bin_iso_read) $(bin_cdda_player) $(bin_mmc_tool)
387 +bin_cdtextinfo = cdtextinfo
388 +cdtextinfo_SOURCES = cdtextinfo.c cddb.c cddb.h $(GETOPT_C)
389 +cdtextinfo_LDADD = $(LIBCDIO_LIBS) $(LIBICONV) $(CDDB_LIBS)
390 +cdtextinfo_DEPENDENCIES = $(LIBCDIO_DEPS)
392 +bin_PROGRAMS = $(bin_cd_drive) $(bin_cd_info) $(bin_cdinfo_linux) $(bin_cd_read) $(bin_iso_info) $(bin_iso_read) $(bin_cdda_player) $(bin_mmc_tool) $(bin_cdtextinfo)
394 INCLUDES = -I$(top_srcdir) $(LIBCDIO_CFLAGS) $(VCDINFO_CFLAGS) $(CDDB_CFLAGS)