Beispiel #1
0
 public static string GetFirstAlbumArtist(IFileMetadata fileMetadata)
 {
     return(string.IsNullOrWhiteSpace(fileMetadata.AlbumArtists.Value) ? Defaults.UnknownArtistText : MetadataUtils.SanitizeTag(MetadataUtils.PatchID3v23Enumeration(fileMetadata.AlbumArtists.Values).FirstNonEmpty(Defaults.UnknownArtistText)));
 }
Beispiel #2
0
        public static void SplitMetadata(IFileMetadata fileMetadata, ref Track track, ref TrackStatistic trackStatistic, ref Album album, ref Artist artist, ref Genre genre)
        {
            string path = fileMetadata.Path;

            // Track information
            track.Path          = path;
            track.SafePath      = path.ToSafePath();
            track.FileName      = FileUtils.NameWithoutExtension(path);
            track.Duration      = Convert.ToInt64(fileMetadata.Duration.TotalMilliseconds);
            track.MimeType      = fileMetadata.MimeType;
            track.BitRate       = fileMetadata.BitRate;
            track.SampleRate    = fileMetadata.SampleRate;
            track.TrackTitle    = MetadataUtils.SanitizeTag(fileMetadata.Title.Value);
            track.TrackNumber   = MetadataUtils.SafeConvertToLong(fileMetadata.TrackNumber.Value);
            track.TrackCount    = MetadataUtils.SafeConvertToLong(fileMetadata.TrackCount.Value);
            track.DiscNumber    = MetadataUtils.SafeConvertToLong(fileMetadata.DiscNumber.Value);
            track.DiscCount     = MetadataUtils.SafeConvertToLong(fileMetadata.DiscCount.Value);
            track.Year          = MetadataUtils.SafeConvertToLong(fileMetadata.Year.Value);
            track.HasLyrics     = string.IsNullOrWhiteSpace(fileMetadata.Lyrics.Value) ? 0 : 1;
            track.NeedsIndexing = 0;

            // TrackStatistic information
            trackStatistic.Path     = path;
            trackStatistic.SafePath = path.ToSafePath();
            trackStatistic.Rating   = fileMetadata.Rating.Value;

            // Before proceeding, get the available artists
            string albumArtist = GetFirstAlbumArtist(fileMetadata);
            string trackArtist = GetFirstArtist(fileMetadata); // will be used for the album if no album artist is found

            // Album information
            album.AlbumTitle  = string.IsNullOrWhiteSpace(fileMetadata.Album.Value) ? Defaults.UnknownAlbumText : MetadataUtils.SanitizeTag(fileMetadata.Album.Value);
            album.AlbumArtist = (albumArtist == Defaults.UnknownArtistText ? trackArtist : albumArtist);
            album.DateAdded   = DateTime.Now.Ticks;
            album.DateCreated = FileUtils.DateCreatedTicks(path);

            UpdateAlbumYear(album, MetadataUtils.SafeConvertToLong(fileMetadata.Year.Value));

            // Artist information
            artist.ArtistName = trackArtist;

            // Genre information
            genre.GenreName = GetFirstGenre(fileMetadata);

            // Metadata hash
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.Append(album.AlbumTitle);
            sb.Append(artist.ArtistName);
            sb.Append(genre.GenreName);
            sb.Append(track.TrackTitle);
            sb.Append(track.TrackNumber);
            sb.Append(track.Year);
            track.MetaDataHash = CryptographyUtils.MD5Hash(sb.ToString());

            // File information
            track.FileSize         = FileUtils.SizeInBytes(path);
            track.DateFileModified = FileUtils.DateModifiedTicks(path);
            track.DateLastSynced   = DateTime.Now.Ticks;
        }
Beispiel #3
0
 public static string GetFirstGenre(IFileMetadata fmd)
 {
     return(string.IsNullOrWhiteSpace(fmd.Genres.Value) ? Defaults.UnknownGenreText : MetadataUtils.PatchID3v23Enumeration(fmd.Genres.Values).FirstNonEmpty(Defaults.UnknownGenreText));
 }