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; }
public static void SplitMetadata(string path, ref Track track, ref Album album, ref Artist artist, ref Genre genre) { if (!string.IsNullOrEmpty(path)) { var fmd = new FileMetadata(path); var fi = new FileInformation(path); // Track information track.Path = path; track.FileName = fi.NameWithoutExtension; track.Duration = Convert.ToInt64(fmd.Duration.TotalMilliseconds); track.MimeType = fmd.MimeType; track.BitRate = fmd.BitRate; track.SampleRate = fmd.SampleRate; track.TrackTitle = MetadataUtils.SanitizeTag(fmd.Title.Value); track.TrackNumber = MetadataUtils.SafeConvertToLong(fmd.TrackNumber.Value); track.TrackCount = MetadataUtils.SafeConvertToLong(fmd.TrackCount.Value); track.DiscNumber = MetadataUtils.SafeConvertToLong(fmd.DiscNumber.Value); track.DiscCount = MetadataUtils.SafeConvertToLong(fmd.DiscCount.Value); track.Year = MetadataUtils.SafeConvertToLong(fmd.Year.Value); track.Rating = fmd.Rating.Value; // Before proceeding, get the available artists string albumArtist = GetFirstAlbumArtist(fmd); string trackArtist = GetFirstArtist(fmd); // will be used for the album if no album artist is found // Album information album.AlbumTitle = string.IsNullOrWhiteSpace(fmd.Album.Value) ? Defaults.UnknownAlbumString : MetadataUtils.SanitizeTag(fmd.Album.Value); album.AlbumArtist = (albumArtist == Defaults.UnknownAlbumArtistString ? trackArtist : albumArtist); album.DateAdded = FileOperations.GetDateCreated(path); IndexerUtils.UpdateAlbumYear(album, MetadataUtils.SafeConvertToLong(fmd.Year.Value)); // Artist information artist.ArtistName = trackArtist; // Genre information genre.GenreName = GetFirstGenre(fmd); // 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 = fi.SizeInBytes; track.DateFileModified = fi.DateModifiedTicks; track.DateLastSynced = DateTime.Now.Ticks; } }
/// <summary> /// Constructs an API method signature as described in point 4 on http://www.last.fm/api/mobileauth /// </summary> /// <param name="data"></param> /// <param name="method"></param> /// <returns>API method signature</returns> private static string GenerateMethodSignature(IEnumerable <KeyValuePair <string, string> > parameters, string method) { var alphabeticalList = new List <string>(); // Add everything to the list foreach (KeyValuePair <string, string> parameter in parameters) { alphabeticalList.Add(string.Format("{0}{1}", parameter.Key, parameter.Value)); } alphabeticalList.Add("method" + method); // Order the list alphabetically alphabeticalList = alphabeticalList.OrderBy((t) => t).ToList(); // Join all parts of the list alphabetically and append API secret string signature = string.Format("{0}{1}", string.Join("", alphabeticalList.ToArray()), SensitiveInformation.LastfmSharedSecret); // Create MD5 hash and return that return(CryptographyUtils.MD5Hash(signature)); }
/// <summary> /// Constructs an API method signature as described in point 4 on http://www.last.fm/api/mobileauth /// </summary> /// <param name="data"></param> /// <param name="method"></param> /// <returns>API method signature</returns> private static string GenerateSignature(NameValueCollection data, string method) { var alphabeticalList = new List <string>(); // Add everything to the list foreach (string key in data) { alphabeticalList.Add(string.Format("{0}{1}", key, data[key])); } alphabeticalList.Add("method" + method); // Order the list alphabetically alphabeticalList = alphabeticalList.OrderBy((t) => t).ToList(); // Join all parts of the list alphabetically and append API secret string signatureString = string.Format("{0}{1}", string.Join("", alphabeticalList.ToArray()), SensitiveInformation.LastfmSharedSecret); // Create MD5 hash and return that return(CryptographyUtils.MD5Hash(signatureString)); }