예제 #1
0
    /// <summary>
    /// Explicitly casts <see cref="Lastfm.Services.Album"/>
    /// to <see cref="mp3tag.Metadata"/>
    /// </summary>
    /// <param name="album">Album tag to be casted</param>
    /// <returns>mp3tag.Tag object</returns>
    static public Metadata ToTag(this Lastfm.Services.Album album)
    {
      // Set album specific data
      Metadata Collection = new MetadataCollection();
      Metadata Metadata = new Id3();
      Metadata.Artist = album.Artist.Name;
      Metadata.Release = album.Name;
      Metadata.ReleaseYear = album.GetReleaseDate().Year.ToString();
      Metadata.Art = album.GetImageURL(AlbumImageSize.ExtraLarge);
      
      // Invoke copy constructor on tag object
      // otherwirse all tags in the collection will have changes
      // applied.
      foreach (Track t in album.GetTracks())
      {
        Metadata.Title = t.Title;
        Metadata.Track = (Collection.ToList<Metadata>().Count() + 1).ToString();
        Collection.Add(new Id3(Metadata));
      }

      // Return tag collection for album
      return Collection;
    }
예제 #2
0
    /// <summary>
    /// Converts musicbrainz metadata collection to 
    /// <see cref="mp3tag.MetadataCollection"/>.
    /// </summary>
    /// <param name="album">Musicbrainz album object</param>
    /// <returns>Corresponding tag collection</returns>
    /// <remarks>
    /// Musicbrainz supports release types. This information
    /// in the case of non-album releases the data is appended
    /// to the album name. Date defaults to today if nothing 
    /// is set.
    /// 
    /// In the case of various artist, the artist is set to
    /// album artist first to locate album art & genre. 
    /// Then artist is based on a per-track basis.
    /// </remarks>
    static public Metadata ToTag(this MusicBrainz.Release album)
    {
      Metadata Collection = new MetadataCollection();
      Metadata Metadata = new Id3();

      // If date is not set, use current date
      string ReleaseDate = String.Empty;
      try {
        ReleaseDate = album.GetEvents().First().Date.ToString();
      } 
      catch(Exception)
      {
        ReleaseDate = DateTime.Now.Year.ToString();
      }
      
      // Build tag with search data
      Art Art = new Art();
      Metadata.MusicBrainzReleaseArtistId = album.GetArtist().Id;
      Metadata.MusicBrainzReleaseId = album.Id;
      Metadata.MusicBrainzReleaseType = album.GetReleaseType().ToString();
      Metadata.AlbumArtist = album.GetArtist();
      Metadata.Release = album.GetTitle();
      Metadata.AmazonId = album.GetAsin();
      Metadata.ReleaseYear = ReleaseDate.Substring(0, 4);
      Metadata.Art = Art.Search(Metadata);

      // Search for genre; populate with default for now
      Metadata.Genre = "Hardcore";
      //Metadata.Genre = ITunesService.SearchArtistGenre(Metadata);

      // Set track titles
      foreach (Track Trk in album.GetTracks())
      {
        Metadata.Title = Trk.GetTitle();
        Metadata.Artist = Trk.GetArtist();
        Metadata.MusicBrainzArtistId = Trk.GetArtist().Id;
        Metadata.Track = (Collection.ToList<Metadata>().Count() + 1).ToString();
        Collection.Add(new Id3(Metadata));
      }

      return Collection;
    }