private void AddChangedFile(int workerId) { foreach (var file in AddedThreadQueue.GetConsumingEnumerable()) { LogThread(workerId, $"Adding file {file}"); var fileInfo = new FileInfo(file); var crc32 = Helpers.GetFileCRC32(file); var fileSize = Helpers.GetFileSize(file); var fingerprint = new TrackFingerprint(file, crc32, fileSize); if (SupportedExtensions.Contains(fileInfo.Extension.Substring(1, fileInfo.Extension.Length - 1))) { LogThread(workerId, $"Copying added file {file}"); var copiedFile = CopySupportedFile(file, fingerprint); iTunesService.AddFile(copiedFile); } else { LogThread(workerId, $"Converting added file {file}"); var convertedFile = ConvertALACToFLAC(file, fingerprint); iTunesService.AddFile(convertedFile); } } }
public void Init() { iTunesTracks.AddRange(GetAllTracks()); foreach (var track in iTunesTracks) { try { Console.WriteLine($"Parsing fingerprint from ${track.Location}"); var serializedFingerprint = track.Comment; var fingerprint = new TrackFingerprint(serializedFingerprint); iTunesFingerprints.Add(fingerprint); } catch { } } }
public string ConvertALACToFLAC(string filePath, TrackFingerprint fingerprint) { var output = filePath.Replace(Source, Destination); var outputPath = Path.GetDirectoryName(output); var basename = Path.GetFileNameWithoutExtension(output); Directory.CreateDirectory(outputPath); var converter = new FFmpegCommand(); converter.Codec = "alac"; converter.InputPath = filePath; converter.OutputPath = String.Format("{0}\\{1}.m4a", outputPath, basename); converter.Hash = fingerprint.ToString(); converter.Convert(); return(converter.OutputPath); }
public string CopySupportedFile(string filePath, TrackFingerprint fingerprint) { FFmpegCommand converter = new FFmpegCommand(); converter.Codec = "copy"; converter.InputPath = filePath; converter.OutputPath = filePath.Replace(Source, Destination); var outputPath = Path.GetDirectoryName(converter.OutputPath); Directory.CreateDirectory(outputPath); converter.Convert(); var file = TagLib.File.Create(converter.OutputPath); file.Tag.Comment = fingerprint.ToString(); file.Save(); file.Dispose(); return(converter.OutputPath); }
public Track(IITFileOrCDTrack track) { /*Album = track.Album; * AlbumArtist = track.AlbumArtist; * AlbumRating = track.AlbumRating; * AlbumRatingKind = track.AlbumRatingKind; * Artist = track.Artist; * BitRate = track.BitRate; * BookmarkTime = track.BookmarkTime; * BPM = track.BPM; * Category = track.Category;*/ Comment = track.Comment; /*Compilation = track.Compilation; * DateAdded = track.DateAdded; * Description = track.Description; * DiscCount = track.DiscCount; * DiscNumber = track.DiscNumber; * Duration = track.Duration; * Enabled = track.Enabled; * EpisodeNumber = track.EpisodeNumber; * ExcludeFromShuffle = track.ExcludeFromShuffle; * Finish = track.Finish; * Genre = track.Genre; * Index = track.Index; * Kind = track.Kind; * KindAsString = track.KindAsString;*/ Location = track.Location; /*LongDescription = track.LongDescription; * Lyrics = track.Lyrics; * ModificationDate = track.ModificationDate; * Name = track.Name; * PartOfGaplessAlbum = track.PartOfGaplessAlbum; * PlayedCount = track.PlayedCount; * PlayedDate = track.PlayedDate; * PlayOrderIndex = track.PlayOrderIndex; * Podcast = track.Podcast; * Rating = track.Rating; * ReleaseDate = track.ReleaseDate; * RememberBookmark = track.RememberBookmark; * SampleRate = track.SampleRate; * SeasonNumber = track.SeasonNumber; * Size = track.Size; * Size64High = track.Size64High; * Size64Low = track.Size64Low; * SkippedCount = track.SkippedCount; * SkippedDate = track.SkippedDate; * SortAlbum = track.SortAlbum; * SortAlbumArtist = track.SortAlbumArtist; * SortArtist = track.SortArtist; * SortComposer = track.SortComposer; * SortName = track.SortName; * SortShow = track.SortShow; * Start = track.Start; * Time = track.Time; * TrackCount = track.TrackCount; * TrackNumber = track.TrackNumber; * Unplayed = track.Unplayed; * VolumeAdjustment = track.VolumeAdjustment; * Year = track.Year;*/ iTunesTrack = track; try { Fingerprint = new TrackFingerprint(Comment); } catch { } }