예제 #1
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;
    }
예제 #2
0
    /// <summary>
    /// Embeds binary image data into metadata tag.
    /// </summary>
    /// <param name="file">TagLib.File to embed image data in</param>
    /// <param name="art">Image object</param>
    static public void SetImage(this TagLib.File file, Art art)
    {
      if (art.Url == String.Empty)
      {
        Trace.WriteLine("No image set for " + file.Name + "!");
        return;
      }

      
      file.Tag.Pictures = art.Picture;
      file.Save();
    }
예제 #3
0
파일: Release.cs 프로젝트: hannuraina/tag
    /// <summary>
    /// Creates new tree heirarchy underneath the specified path. 
    /// Leaf nodes are represented by <creg="Song"/> and sub-directories
    /// by <see cref="Album"/>.
    /// </summary>
    /// <param name="depth">Number of levels down object resides from root</param>
    /// <param name="path">Absolute path of the object. Must be a directory.</param>
    /// <remarks>
    /// Depth defaults to 0, meaning root. Each child's depth is incremented by 1
    /// and the child's parent is set to the current object. The album object
    /// assumed the path represents a directory, otherwise a <see cref="Song"/> 
    /// should be created.
    /// 
    /// Once individual files have been read in the metadata for the 
    /// folder is set since requesting Metadata.Artist pulls the artist
    /// tag from the first file in the folder.
    /// </remarks>
    /// <exception cref="IOException">When path is not directory</exception>
    public Release(string path, int depth=0)
    {
      // Initialize album parameters
      Path = path;
      Depth = depth;
      Art = new Art();
      TargetFormat = Encoding.MP3;
      Checksum = new Md5();
      children = new List<File>();
      metadata = new MetadataCollection();

      // Parse directories
      foreach (var Item in System.IO.Directory.GetDirectories(Path))
      {
        Add(new Release(Item, Depth + 1));
      }

      // Parse individual files
      foreach (var Item in System.IO.Directory.GetFiles(Path))
      {
        Add(new Song(Item, Depth + 1));
      }

      if (!Root)
      {
        // If no album metadata set, use folder name
        Metadata.Release = Metadata.Release ?? Name;
      }
    }
예제 #4
0
파일: Release.cs 프로젝트: hannuraina/tag
 /// <summary>
 /// Default ctor
 /// </summary>
 public Release() 
 {
   Art = new Art();
   TargetFormat = Encoding.MP3;
   Checksum = new Md5();
   children = new List<File>();
   metadata = new MetadataCollection();
 }