/// <summary> /// The merge with database. /// </summary> /// <param name="importDatabase"> /// The import database. /// </param> public static void MergeWithDatabase( BindingList <MovieModel> importDatabase, MovieDBTypes type = MovieDBTypes.Movies) { foreach (MovieModel movie in importDatabase) { if (movie.SmallPoster != null) { movie.SmallPoster = ImageHandler.ResizeImage(movie.SmallPoster, 100, 150); } switch (type) { case MovieDBTypes.Movies: MovieDatabase.Add(movie); break; case MovieDBTypes.Duplicates: DuplicatedMoviesDatabase.Add(movie); break; default: break; } } if (type == MovieDBTypes.Movies) { MediaPathDBFactory.GetMediaPathMoviesUnsorted().Clear(); GeneratePictureGallery(); } }
/// <summary> /// Handles the Click event of the ButRefresh control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void ButRefresh_Click(object sender, EventArgs e) { MediaPathDBFactory.GetMediaPathMoviesUnsorted().Clear(); MediaPathDBFactory.GetMediaPathTvUnsorted().Clear(); this.backgroundWorker = new BackgroundWorker(); this.backgroundWorker.DoWork += this.BackgroundWorker_DoWork; this.backgroundWorker.RunWorkerCompleted += this.BackgroundWorker_RunWorkerCompleted; this.backgroundWorker.RunWorkerAsync(); this.EnableForm(false); }
/// <summary> /// The merge with database. /// </summary> /// <param name="importDatabase"> /// The import database. /// </param> public static void MergeWithDatabase(BindingList <MovieModel> importDatabase) { foreach (MovieModel movie in importDatabase) { if (movie.SmallPoster != null) { movie.SmallPoster = Tools.ResizeImage(movie.SmallPoster, 100, 150); } MovieDatabase.Add(movie); } MediaPathDBFactory.GetMediaPathMoviesUnsorted().Clear(); GeneratePictureGallery(); }
/// <summary> /// Converts the media path import database into a MovieModel DB. /// </summary> public static void ConvertMediaPathImportToDB() { var db = MediaPathDBFactory.GetMediaPathMoviesUnsorted(); var count = 0; MovieDBFactory.ImportProgressMaximum = db.Count; ImportDatabase.Clear(); var getFiles = new string[1]; var currentGetPathFiles = string.Empty; foreach (var file in db) { MovieDBFactory.ImportProgressCurrent = count; MovieDBFactory.ImportProgressStatus = string.Format("Processing: " + file.PathAndFileName); if (file.Path != currentGetPathFiles) { var files = FastDirectoryEnumerator.EnumerateFiles(file.Path, "*.*", SearchOption.TopDirectoryOnly); getFiles = (from f in files select f.Path).ToArray(); currentGetPathFiles = file.Path; } var movieModel = new MovieModel { Title = Tools.Importing.MovieNaming.GetMovieName(file.PathAndFileName, file.MediaPathType), Year = Tools.Importing.MovieNaming.GetMovieYear(file.PathAndFileName), ScraperGroup = file.ScraperGroup, VideoSource = file.DefaultVideoSource, NfoPathOnDisk = FindNFO(file.FilenameWithOutExt, file.Path, getFiles), PosterPathOnDisk = FindPoster(file.FilenameWithOutExt, file.Path, getFiles), FanartPathOnDisk = FindFanart(file.FilenameWithOutExt, file.Path, getFiles) }; var result = (from m in ImportDatabase where m.Title == movieModel.Title select m).ToList(); if (result.Count == 0) { if (!string.IsNullOrEmpty(movieModel.NfoPathOnDisk)) { InOut.OutFactory.LoadMovie(movieModel); movieModel.ChangedText = false; } if (!string.IsNullOrEmpty(movieModel.PosterPathOnDisk)) { movieModel.GenerateSmallPoster(movieModel.PosterPathOnDisk); movieModel.ChangedPoster = false; } if (!string.IsNullOrEmpty(movieModel.FanartPathOnDisk)) { movieModel.GenerateSmallFanart(movieModel.FanartPathOnDisk); movieModel.ChangedFanart = false; } movieModel.AssociatedFiles.AddToMediaCollection(file); ImportDatabase.Add(movieModel); } else { // result[0].AssociatedFiles.GetMediaCollection().Clear(); result[0].AssociatedFiles.AddToMediaCollection(file); } count++; } }
/// <summary> /// The setup bindings. /// </summary> public void SetupBindings() { this.grdMediaPathList.DataSource = MediaPathDBFactory.MediaPathDB; this.grdMediaPathUnsortedMovies.DataSource = MediaPathDBFactory.GetMediaPathMoviesUnsorted(); this.grdMediaPathUnsortedTv.DataSource = MediaPathDBFactory.GetMediaPathTvUnsorted(); }
/// <summary> /// Converts the media path import database into a MovieModel DB. /// </summary> public static void ConvertMediaPathImportToDB() { cancelImport = false; var db = MediaPathDBFactory.GetMediaPathMoviesUnsorted(); var count = 0; MovieDBFactory.ImportProgressMaximum = db.Count; ImportDatabase.Clear(); ImportDuplicatesDatabase.Clear(); var getFiles = new string[1]; var currentGetPathFiles = string.Empty; UI.Windows7UIFactory.StartProgressState(db.Count); foreach (var file in db) { if (cancelImport) { break; } MovieDBFactory.ImportProgressCurrent = count; MovieDBFactory.ImportProgressStatus = string.Format("Processing: " + file.PathAndFileName.Replace("{", "{{").Replace("}", "}}")); if (file.Path != currentGetPathFiles) { getFiles = FileHelper.GetFilesRecursive(file.Path, "*.*").ToArray(); currentGetPathFiles = file.Path; } var videoSource = file.DefaultVideoSource; if (MovieNaming.IsBluRay(file.PathAndFileName)) { videoSource = "Bluray"; } else if (MovieNaming.IsDVD(file.PathAndFileName)) { videoSource = "DVD"; } else { var detect = Tools.IO.DetectType.FindVideoSource(file.PathAndFileName); if (!string.IsNullOrEmpty(detect)) { videoSource = detect; } } string title = MovieNaming.GetMovieName(file.PathAndFileName, file.MediaPathType); var movieModel = new MovieModel { Title = title, Year = MovieNaming.GetMovieYear(file.PathAndFileName), ScraperGroup = file.ScraperGroup, VideoSource = videoSource, NfoPathOnDisk = FindNFO(file.FilenameWithOutExt, FindFilePath(title, file), getFiles), PosterPathOnDisk = FindPoster(file.FilenameWithOutExt, FindFilePath(title, file), getFiles), FanartPathOnDisk = FindFanart(file.FilenameWithOutExt, FindFilePath(title, file), getFiles) }; if (!string.IsNullOrEmpty(movieModel.NfoPathOnDisk)) { InOut.OutFactory.LoadMovie(movieModel); movieModel.ChangedText = false; } var result = (from m in ImportDatabase where (m.Title.ToLower().Trim() == movieModel.Title.ToLower().Trim()) select m).ToList(); if (result.Count == 0) { if (!string.IsNullOrEmpty(movieModel.PosterPathOnDisk)) { movieModel.GenerateSmallPoster(movieModel.PosterPathOnDisk); movieModel.ChangedPoster = false; } if (!string.IsNullOrEmpty(movieModel.FanartPathOnDisk)) { movieModel.GenerateSmallFanart(movieModel.FanartPathOnDisk); movieModel.ChangedFanart = false; } movieModel.AssociatedFiles.AddToMediaCollection(file); // Does the movie exist in our current DB? var result2 = (from m in MovieDBFactory.MovieDatabase where (m.Title.ToLower().Trim() == movieModel.Title.ToLower().Trim()) select m).ToList(); if (result2.Count > 0) { if (movieModel.Year != null) { var r = (from m in result2 where m.Year == movieModel.Year select m).ToList(); if (r.Count > 0) { // We already have a movie with that name and year, mark as dupe ImportDuplicatesDatabase.Add(movieModel); } } else { // No year, so we can't ensure it's a dupe ImportDuplicatesDatabase.Add(movieModel); } } // Add it to the list anyway, since there's no implementation of any action on duplicates. ImportDatabase.Add(movieModel); } else { var r = (from m in result where m.Year == movieModel.Year select m).ToList(); if (Regex.IsMatch(file.PathAndFileName.ToLower(), @"(disc|disk|part|cd|vob|ifo|bup)", RegexOptions.IgnoreCase)) { // Only associate with an existing movie if its not a dupe result[0].AssociatedFiles.AddToMediaCollection(file); } else if (r.Count == 0) { // Same title, different year ImportDatabase.Add(movieModel); } else { // Dont count a disc or part as a dupe or movies with different years ImportDuplicatesDatabase.Add(movieModel); // Add it to the list anyway, since there's no implementation of any action on duplicates. ImportDatabase.Add(movieModel); } } count++; UI.Windows7UIFactory.SetProgressValue(count); } UI.Windows7UIFactory.StopProgressState(); }