Towards making a common init_cddb routine.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
$Id: cd-info.c,v 1.132 2005/03/06 11:21:52 rocky Exp $
|
||||
$Id: cd-info.c,v 1.133 2005/03/11 10:34:28 rocky Exp $
|
||||
|
||||
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
|
||||
Copyright (C) 1996, 1997, 1998 Gerd Knorr <kraxel@bytesex.org>
|
||||
@@ -22,7 +22,6 @@
|
||||
/*
|
||||
CD Info - prints various information about a CD, and detects the type of
|
||||
the CD.
|
||||
|
||||
*/
|
||||
|
||||
#include "util.h"
|
||||
@@ -71,20 +70,13 @@ struct cdrom_subchnl sub;
|
||||
|
||||
/* Used by `main' to communicate with `parse_opt'. And global options
|
||||
*/
|
||||
struct arguments
|
||||
struct opts_s
|
||||
{
|
||||
int no_tracks;
|
||||
int no_ioctl;
|
||||
int no_analysis;
|
||||
char *access_mode; /* Access method driver should use for control */
|
||||
int no_cddb; /* If set the below are meaningless. */
|
||||
char *cddb_email; /* email to report to CDDB server. */
|
||||
char *cddb_server; /* CDDB server to contact */
|
||||
int cddb_port; /* port number to contact CDDB server. */
|
||||
int cddb_http; /* 1 if use http proxy */
|
||||
int cddb_timeout;
|
||||
bool cddb_disable_cache; /* If set the below is meaningless. */
|
||||
char *cddb_cachedir;
|
||||
int no_vcd;
|
||||
int show_dvd;
|
||||
int no_device;
|
||||
@@ -119,7 +111,6 @@ enum {
|
||||
|
||||
char *temp_str;
|
||||
|
||||
|
||||
/* Parse a all options. */
|
||||
static bool
|
||||
parse_options (int argc, const char *argv[])
|
||||
@@ -144,49 +135,49 @@ parse_options (int argc, const char *argv[])
|
||||
{"no-cddb", '\0', POPT_ARG_NONE, &opts.no_cddb, 0,
|
||||
"Don't look up audio CDDB information or print that"},
|
||||
|
||||
{"cddb-port", 'P', POPT_ARG_INT, &opts.cddb_port, 8880,
|
||||
{"cddb-port", 'P', POPT_ARG_INT, &cddb_opts.port, 8880,
|
||||
"CDDB port number to use (default 8880)"},
|
||||
|
||||
{"cddb-http", 'H', POPT_ARG_NONE, &opts.cddb_http, 0,
|
||||
{"cddb-http", 'H', POPT_ARG_NONE, &cddb_opts.http, 0,
|
||||
"Lookup CDDB via HTTP proxy (default no proxy)"},
|
||||
|
||||
{"cddb-server", '\0', POPT_ARG_STRING, &opts.cddb_server, 0,
|
||||
{"cddb-server", '\0', POPT_ARG_STRING, &cddb_opts.server, 0,
|
||||
"CDDB server to contact for information (default: freedb.freedb.org)"},
|
||||
|
||||
{"cddb-cache", '\0', POPT_ARG_STRING, &opts.cddb_cachedir, 0,
|
||||
{"cddb-cache", '\0', POPT_ARG_STRING, &cddb_opts.cachedir, 0,
|
||||
"Location of CDDB cache directory (default ~/.cddbclient)"},
|
||||
|
||||
{"cddb-email", '\0', POPT_ARG_STRING, &opts.cddb_email, 0,
|
||||
{"cddb-email", '\0', POPT_ARG_STRING, &cddb_opts.email, 0,
|
||||
"Email address to give CDDB server (default me@home"},
|
||||
|
||||
{"no-cddb-cache", '\0', POPT_ARG_NONE, &opts.cddb_disable_cache, 0,
|
||||
{"no-cddb-cache", '\0', POPT_ARG_NONE, &cddb_opts.disable_cache, 0,
|
||||
"Lookup CDDB via HTTP proxy (default no proxy)"},
|
||||
|
||||
{"cddb-timeout", '\0', POPT_ARG_INT, &opts.cddb_timeout, 0,
|
||||
{"cddb-timeout", '\0', POPT_ARG_INT, &cddb_opts.timeout, 0,
|
||||
"CDDB timeout value in seconds (default 10 seconds)"},
|
||||
#else
|
||||
{"no-cddb", '\0', POPT_ARG_NONE, &opts.no_cddb, 0,
|
||||
"Does nothing since this program is not CDDB-enabled"},
|
||||
|
||||
{"cddb-port", 'P', POPT_ARG_INT, &opts.cddb_port, 8880,
|
||||
{"cddb-port", 'P', POPT_ARG_INT, &cddb_opts.port, 8880,
|
||||
"Does nothing since this program is not CDDB-enabled"},
|
||||
|
||||
{"cddb-http", 'H', POPT_ARG_NONE, &opts.cddb_http, 0,
|
||||
{"cddb-http", 'H', POPT_ARG_NONE, &cddb_opts.http, 0,
|
||||
"Does nothing since this program is not CDDB-enabled"},
|
||||
|
||||
{"cddb-server", '\0', POPT_ARG_STRING, &opts.cddb_server, 0,
|
||||
{"cddb-server", '\0', POPT_ARG_STRING, &cddb_opts.server, 0,
|
||||
"Does nothing since this program is not CDDB-enabled"},
|
||||
|
||||
{"cddb-cache", '\0', POPT_ARG_STRING, &opts.cddb_cachedir, 0,
|
||||
{"cddb-cache", '\0', POPT_ARG_STRING, &cddb_opts.cachedir, 0,
|
||||
"Does nothing since this program is not CDDB-enabled"},
|
||||
|
||||
{"cddb-email", '\0', POPT_ARG_STRING, &opts.cddb_email, 0,
|
||||
{"cddb-email", '\0', POPT_ARG_STRING, &cddb_opts.email, 0,
|
||||
"Does nothing since this program is not CDDB-enabled"},
|
||||
|
||||
{"no-cddb-cache", '\0', POPT_ARG_NONE, &opts.cddb_disable_cache, 0,
|
||||
{"no-cddb-cache", '\0', POPT_ARG_NONE, &cddb_opts.disable_cache, 0,
|
||||
"Does nothing since this program is not CDDB-enabled"},
|
||||
|
||||
{"cddb-timeout", '\0', POPT_ARG_INT, &opts.cddb_timeout, 0,
|
||||
{"cddb-timeout", '\0', POPT_ARG_INT, &cddb_opts.timeout, 0,
|
||||
"Does nothing since this program is not CDDB-enabled"},
|
||||
#endif
|
||||
|
||||
@@ -410,39 +401,39 @@ static void
|
||||
print_cddb_info(CdIo_t *p_cdio, track_t i_tracks, track_t i_first_track) {
|
||||
int i, matches;
|
||||
|
||||
cddb_conn_t *conn = cddb_new();
|
||||
cddb_conn_t *p_conn = cddb_new();
|
||||
cddb_disc_t *disc = NULL;
|
||||
|
||||
if (!conn) {
|
||||
if (!p_conn) {
|
||||
report(stderr, "%s: unable to initialize libcddb\n", program_name);
|
||||
goto cddb_destroy;
|
||||
}
|
||||
|
||||
if (NULL == opts.cddb_email)
|
||||
cddb_set_email_address(conn, "me@home");
|
||||
if (NULL == cddb_opts.email)
|
||||
cddb_set_email_address(p_conn, "me@home");
|
||||
else
|
||||
cddb_set_email_address(conn, opts.cddb_email);
|
||||
cddb_set_email_address(p_conn, cddb_opts.email);
|
||||
|
||||
if (NULL == opts.cddb_server)
|
||||
cddb_set_server_name(conn, "freedb.freedb.org");
|
||||
if (NULL == cddb_opts.server)
|
||||
cddb_set_server_name(p_conn, "freedb.freedb.org");
|
||||
else
|
||||
cddb_set_server_name(conn, opts.cddb_server);
|
||||
cddb_set_server_name(p_conn, cddb_opts.server);
|
||||
|
||||
if (opts.cddb_timeout >= 0)
|
||||
cddb_set_timeout(conn, opts.cddb_timeout);
|
||||
if (cddb_opts.timeout >= 0)
|
||||
cddb_set_timeout(p_conn, cddb_opts.timeout);
|
||||
|
||||
cddb_set_server_port(conn, opts.cddb_port);
|
||||
cddb_set_server_port(p_conn, cddb_opts.port);
|
||||
|
||||
if (opts.cddb_http)
|
||||
cddb_http_enable(conn);
|
||||
if (cddb_opts.http)
|
||||
cddb_http_enable(p_conn);
|
||||
else
|
||||
cddb_http_disable(conn);
|
||||
cddb_http_disable(p_conn);
|
||||
|
||||
if (NULL != opts.cddb_cachedir)
|
||||
cddb_cache_set_dir(conn, opts.cddb_cachedir);
|
||||
if (NULL != cddb_opts.cachedir)
|
||||
cddb_cache_set_dir(p_conn, cddb_opts.cachedir);
|
||||
|
||||
if (opts.cddb_disable_cache)
|
||||
cddb_cache_disable(conn);
|
||||
if (cddb_opts.disable_cache)
|
||||
cddb_cache_disable(p_conn);
|
||||
|
||||
disc = cddb_disc_new();
|
||||
if (!disc) {
|
||||
@@ -465,22 +456,22 @@ print_cddb_info(CdIo_t *p_cdio, track_t i_tracks, track_t i_first_track) {
|
||||
goto cddb_destroy;
|
||||
}
|
||||
|
||||
matches = cddb_query(conn, disc);
|
||||
matches = cddb_query(p_conn, disc);
|
||||
|
||||
if (-1 == matches)
|
||||
printf("%s: %s\n", program_name, cddb_error_str(cddb_errno(conn)));
|
||||
printf("%s: %s\n", program_name, cddb_error_str(cddb_errno(p_conn)));
|
||||
else {
|
||||
printf("%s: Found %d matches in CDDB\n", program_name, matches);
|
||||
for (i=1; i<=matches; i++) {
|
||||
cddb_read(conn, disc);
|
||||
cddb_read(p_conn, disc);
|
||||
cddb_disc_print(disc);
|
||||
cddb_query_next(conn, disc);
|
||||
cddb_query_next(p_conn, disc);
|
||||
}
|
||||
}
|
||||
|
||||
cddb_disc_destroy(disc);
|
||||
cddb_destroy:
|
||||
cddb_destroy(conn);
|
||||
cddb_destroy(p_conn);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -781,12 +772,12 @@ init(void)
|
||||
opts.print_iso9660 = 0;
|
||||
#ifdef HAVE_CDDB
|
||||
opts.no_cddb = 0;
|
||||
opts.cddb_port = 8880;
|
||||
opts.cddb_http = 0;
|
||||
opts.cddb_cachedir = NULL;
|
||||
opts.cddb_server = NULL;
|
||||
opts.cddb_timeout = -1;
|
||||
opts.cddb_disable_cache = false;
|
||||
cddb_opts.port = 8880;
|
||||
cddb_opts.http = 0;
|
||||
cddb_opts.cachedir = NULL;
|
||||
cddb_opts.server = NULL;
|
||||
cddb_opts.timeout = -1;
|
||||
cddb_opts.disable_cache = false;
|
||||
#endif
|
||||
#ifdef HAVE_VCDINFO
|
||||
opts.no_vcd = 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
$Id: cdda-player.c,v 1.3 2005/03/09 02:19:54 rocky Exp $
|
||||
$Id: cdda-player.c,v 1.4 2005/03/11 10:34:28 rocky Exp $
|
||||
|
||||
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
|
||||
|
||||
@@ -69,10 +69,8 @@
|
||||
static void play_track(track_t t1, track_t t2);
|
||||
static void display_cdinfo(CdIo_t *p_cdio, track_t i_tracks,
|
||||
track_t i_first_track);
|
||||
static bool init_cddb(CdIo_t *p_cdio, track_t i_tracks);
|
||||
static void get_cddb_track_info(track_t i_track);
|
||||
|
||||
|
||||
CdIo_t *p_cdio; /* libcdio handle */
|
||||
driver_id_t driver_id = DRIVER_DEVICE;
|
||||
int b_sig = false; /* set on some signals */
|
||||
@@ -116,17 +114,6 @@ typedef enum {
|
||||
char *psz_device=NULL;
|
||||
char *psz_program;
|
||||
|
||||
struct opts_s
|
||||
{
|
||||
char *cddb_email; /* email to report to CDDB server. */
|
||||
char *cddb_server; /* CDDB server to contact */
|
||||
int cddb_port; /* port number to contact CDDB server. */
|
||||
int cddb_http; /* 1 if use http proxy */
|
||||
int cddb_timeout;
|
||||
bool cddb_disable_cache; /* If set the below is meaningless. */
|
||||
char *cddb_cachedir;
|
||||
} opts;
|
||||
|
||||
/* Info about songs and titles. The 0 entry will contain the disc info.
|
||||
*/
|
||||
typedef struct
|
||||
@@ -134,6 +121,7 @@ typedef struct
|
||||
char title[80];
|
||||
char artist[80];
|
||||
char ext_data[80];
|
||||
bool b_cdtext; /* true if from CD-Text, false if from CDDB */
|
||||
} cd_track_info_rec_t;
|
||||
|
||||
cd_track_info_rec_t cd_info[CDIO_CD_MAX_TRACKS+2];
|
||||
@@ -144,7 +132,14 @@ char genre[40];
|
||||
char category[40];
|
||||
char year[5];
|
||||
|
||||
bool b_cdtext_title; /* true if from CD-Text, false if from CDDB */
|
||||
bool b_cdtext_artist; /* true if from CD-Text, false if from CDDB */
|
||||
bool b_cdtext_genre; /* true if from CD-Text, false if from CDDB */
|
||||
bool b_cdtext_category; /* true if from CD-Text, false if from CDDB */
|
||||
|
||||
#ifdef HAVE_CDDB
|
||||
static bool init_cddb(CdIo_t *p_cdio, cddb_conn_t *p_conn, track_t i_tracks);
|
||||
|
||||
cddb_conn_t *p_conn = NULL;
|
||||
cddb_disc_t *p_cddb_disc = NULL;
|
||||
int i_cddb_matches = 0;
|
||||
@@ -360,7 +355,13 @@ read_toc(CdIo_t *p_cdio)
|
||||
} else {
|
||||
b_cd = true;
|
||||
data = 0;
|
||||
b_db = init_cddb(p_cdio, i_tracks);
|
||||
b_db =
|
||||
#ifdef HAVE_CDDB
|
||||
init_cddb(p_cdio, p_conn, i_tracks)
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
;
|
||||
for (i = i_first_track; i <= i_last_track+1; i++) {
|
||||
if ( !cdio_get_track_msf(p_cdio, i, &(toc[i])) )
|
||||
{
|
||||
@@ -506,10 +507,10 @@ display_status()
|
||||
if (p_cddb_disc->field) \
|
||||
snprintf(field, sizeof(field)-1, format_str, p_cddb_disc->field);
|
||||
|
||||
static bool
|
||||
init_cddb(CdIo_t *p_cdio, track_t i_tracks)
|
||||
{
|
||||
#ifdef HAVE_CDDB
|
||||
static bool
|
||||
init_cddb(CdIo_t *p_cdio, cddb_conn_t *p_conn, track_t i_tracks)
|
||||
{
|
||||
track_t i;
|
||||
|
||||
if (p_conn) cddb_destroy(p_conn);
|
||||
@@ -521,30 +522,30 @@ init_cddb(CdIo_t *p_cdio, track_t i_tracks)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (NULL == opts.cddb_email)
|
||||
if (NULL == cddb_opts.email)
|
||||
cddb_set_email_address(p_conn, "me@home");
|
||||
else
|
||||
cddb_set_email_address(p_conn, opts.cddb_email);
|
||||
cddb_set_email_address(p_conn, cddb_opts.email);
|
||||
|
||||
if (NULL == opts.cddb_server)
|
||||
if (NULL == cddb_opts.server)
|
||||
cddb_set_server_name(p_conn, "freedb.freedb.org");
|
||||
else
|
||||
cddb_set_server_name(p_conn, opts.cddb_server);
|
||||
cddb_set_server_name(p_conn, cddb_opts.server);
|
||||
|
||||
if (opts.cddb_timeout >= 0)
|
||||
cddb_set_timeout(p_conn, opts.cddb_timeout);
|
||||
if (cddb_opts.timeout >= 0)
|
||||
cddb_set_timeout(p_conn, cddb_opts.timeout);
|
||||
|
||||
cddb_set_server_port(p_conn, opts.cddb_port);
|
||||
cddb_set_server_port(p_conn, cddb_opts.port);
|
||||
|
||||
if (opts.cddb_http)
|
||||
if (cddb_opts.http)
|
||||
cddb_http_enable(p_conn);
|
||||
else
|
||||
cddb_http_disable(p_conn);
|
||||
|
||||
if (NULL != opts.cddb_cachedir)
|
||||
cddb_cache_set_dir(p_conn, opts.cddb_cachedir);
|
||||
if (NULL != cddb_opts.cachedir)
|
||||
cddb_cache_set_dir(p_conn, cddb_opts.cachedir);
|
||||
|
||||
if (opts.cddb_disable_cache)
|
||||
if (cddb_opts.disable_cache)
|
||||
cddb_cache_disable(p_conn);
|
||||
|
||||
p_cddb_disc = cddb_disc_new();
|
||||
@@ -579,10 +580,8 @@ init_cddb(CdIo_t *p_cdio, track_t i_tracks)
|
||||
add_cddb_disc_info("%s", genre);
|
||||
add_cddb_disc_info("%5d", year);
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
#endif /*HAVE_CDDB*/
|
||||
|
||||
#define add_cddb_track_info(format_str, field) \
|
||||
if (t->field) \
|
||||
@@ -1052,7 +1051,7 @@ main(int argc, char *argv[])
|
||||
psz_program = strrchr(argv[0],'/');
|
||||
psz_program = psz_program ? psz_program+1 : argv[0];
|
||||
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
memset(&cddb_opts, 0, sizeof(cddb_opts));
|
||||
|
||||
/* parse options */
|
||||
while ( 1 ) {
|
||||
|
||||
15
src/cddb.h
15
src/cddb.h
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
$Id: cddb.h,v 1.1 2005/03/06 11:21:52 rocky Exp $
|
||||
$Id: cddb.h,v 1.2 2005/03/11 10:34:28 rocky Exp $
|
||||
|
||||
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
|
||||
|
||||
@@ -18,6 +18,19 @@
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
typedef struct cddb_opts_s
|
||||
{
|
||||
char *email; /* email to report to CDDB server. */
|
||||
char *server; /* CDDB server to contact */
|
||||
int port; /* port number to contact CDDB server. */
|
||||
int http; /* 1 if use http proxy */
|
||||
int timeout;
|
||||
bool disable_cache; /* If set the below is meaningless. */
|
||||
char *cachedir;
|
||||
} cddb_opts_t;
|
||||
|
||||
cddb_opts_t cddb_opts;
|
||||
|
||||
/*!
|
||||
Compute the CDDB disk ID for an Audio disk. This is a funny checksum
|
||||
consisting of the concatenation of 3 things:
|
||||
|
||||
Reference in New Issue
Block a user