public App() { var tracksSerializer = new iTunesXMLTracksDeserializer(); var tracksRepository = new SerializingTracksRepository(tracksSerializer); var playlistsRepository = new FakePlaylistsRepository(tracksRepository); var service = new LocalLibraryService(tracksRepository, tracksRepository); var audio = new CSCoreAudioPlaybackEngine(); var windowManager = new CustomWindowManager(); var dialog = new WindowsDialogService(windowManager); var proxy = new LibraryViewModelsProxy(service, t => new TrackViewModel(t)); //var tagger = new TagLibSharpAudioFileTagger(); //var audioDurationCalc = new CSCoreAudioFileDurationCalculator(); //var audioFIProvider = new LocalAudioFileInfoProvider(tagger, audioDurationCalc); var libraryVM = new LibraryViewModel(proxy); var libraryView = new LibraryWindow() { DataContext = libraryVM }; var libraryConductor = new CustomWindowManager.WindowConductor(libraryVM, libraryView); libraryView.ShowDialog(); //var shellVM = new ShellViewModel(audio, service, dialog, libraryVM, new PlaybackControlsViewModel(audio, new PlaybackTimelineViewModel(audio))); //var shellView = new ShellWindow() { DataContext = shellVM }; //var shellConductor = new CustomWindowManager.WindowConductor(shellVM, shellView); //shellView.ShowDialog(); this.Shutdown(); }
public void ScanForChanges() { var localFiles = LocalLibraryService.GetAllMusicFilePaths().ToList(); var libraryLocalFileReferences = iTunesService.iTunesTracks.Where(itt => itt.Fingerprint != null).Select(itt => itt.Fingerprint.File).ToList(); var localFilesNotInLibrary = localFiles.Where(lf => !libraryLocalFileReferences.Contains(lf)).ToList(); var libraryFilesNotFoundInLocal = libraryLocalFileReferences.Where(llfr => !localFiles.Contains(llfr)).ToList(); var filesFoundLocalAndInLibrary = localFiles.Where(lf => libraryLocalFileReferences.Contains(lf)).ToList(); TracksToAddToLibrary.AddRange(localFilesNotInLibrary); TracksToRemoveFromLibrary.AddRange(iTunesService.iTunesTracks.Where(itt => itt.Fingerprint != null && libraryFilesNotFoundInLocal.Contains(itt.Fingerprint.File))); // Hydrates TracksToUpdateInLibrary // This is multithreaded as calculating hashes can take a while Task.WaitAll(CheckForChangedFiles(filesFoundLocalAndInLibrary)); // Next, update/encode changed files. This is multithreaded as // encoding to Apple lossless may occur. Task.WaitAll(UpdateChangedFiles()); // We have to remove tracks first in descending order // The iTunes database goes by indexes/total song counts // If we add or remove to that in any descending order, // all of our cached songs with their indexes are then invalidated TracksToRemoveFromLibrary = TracksToRemoveFromLibrary.OrderByDescending(t => t.iTunesTrack.Index).ToList(); iTunesService.RemoveFiles(TracksToRemoveFromLibrary.Select(t => t.Location).ToList()); // Next, add all remaining files. This is multithreaded as // encoding to Apple lossless may occur. Task.WaitAll(AddChangedFiles()); }
public ConversionService() { Source = ConfigurationManager.AppSettings["Source"]; Destination = ConfigurationManager.AppSettings["Destination"]; LocalLibraryService = new LocalLibraryService(); iTunesService = new iTunesService(); ThreadMessages = new Dictionary <int, string>(); SupportedExtensions = ConfigurationManager.AppSettings["SupportedFileExtensions"].Split('|'); UnsupportedExtensions = ConfigurationManager.AppSettings["UnsupportedFileExtensions"].Split('|'); }
public Task[] ProcessUpdatedMusic() { // 4x as many threads because calculating hashes is FAST Task[] workers = new Task[Threads * 4]; for (int i = 0; i < Threads * 4; i++) { int workerId = i; Task task = new Task(() => ProcessChangedFile(workerId)); workers[i] = task; task.Start(); } // Build full list of files var localFiles = LocalLibraryService.GetAllMusicFilePaths().ToList(); var libraryFiles = iTunesService.iTunesFingerprints.Select(itf => itf.File).ToList(); localFiles.AddRange(libraryFiles); localFiles = localFiles.Distinct().ToList(); return(workers); }