Beispiel #1
0
static void 
get_cddb_disc_info(CdIo_t *p_cdio) 
{
#ifdef HAVE_CDDB
  b_db = init_cddb(p_cdio, &p_conn, &p_cddb_disc, xperror, i_first_track, 
                   i_tracks, &i_cddb_matches);
  if (b_db) {
    int i_year;
    i_year = atoi(year);
    cddb_disc_set_artist(p_cddb_disc, artist);
    cddb_disc_set_title(p_cddb_disc, title);
    cddb_disc_set_genre(p_cddb_disc, genre);
    cddb_disc_set_year(p_cddb_disc, i_year);
  }
#endif /* HAVE_CDDB */
  return;
}
Beispiel #2
0
// Copied from asunder v2.2 - GPL v2
void CddbInterface::readDisc()
{
    if (disc) {
        return;
    }

    int fd=open(dev.toLocal8Bit(), O_RDONLY | O_NONBLOCK);
    if (fd < 0) {
        emit error(i18n("Failed to open CD device"));
        return;
    }
    QByteArray unknown=i18n("Unknown").toUtf8();

#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
    struct ioc_toc_header th;
    struct ioc_read_toc_single_entry te;
    struct ioc_read_subchannel cdsc;
    struct cd_sub_channel_info data;
    bzero(&cdsc,sizeof(cdsc));
    cdsc.data = &data;
    cdsc.data_len = sizeof(data);
    cdsc.data_format = CD_CURRENT_POSITION;
    cdsc.address_format = CD_MSF_FORMAT;
    if (ioctl(fd, CDIOCREADSUBCHANNEL, (char *)&cdsc) >= 0 && 0==ioctl(fd, CDIOREADTOCHEADER, &th)) {
        disc = cddb_disc_new();
        if (disc) {
            te.address_format = CD_LBA_FORMAT;
            for (int i=th.starting_track; i<=th.ending_track; i++) {
                te.track = i;
                if (0==ioctl(fd, CDIOREADTOCENTRY, &te)) {
                    cddb_track_t *track = cddb_track_new();
                    if (track) {
                        cddb_track_set_frame_offset(track, te.entry.addr.lba + SECONDS_TO_FRAMES(2));
                        cddb_track_set_title(track, te.entry.control&0x04 ? dataTrack().toUtf8().constData() : i18n("Track %1", i).toUtf8().constData());
                        cddb_track_set_artist(track, unknown.constData());
                        cddb_disc_add_track(disc, track);
                    }
                }
            }
            te.track = 0xAA;
            if (0==ioctl(fd, CDIOREADTOCENTRY, &te))  {
                cddb_disc_set_length(disc, (ntohl(te.entry.addr.lba)+SECONDS_TO_FRAMES(2))/SECONDS_TO_FRAMES(1));
            }
        }
    }
#elif defined(__linux__)
    struct cdrom_tochdr th;
    struct cdrom_tocentry te;
    int status = ioctl(fd, CDROM_DISC_STATUS, CDSL_CURRENT);
    if ((CDS_AUDIO==status || CDS_MIXED==status) && 0==ioctl(fd, CDROMREADTOCHDR, &th)) {
        disc = cddb_disc_new();
        if (disc) {
            te.cdte_format = CDROM_LBA;
            for (int i=th.cdth_trk0; i<=th.cdth_trk1; i++) {
                te.cdte_track = i;
                if (0==ioctl(fd, CDROMREADTOCENTRY, &te)) {
                    cddb_track_t *track = cddb_track_new();
                    if (track) {
                        cddb_track_set_frame_offset(track, te.cdte_addr.lba + SECONDS_TO_FRAMES(2));
                        cddb_track_set_title(track, te.cdte_ctrl&CDROM_DATA_TRACK ? dataTrack().toUtf8().constData() : i18n("Track %1", i).toUtf8().constData());
                        cddb_track_set_artist(track, unknown.constData());
                        cddb_disc_add_track(disc, track);
                    }
                }
            }

            te.cdte_track = CDROM_LEADOUT;
            if (0==ioctl(fd, CDROMREADTOCENTRY, &te)) {
                cddb_disc_set_length(disc, (te.cdte_addr.lba+SECONDS_TO_FRAMES(2))/SECONDS_TO_FRAMES(1));
            }
        }
    }
#endif

    cddb_disc_set_artist(disc, unknown.constData());
    cddb_disc_set_title(disc, unknown.constData());
    cddb_disc_set_genre(disc, unknown.constData());
    cddb_disc_calc_discid(disc);
    close(fd);

    initial=toAlbum(disc);
    initial.isDefault=true;
    emit initialDetails(initial);
}