Esempio n. 1
0
/* read data from cddb database */
void read_db(cddb_conn_t *conn, cddb_disc_t *disc) {
	int success = cddb_read(conn, disc);
	if (!success) {
	    /* something went wrong, print error */
	    cddb_error_print(cddb_errno(conn));
	    exit(-1);
	}
}
Esempio n. 2
0
File: cddb.c Progetto: bricka/giles
/**
 * Given a CDIO device, calculates the necessary information about the device
 * and contacts a CDDB server to get disk information.
 *
 * @param p_cdio a CDIO device
 * @param disk the disk structure to store the information in
 *
 * @return an error status about whether information was obtained
 */
enum giles_cddb_err get_cddb_info_for_device(const CdIo_t *p_cdio, cddb_disc_t *disc) {
    lsn_t last_lsn;
    msf_t last_msf;
    unsigned disc_len_in_s, i, matches;
    track_t num_tracks;
    cddb_track_t *track;
    cddb_conn_t *conn;

    num_tracks = cdio_get_num_tracks(p_cdio);

    DPRINTF ("Disc contains %d tracks\n", num_tracks);

    for (i = 1; i <= num_tracks; i++) {
        track = cddb_track_new();
        
        cddb_track_set_frame_offset(track, cdio_get_track_lba(p_cdio, i));
        DPRINTF ("Offset for track %d is %d\n", i, cdio_get_track_lba(p_cdio, i));
        cddb_disc_add_track(disc, track);
    }

    last_lsn = cdio_get_disc_last_lsn(p_cdio);
    cdio_lsn_to_msf(last_lsn, &last_msf);
    disc_len_in_s = cdio_audio_get_msf_seconds(&last_msf);

    cddb_disc_set_length(disc, disc_len_in_s);

    conn = cddb_new();

    if (conn == NULL) {
        cddb_error_print(cddb_errno(conn));
        return giles_cddb_err_no_conn;
    }

    matches = cddb_query(conn, disc);

    if (matches == -1) {
        return giles_cddb_err_no_conn;
    } else if (matches == 0) {
        return giles_cddb_err_no_match;
    }

    cddb_read(conn, disc);

    cddb_destroy(conn);

    return giles_cddb_err_none;
}
Esempio n. 3
0
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");
            }
        }
    }
}