/// <summary> /// UpdateLibrary loads the updates your existing saved library by rescanning the disk for changes. /// </summary> /// <returns>A list of updated library files.</returns> public async Task <IEnumerable <MovieLibraryFile> > ScanLibrary() { var newLibrary = new List <MovieLibraryFile>(); // Add all the existing library to the dictionary var existing = new Dictionary <string, MovieLibraryFile>(); foreach (var movie in await LoadMoviesFromFile()) { existing.TryAdd(movie.Path, movie); } // TODO: Figure out if I should try to minimize api requests by only querying for // Loop through checking if each value exists in the library already foreach (var path in Discover.FindMovieFiles(moviesDirectory)) { // If the paths match we use the existing metadata if user set metadata manually if (existing.ContainsKey(path) && existing[path].Modified) { existing[path].Id = newLibrary.Count(); newLibrary.Add(existing[path]); } else { // Otherwise we fetch fresh metadata for the file. newLibrary.Add(await Discover.MatchMovie(path, newLibrary.Count(), apiUrl)); } } movies = newLibrary; SaveMoviesToFile(); return(movies); }