Exemplo n.º 1
0
track_info_t *
get_one_track(MbRelease release, album_info_t *a, int i)
{
    MbTrack t;
    MbArtist artist;
    track_info_t *track; 
    char buf[256];

    track = g_new0(track_info_t, 1);
    track->album = a;

    track->track_num = i;

    t = mb_release_get_track(release, i-1);

    mb_track_get_id(t, buf, sizeof(buf));
    track->track_id = g_strdup(buf);

    mb_track_get_title(t, buf, sizeof(buf));
    track->title = g_strdup(buf);
    // TODO: handle [Untitled]
    
    artist = mb_track_get_artist(t);
    if (!artist)
        artist = mb_release_get_artist(release);

    mb_artist_get_name(artist, buf, sizeof(buf));
    track->artist = g_strdup(buf);

    mb_artist_get_sortname(artist, buf, sizeof(buf));
    track->artist_sortname = g_strdup(buf);

    track->duration = mb_track_get_duration(t) / 1000;

    return track;


    /*
    track_info_t *track; 
    char buf[256];

    track = g_new0(track_info_t, 1);
    track->album = a;

    track->track_num = i;

    if (mb_GetResultData1(mb, MBE_AlbumGetTrackId, buf, sizeof(buf), i)) {
        mb_GetIDFromURL(mb, buf, buf, sizeof(buf));
        track->track_id = g_strdup(buf);
    }

    if (mb_GetResultData1(mb, MBE_AlbumGetArtistId, buf, sizeof(buf), i)) {
        mb_GetIDFromURL(mb, buf, buf, sizeof(buf));
        track->artist_id = g_strdup(buf);
    }

    if (mb_GetResultData1(mb, MBE_AlbumGetTrackName, buf, sizeof(buf), i)) {
        track->title = g_strdup(buf);
    } else {
        track->title = g_strdup("[Untitled]");
    }

    if (track->artist == NULL &&
        mb_GetResultData1(mb, MBE_AlbumGetArtistName, buf, sizeof(buf), i)) {
        track->artist = g_strdup(buf);
    }

    if (mb_GetResultData1(mb, MBE_AlbumGetArtistSortName, 
                          buf, sizeof(buf), i)) {

        track->artist_sortname = g_strdup(buf);
    }

    if (mb_GetResultData1(mb, MBE_AlbumGetTrackDuration, buf, sizeof(buf), i)) {
        track->duration = atoi(buf) / 1000;
    }

    return track;
    */
}
static AlbumDetails *
make_album_from_release (MbRelease *release)
{
  AlbumDetails *album;
  char buffer[512];
  MbArtist artist;
  char *new_title;
  int i;

  g_assert (release);

  album = g_new0 (AlbumDetails, 1);

  GET_ID (album->album_id, mb_release_get_id, release);
  GET (album->title, mb_release_get_title, release);
  new_title = sj_metadata_helper_scan_disc_number (album->title, &album->disc_number);
  if (new_title) {
    g_free (album->title);
    album->title = new_title;
  }

  artist = mb_release_get_artist (release);
  GET_ID (album->artist_id, mb_artist_get_id, artist);
  GET (album->artist, mb_artist_get_name, artist);
  GET (album->artist_sortname, mb_artist_get_sortname, artist);

  if (mb_release_get_num_release_events (release) >= 1) {
    MbReleaseEvent event;
    char *date = NULL;

    event = mb_release_get_release_event (release, 0);
    GET (date, mb_release_event_get_date, event);
    album->release_date = sj_metadata_helper_scan_date (date);
    g_free (date);
  }

  album->number = mb_release_get_num_tracks (release);
  GET (album->asin, mb_release_get_asin, release);

  for (i = 0; i < mb_release_get_num_relations (release); i++) {
    MbRelation relation;
    char *type = NULL;

    relation = mb_release_get_relation (release, i);
    GET(type, mb_relation_get_type, relation);
    if (type && g_str_equal (type, "http://musicbrainz.org/ns/rel-1.0#Wikipedia")) {
      GET (album->wikipedia, mb_relation_get_target_id, relation);
    } else if (type && g_str_equal (type, "http://musicbrainz.org/ns/rel-1.0#Discogs")) {
      GET (album->discogs, mb_relation_get_target_id, relation);
      continue;
    }
    g_free (type);
  }

  for (i = 0; i < mb_release_get_num_types (release); i++) {
    mb_release_get_type (release, i, buffer, sizeof(buffer));

    if (g_str_has_suffix (buffer, "#Spokenword")
    	|| g_str_has_suffix (buffer, "#Interview")
    	|| g_str_has_suffix (buffer, "#Audiobook")) {
      album->is_spoken_word = TRUE;
      break;
    }
  }

  for (i = 0; i < album->number; i++) {
    MbTrack mbt;
    TrackDetails *track;

    mbt = mb_release_get_track (release, i);
    track = g_new0 (TrackDetails, 1);

    track->album = album;

    track->number = i + 1;
    GET_ID (track->track_id, mb_track_get_id, mbt);

    GET (track->title, mb_track_get_title, mbt);
    track->duration = mb_track_get_duration (mbt) / 1000;

    artist = mb_track_get_artist (mbt);
    if (artist == NULL)
      artist = mb_release_get_artist (release);
    GET_ID (track->artist_id, mb_artist_get_id, artist);
    GET (track->artist, mb_artist_get_name, artist);
    GET (track->artist_sortname, mb_artist_get_sortname, artist);

    album->tracks = g_list_append (album->tracks, track);
  }

  return album;
}