static int resolve_disc (cddb_disc_t* disc, char *disc_list) { trace("cda: resolve_disc\n"); cddb_conn_t *conn = new_cddb_connection(); if (!conn) { return 0; } cddb_disc_t *temp_disc = cddb_disc_clone(disc); cddb_disc_t *query_disc = disc; cddb_cache_disable(conn); const int matches = cddb_query(conn, query_disc); cddb_cache_enable(conn); size_t discs_read = 0; disc_list[0] = '\0'; for (int i = 0; i < matches; i++) { if (cddb_read(conn, query_disc) && discs_read < MAX_CDDB_DISCS) { discs_read++; char temp_string[CDDB_CATEGORY_SIZE + CDDB_DISCID_SIZE + 1]; sprintf(temp_string, ",%s/%08x", cddb_disc_get_category_str(query_disc), cddb_disc_get_discid(query_disc)); strcat(disc_list, temp_string); query_disc = temp_disc; } cddb_query_next(conn, query_disc); } cddb_disc_destroy(temp_disc); cddb_destroy(conn); return discs_read; }
static void print_cddb_info(CdIo_t *p_cdio, track_t i_tracks, track_t i_first_track) { int i, i_cddb_matches = 0; cddb_conn_t *p_conn = NULL; cddb_disc_t *p_cddb_disc = NULL; if ( init_cddb(p_cdio, &p_conn, &p_cddb_disc, cddb_errmsg, i_first_track, i_tracks, &i_cddb_matches) ) { if (-1 == i_cddb_matches) printf("%s: %s\n", program_name, cddb_error_str(cddb_errno(p_conn))); else { printf("%s: Found %d matches in CDDB\n", program_name, i_cddb_matches); for (i=1; i<=i_cddb_matches; i++) { cddb_disc_print(p_cddb_disc); cddb_query_next(p_conn, p_cddb_disc); if (i != i_cddb_matches) cddb_read(p_conn, p_cddb_disc); } } cddb_disc_destroy(p_cddb_disc); cddb_destroy(p_conn); libcddb_shutdown(); } }
bool AudioCDDemux::freedb_query( cddb_disc_t *&cddb_disc ) { #ifdef Q_OS_WIN bool hasHomeEnv = getenv( "HOME" ); if ( !hasHomeEnv ) putenv( "HOME=" + QDir::homePath().toLocal8Bit() ); #endif cddb_conn_t *cddb = cddb_new(); #ifdef Q_OS_WIN if ( !hasHomeEnv ) putenv( "HOME=" ); #endif cddb_disc = cddb_disc_new(); #ifdef Q_OS_WIN const QString cddbDir = QMPlay2Core.getSettingsDir() + "CDDB"; if ( QDir( cddbDir ).exists() || QDir( QMPlay2Core.getSettingsDir() ).mkdir( "CDDB" ) ) cddb_cache_set_dir( cddb, cddbDir.toLocal8Bit() ); #endif cddb_disc_set_length( cddb_disc, FRAMES_TO_SECONDS( cdio_get_track_lba( cdio, CDIO_CDROM_LEADOUT_TRACK ) ) ); for ( int trackno = 1 ; trackno <= numTracks ; ++trackno ) { cddb_track_t *pcddb_track = cddb_track_new(); cddb_track_set_frame_offset( pcddb_track, cdio_get_track_lba( cdio, trackno ) ); cddb_disc_add_track( cddb_disc, pcddb_track ); } bool useNetwork = false; cddb_disc_calc_discid( cddb_disc ); if ( cddb_disc_get_discid( cddb_disc ) == discID ) cddb_cache_only( cddb ); else { discID = cddb_disc_get_discid( cddb_disc ); cddb_set_timeout( cddb, 3 ); cddb_http_enable( cddb ); cddb_set_server_port( cddb, 80 ); Settings sets( "QMPlay2" ); if ( sets.getBool( "Proxy/Use" ) ) { cddb_http_proxy_enable( cddb ); cddb_set_http_proxy_server_name( cddb, sets.getString( "Proxy/Host" ).toLocal8Bit() ); cddb_set_http_proxy_server_port( cddb, sets.getUInt( "Proxy/Port" ) ); if ( sets.getBool( "Proxy/Login" ) ) { cddb_set_http_proxy_username( cddb, sets.getString( "Proxy/User" ).toLocal8Bit() ); cddb_set_http_proxy_password( cddb, QString( QByteArray::fromBase64( sets.getByteArray( "Proxy/Password" ) ) ).toLocal8Bit() ); } } useNetwork = true; } for ( int i = 0 ; i <= useNetwork ; ++i ) { if ( cddb_query( cddb, cddb_disc ) > 0 ) { do if ( cddb_disc_get_discid( cddb_disc ) == discID ) { cddb_read( cddb, cddb_disc ); cddb_destroy( cddb ); return true; } while ( cddb_query_next( cddb, cddb_disc ) ); } if ( useNetwork && !i ) cddb_set_server_name( cddb, "freedb.musicbrainz.org" ); } cddb_disc_destroy( cddb_disc ); cddb_destroy( cddb ); cddb_disc = NULL; return false; }
int next() { return cddb_query_next(connection, disc); }
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_disc_t *disc = NULL; if (!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"); else cddb_set_email_address(conn, opts.cddb_email); if (NULL == opts.cddb_server) cddb_set_server_name(conn, "freedb.freedb.org"); else cddb_set_server_name(conn, opts.cddb_server); if (opts.cddb_timeout >= 0) cddb_set_timeout(conn, opts.cddb_timeout); cddb_set_server_port(conn, opts.cddb_port); if (opts.cddb_http) cddb_http_enable(conn); else cddb_http_disable(conn); if (NULL != opts.cddb_cachedir) cddb_cache_set_dir(conn, opts.cddb_cachedir); if (opts.cddb_disable_cache) cddb_cache_disable(conn); disc = cddb_disc_new(); if (!disc) { report(stderr, "%s: unable to create CDDB disc structure", program_name); goto cddb_destroy; } for(i = 0; i < i_tracks; i++) { cddb_track_t *t = cddb_track_new(); t->frame_offset = cdio_get_track_lba(p_cdio, i+i_first_track); cddb_disc_add_track(disc, t); } disc->length = cdio_get_track_lba(p_cdio, CDIO_CDROM_LEADOUT_TRACK) / CDIO_CD_FRAMES_PER_SEC; if (!cddb_disc_calc_discid(disc)) { report(stderr, "%s: libcddb calc discid failed.\n", program_name); goto cddb_destroy; } matches = cddb_query(conn, disc); if (-1 == matches) { sprintf(temp_msg, "%s: %s\n", program_name, cddb_error_str(cddb_errno(conn))); report(stdout, temp_msg); } else { sprintf(temp_msg, "%s: Found %d matches in CDDB\n", program_name, matches); report(stdout, temp_msg); for (i=1; i<=matches; i++) { cddb_read(conn, disc); cddb_disc_print(disc); cddb_query_next(conn, disc); } } cddb_disc_destroy(disc); cddb_destroy: cddb_destroy(conn); }
void do_query(cddb_conn_t *conn, cddb_disc_t *disc, int quiet) { int matches, i; /* This command also requires the disc ID to be initalized correctly. So we first calculate this disc ID before executing the query command. */ cddb_disc_calc_discid(disc); /* Try querying the database for information about the provided disc. This function will return the number of matches that were found. A return value of 0 means that no matches were found. The data of the first match (when found) will be filled in into the disc structure passed to it. The information will be retrieved from the server or read from the cache depending on the connection settings. */ matches = cddb_query(conn, disc); /* If an error occured then the return value will be -1 and the internal libcddb error number will be set. */ if (matches == -1) { /* Print an explanatory message on stderr. Other routines are available for retrieving the message without printing it or printing it on a stream other than stderr. */ if (!quiet) { cddb_error_print(cddb_errno(conn)); } /* Return to calling fucntion. */ return; } printf("Number of matches: %d\n", matches); /* A CDDB query command will not return all the disc information. It will return a subset that can afterwards be used to do a CDDB read. This enables you to first show a pop-up listing the found matches before doing further reads for the full data. The data that is returned for each match is: the disc CDDB category, the disc ID as known by the server, the disc title and the artist's name. */ /* Let's loop over the matches. */ i = 0; while (i < matches) { /* Increment the match counter. */ i++; /* Print out the information for the current match. */ printf("Match %d\n", i); /* Retrieve and print the category and disc ID. */ printf(" category: %s (%d)\t%08x\n", cddb_disc_get_category_str(disc), cddb_disc_get_category(disc), cddb_disc_get_discid(disc)); /* Retrieve and print the disc title and artist name. */ printf(" '%s' by %s\n", cddb_disc_get_title(disc), cddb_disc_get_artist(disc)); /* Get the next match, if there is one left. */ if (i < matches) { /* If there are multiple matches, then you can use the following function to retrieve the matches beyond the first. This function will overwrite any data that might be present in the disc structure passed to it. So if you still need that disc for anything else, then first create a new disc and use that to call this function. If there are no more matches left, false (i.e. 0) will be returned. */ if (!cddb_query_next(conn, disc)) { error_exit(cddb_errno(conn), "query index out of bounds"); } } } }