示例#1
0
static void
lookup_cd_info (char *device, album_info_t *album)
{
    MbDisc disc;
    MbQuery q;
    MbReleaseFilter f;
    MbResultList results;
    MbRelease release;
    char discid[100];
    int num_albums;

    memset(album, 1, sizeof(*album));

    disc = mb_read_disc(device);
    if (!disc) {
        fprintf(stderr, "unable to identify disc.\n");
        exit(1);
    }

    mb_disc_get_id(disc, discid, 100);
    fprintf(stderr, "got disc id: %s\n\n", discid);

    q = mb_query_new(NULL, NULL);
    f = mb_release_filter_new();

    mb_release_filter_disc_id(f, discid);
    results = mb_query_get_releases(q,f);

    mb_release_filter_free(f);
    mb_query_free(q);

    if (!results) {
        fprintf(stderr, "no results found\n");
        exit(1);
    }

    num_albums = mb_result_list_get_size(results);
    if (num_albums < 1) {
        char buf[256];
        mb_get_submission_url(disc, 0, 0, buf, sizeof(buf));
        fprintf(stderr, "nothing in musicbrainz for this one. add it via: %s\n", buf);
        exit(1);
    }

    if (num_albums > 1) {
        fprintf(stderr, "multiple albums!!! picking the last one\n");
    }

    release = mb_result_list_get_release(results, num_albums-1);
    get_album(release, &album->album_id, &album->title, &album->disc_number);

    album->release_date = get_release_date(release);

    get_album_artist(
        release, &album->artist_id, &album->artist, &album->artist_sortname
    );

    get_tracks(release, album);


    /*
    musicbrainz_t mb;
    char buf[256];
    int num_albums;

    mb = mb_New();
    mb_SetDevice(mb, device);
    mb_UseUTF8(mb, TRUE);

#ifdef MB_DEBUG
    mb_SetDebug(mb, TRUE);
#endif

    memset(album, 1, sizeof(*album));
    if (!mb_Query(mb, MBQ_GetCDInfo)) {
        mb_GetQueryError(mb, buf, sizeof(buf));
        fprintf(stderr, "unable to query cd: %s\n", buf);
        exit(1);
    }

    num_albums = mb_GetResultInt(mb, MBE_GetNumAlbums);

    if (num_albums < 1) {
        fprintf(stderr, "nothing in musicbrainz for this one. TODO add url\n");
        exit(1);
    }

    if (num_albums > 1) {
        fprintf(stderr, "multiple albums!!! picking the last one\n");
    }

    mb_Select1(mb, MBS_SelectAlbum, num_albums);

    get_album(mb, &album->album_id, &album->title, &album->disc_number);

    album->release_date = get_release_date(mb);
    
    get_album_artist(
        mb, &album->artist_id, &album->artist, &album->artist_sortname
    );

    get_tracks(mb, album);

    mb_Delete(mb);
    */
}
static GList *
mb_list_albums (SjMetadata *metadata, char **url, GError **error)
{
  SjMetadataMusicbrainz3Private *priv;
  GList *albums = NULL;
  MbQuery query;
  MbReleaseFilter filter;
  MbResultList results;
  MbRelease release;
  char *id = NULL;
  char buffer[1024];
  int i;
  g_return_val_if_fail (SJ_IS_METADATA_MUSICBRAINZ3 (metadata), NULL);

  priv = GET_PRIVATE (metadata);

  if (sj_metadata_helper_check_media (priv->cdrom, error) == FALSE) {
    return NULL;
  }

  priv->disc = mb_read_disc (priv->cdrom);
  if (priv->disc == NULL)
    return NULL;

  if (url != NULL) {
    mb_get_submission_url (priv->disc, NULL, 0, buffer, sizeof (buffer));
    *url = g_strdup (buffer);
  }

  if (g_getenv("MUSICBRAINZ_FORCE_DISC_ID")) {
    id = g_strdup (g_getenv("MUSICBRAINZ_FORCE_DISC_ID"));
  } else {
    GET(id, mb_disc_get_id, priv->disc);
  }

  query = mb_query_new (priv->mb, "sound-juicer");
  filter = mb_release_filter_new ();
  filter = mb_release_filter_disc_id (filter, id);
  results = mb_query_get_releases (query, filter);
  mb_release_filter_free (filter);
  g_free (id);

  if (results == NULL) {
    mb_query_free (query);
    return NULL;
  }

  if (mb_result_list_get_size (results) == 0) {
    mb_result_list_free (results);
    mb_query_free (query);
    return NULL;
  }

  for (i = 0; i < mb_result_list_get_size (results); i++) {
    AlbumDetails *album;
    MbReleaseIncludes includes;
    char buffer[512];

    release = mb_result_list_get_release (results, i);
    if(release) {
      mb_release_get_id (release, buffer, sizeof (buffer));
      includes = get_release_includes ();
      release = mb_query_get_release_by_id (query, buffer, includes);
      if(release) {
        mb_release_includes_free (includes);
        album = make_album_from_release (release);
        album->metadata_source = SOURCE_MUSICBRAINZ;
        fill_empty_durations (priv->disc, album);
        albums = g_list_append (albums, album);
        mb_release_free (release);
      }
    }
  }
  mb_result_list_free (results);
  mb_query_free (query);

  return albums;
}