/// <summary> /// The do import scan. /// </summary> public static void DoImportScan() { SeriesNameList = new BindingList <SeriesListModel>(); Scan = new SortedDictionary <string, ScanSeries>(); // Get file list var filters = Get.InOutCollection.VideoExtentions; var paths = MediaPathDBFactory.GetMediaPathTvUnsorted(); var filteredFiles = (from file in paths let pathAndFileName = Path.GetExtension(file.PathAndFileName).ToLower() where filters.Any(filter => pathAndFileName.ToLower() == "." + filter.ToLower()) select file.PathAndFileName).ToList(); // Process each file and add to ScanDB); foreach (var f in filteredFiles) { var episodeDetails = GetEpisodeDetails(f); if (episodeDetails.TvMatchSuccess) { AddScanResult(episodeDetails); } else { NotCatagorized.Add(new ScanNotCatagorized { FilePath = f }); } } MasterMediaDBFactory.PopulateMasterTvMediaDatabase(); }
/// <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 DoWork event of the BackgroundWorker control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param> private void BackgroundWorker_DoWorkRemoveMediaPath(object sender, DoWorkEventArgs e) { var removeModels = (List <MediaPathModel>)e.Argument; foreach (var model in removeModels) { MediaPathDBFactory.RemoveFromDatabase(model); } }
/// <summary> /// Handles the Click event of the BtnAdd 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 BtnAdd_Click(object sender, EventArgs e) { MediaPathDBFactory.AddNewRecord(); var frmEditMediaPath = new FrmEditMediaPath(FrmEditMediaPath.MediaPathActionType.Add); frmEditMediaPath.ShowDialog(this); grdViewMain.RefreshData(); // ButRefresh_Click(null, null); }
/// <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> /// The edit current row. /// </summary> private void EditCurrentRow() { int[] selectedRows = this.grdViewMain.GetSelectedRows(); if (selectedRows.Length == 0) { return; } MediaPathDBFactory.EditRecord(this.grdViewMain.GetRow(selectedRows[0]) as MediaPathModel); var frmEditMediaPath = new FrmEditMediaPath(FrmEditMediaPath.MediaPathActionType.Edit); frmEditMediaPath.ShowDialog(this); }
/// <summary> /// Handles the Click event of the BtnDelete 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 BtnDelete_Click(object sender, EventArgs e) { DialogResult result = XtraMessageBox.Show( this, string.Format( "Are you sure you wish to delete the selected {0} media path(s)?", this.grdViewMain.SelectedRowsCount), "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { foreach (int v in this.grdViewMain.GetSelectedRows()) { var row = this.grdViewMain.GetRow(v) as MediaPathModel; MediaPathDBFactory.RemoveFromDatabase(row); } } }
/// <summary> /// BTNs the ok click. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void BtnOkClick(object sender, EventArgs e) { if (chkFolderContainsMovies.Checked == false && chkFolderContainsTvShows.Checked == false) { XtraMessageBox.Show("Please select an import type"); return; } this.Close(); if (actionType == MediaPathActionType.Add) { MediaPathDBFactory.CommitNewRecord(); } else if (actionType == MediaPathActionType.Edit) { MediaPathDBFactory.CommitChangedRecord(); } ImportFiles.ScanMediaPath(MediaPathDBFactory.CurrentMediaPath); }
/// <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> /// Handles the DoWork event of the BackgroundWorker control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param> private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { MediaPathDBFactory.RefreshFiles(this.currentProgress); }
/// <summary> /// The setup bindings. /// </summary> public void SetupBindings() { this.grdMediaPathList.DataSource = MediaPathDBFactory.MediaPathDB; this.grdMediaPathUnsortedMovies.DataSource = MediaPathDBFactory.GetMediaPathMoviesUnsorted(); this.grdMediaPathUnsortedTv.DataSource = MediaPathDBFactory.GetMediaPathTvUnsorted(); }
/// <summary> /// Add scan result. /// </summary> /// <param name="episodeDetails"> /// The episode details. /// </param> public static void AddScanResult(EpisodeDetails episodeDetails) { var seriesName = episodeDetails.SeriesName; var name = seriesName; var check1 = (from s in Scan where s.Key.ToLower() == name.ToLower() select s.Key).SingleOrDefault(); // Process Series if (check1 == null) { Scan.Add(seriesName, new ScanSeries()); var check2 = (from s in SeriesNameList where s.SeriesName.ToLower() == seriesName.ToLower() select s.SeriesName.ToLower()).ToList(); if (!check2.Contains(seriesName.ToLower()) && !string.IsNullOrEmpty(seriesName)) { string dir = Directory.GetParent(episodeDetails.FilePath).Name; string path = string.Empty; if (dir.StartsWith("season", true, System.Globalization.CultureInfo.CurrentCulture)) { // Looks like it. Qualified series guess path = Directory.GetParent(episodeDetails.FilePath).Parent.FullName; } else { // Best guess path = Directory.GetParent(episodeDetails.FilePath).FullName; } SeriesNameList.Add( new SeriesListModel { WaitingForScan = true, SeriesName = seriesName, SeriesPath = path }); } } else { seriesName = check1; } // Process Series if (!Scan[seriesName].Seasons.ContainsKey(episodeDetails.SeasonNumber)) { Scan[seriesName].Seasons.Add(episodeDetails.SeasonNumber, new ScanSeason()); } if ( !Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.ContainsKey( episodeDetails.EpisodeNumber)) { Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.Add( episodeDetails.EpisodeNumber, new ScanEpisode()); } Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[episodeDetails.EpisodeNumber]. FilePath = episodeDetails.FilePath; if (episodeDetails.SecondaryNumbers.Count > 0) { foreach (int secondary in episodeDetails.SecondaryNumbers) { if ( !Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.ContainsKey( secondary)) { Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.Add( secondary, new ScanEpisode()); } Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].FilePath = episodeDetails.FilePath; Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].Secondary = true; Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].SecondaryTo = episodeDetails.EpisodeNumber; } } var findList = (from s in MediaPathDBFactory.GetMediaPathTvUnsorted() where s.PathAndFileName == episodeDetails.FilePath select s).ToList(); foreach (var path in findList) { MediaPathDBFactory.GetMediaPathTvUnsorted().Remove(path); } }
/// <summary> /// Add scan result. /// </summary> /// <param name="episodeDetails"> /// The episode details. /// </param> public static void AddScanResult(EpisodeDetails episodeDetails) { var seriesName = episodeDetails.SeriesName; var name = seriesName; var check1 = (from s in Scan where s.Key.ToLower() == name.ToLower() select s.Key).SingleOrDefault(); // Process Series if (check1 == null) { Scan.Add(seriesName, new ScanSeries()); var check2 = (from s in SeriesNameList where s.SeriesName.ToLower() == seriesName.ToLower() select s.SeriesName.ToLower()).ToList(); if (!check2.Contains(seriesName.ToLower())) { SeriesNameList.Add( new SeriesListModel { WaitingForScan = true, SeriesName = seriesName }); } } else { seriesName = check1; } // Process Series if (!Scan[seriesName].Seasons.ContainsKey(episodeDetails.SeasonNumber)) { Scan[seriesName].Seasons.Add(episodeDetails.SeasonNumber, new ScanSeason()); } if ( !Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.ContainsKey( episodeDetails.EpisodeNumber)) { Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.Add( episodeDetails.EpisodeNumber, new ScanEpisode()); } Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[episodeDetails.EpisodeNumber]. FilePath = episodeDetails.FilePath; if (episodeDetails.SecondaryNumbers.Count > 0) { foreach (int secondary in episodeDetails.SecondaryNumbers) { if ( !Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.ContainsKey( secondary)) { Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.Add( secondary, new ScanEpisode()); } Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].FilePath = episodeDetails.FilePath; Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].Secondary = true; Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].SecondaryTo = episodeDetails.EpisodeNumber; } } var findList = (from s in MediaPathDBFactory.GetMediaPathTvUnsorted() where s.PathAndFileName == episodeDetails.FilePath select s).ToList(); foreach (var path in findList) { MediaPathDBFactory.GetMediaPathTvUnsorted().Remove(path); } }
/// <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(); }