protected override void DoCheck(SetProgressDelegate prog, TVDoc.ScanSettings settings) { DirFilesCache dfc = new DirFilesCache(); foreach (IDownloadProvider source in sources) { List <TorrentEntry>?downloads = source.GetTorrentDownloads(); if (downloads is null) { continue; } IEnumerable <IGrouping <string, TorrentEntry> > keys = downloads.GroupBy(entry => entry.DownloadingTo); foreach (IGrouping <string, TorrentEntry> torrentKey in keys) { if (torrentKey.All(entry => CanRemove(entry, dfc))) { if (lastFoundEntry != null && lastFoundEpisode != null) { MDoc.TheActionList.Add(new ActionTRemove(source, lastFoundEntry, lastFoundEpisode)); } if (lastFoundEntry != null && lastFoundMovie != null) { MDoc.TheActionList.Add(new ActionTRemove(source, lastFoundEntry, lastFoundMovie)); } } lastFoundEntry = null; lastFoundEpisode = null; lastFoundMovie = null; } } }
private void RetrieveData() { try { for (int i = 5; i <= 100; i += 5) { Thread.Sleep(500); SetProgressDelegate setProgress = new SetProgressDelegate(abortDialog.SetProgress); BeginInvoke(setProgress, new object[] { i }); } string [] results = new String[1]; results[0] = @"Apress is a great book publisher! Check out ASP Today at http://www.asptoday.com for articles about advanced ASP.NET coding Latest articles: Building a Media Encoding System Part 3 Project Estimation for Developers"; ResultsReturnedDelegate resultsReturned = new ResultsReturnedDelegate(this.OnResultsReturned); BeginInvoke(resultsReturned, results); } finally { // Simulate it takes a short time to and clean up resources Thread.Sleep(1000); } }
public void CheckFolders(CancellationToken token, [NotNull] SetProgressDelegate prog, bool detailedLogging, bool showErrorMsgBox) { // Check the folder list, and build up a new "AddItems" list. // guessing what the shows actually are isn't done here. That is done by // calls to "GuessShowItem" Logger.Info("*********************************************************************"); Logger.Info("*Starting to find folders that contain files, but are not in library*"); AddItems = new FolderMonitorEntryList(); int c = TVSettings.Instance.LibraryFolders.Count; int c2 = 0; foreach (string folder in TVSettings.Instance.LibraryFolders) { prog.Invoke(100 * c2++ / c, folder); DirectoryInfo di = new DirectoryInfo(folder); CheckFolderForShows(di, token, detailedLogging, showErrorMsgBox); if (token.IsCancellationRequested) { break; } } prog.Invoke(100, string.Empty); }
protected override void DoCheck(SetProgressDelegate prog, ICollection <ShowItem> showList, TVDoc.ScanSettings settings) { // have a look around for any missing episodes List <Finder> appropriateFinders = finders.Where(f => f.DisplayType() == CurrentType() && f.Active()).ToList(); int currentMatchingFinderId = 0; int totalMatchingFinders = appropriateFinders.Count; foreach (Finder f in appropriateFinders) { if (settings.Token.IsCancellationRequested) { return; } if (!MDoc.TheActionList.MissingItems().Any()) { continue; } f.ActionList = MDoc.TheActionList; currentMatchingFinderId++; int startPos = 100 * (currentMatchingFinderId - 1) / totalMatchingFinders; int endPos = 100 * currentMatchingFinderId / totalMatchingFinders; f.Check(prog, startPos, endPos, showList, settings); MDoc.RemoveIgnored(); } }
public uTorrent(TVDoc doc, SetProgressDelegate progdel) { this.mDoc = doc; this.SetProg = progdel; this.InitializeComponent(); this.watcher.Error += this.WatcherError; bool en = false; // are there any missing items in the to-do list? foreach (Item i in this.mDoc.TheActionList) { if (i is ItemMissing) { en = true; break; } } this.cbUTMatchMissing.Enabled = en; this.EnableDisable(); this.bnUTRefresh_Click(null, null); }
protected override void DoCheck(SetProgressDelegate prog, TVDoc.ScanSettings settings) { BulkAddSeriesManager bam = new BulkAddSeriesManager(MDoc); bam.CheckFolders(settings.Token, prog, false, !settings.Unattended); AskUserAboutShows(settings, bam); if (!bam.AddItems.Any(s => s.CodeKnown)) { return; } var idsToAdd = bam.AddItems.Where(s => s.CodeKnown).Select(folder => new { Code = folder.ProviderCode, folder.Provider }).ToList(); bam.AddAllToMyShows(); List <ShowConfiguration> addedShows = idsToAdd.Select(s => MDoc.TvLibrary.GetShowItem(s.Code, s.Provider)).ToList(); //add each new show into the shows being scanned foreach (ShowConfiguration si in addedShows) { settings.Shows.Add(si); } LOGGER.Info("Added new shows called: {0}", addedShows.Select(si => si.ShowName).ToCsv()); MDoc.TvAddedOrEdited(true, settings.Unattended, settings.Hidden, settings.Owner, addedShows); }
protected override void DoCheck(SetProgressDelegate prog, ICollection <ShowItem> showList, TVDoc.ScanSettings settings) { // get list of files being downloaded by uTorrent string resDatFile = TVSettings.Instance.ResumeDatPath; if (string.IsNullOrEmpty(resDatFile) || !File.Exists(resDatFile)) { return; } try { BTResume btr = new BTResume(prog, resDatFile); if (!btr.LoadResumeDat()) { return; } List <TorrentEntry> downloading = btr.AllFilesBeingDownloaded(); SearchForAppropriateDownloads(downloading, DownloadApp.uTorrent, settings); } catch (FormatException fex) { LOGGER.Error($"Got a format exception accessing {resDatFile}, message: {fex.Message}"); } }
protected override void DoCheck(SetProgressDelegate progress) { IEnumerable <ShowConfiguration> libraryShows = MDoc.TvLibrary.Shows.ToList(); int totalRecords = libraryShows.Count() + MDoc.FilmLibrary.Count; int n = 0; foreach (ShowConfiguration si in libraryShows) { UpdateStatus(n++, totalRecords, si.ShowName); foreach (string folderName in si.AllProposedFolderLocations().SelectMany(folderLocation => folderLocation.Value)) { RemoveIfEmpty(folderName); } } foreach (MovieConfiguration mi in MDoc.FilmLibrary.Movies) { UpdateStatus(n++, totalRecords, mi.ShowName); foreach (string folderName in mi.Locations) { RemoveIfEmpty(folderName); } } }
protected override void DoCheck(SetProgressDelegate prog, ICollection <ShowItem> shows, TVDoc.ScanSettings settings) { returnActions = new List <Item>(); showList = MDoc.Library.GetShowItems(); //We ignore the current set of shows being scanned to be secrure that no files are deleted for unscanned shows currentSettings = settings; //for each directory in settings directory //for each file in directory //for each saved show (order by recent) //is file already available? //if so add show to list of files to be removed int totalDownloadFolders = TVSettings.Instance.DownloadFolders.Count; int c = 0; foreach (string dirPath in TVSettings.Instance.DownloadFolders.ToList()) { UpdateStatus(c++, totalDownloadFolders, dirPath); if (!Directory.Exists(dirPath) || currentSettings.Token.IsCancellationRequested) { continue; } filesThatMayBeNeeded = new List <FileInfo>(); ReviewFilesInDownloadDirectory(dirPath); ReviewDirsInDownloadDirectory(dirPath); } MDoc.TheActionList.AddNullableRange(returnActions); }
protected override void DoCheck([NotNull] SetProgressDelegate prog, ICollection <ShowItem> showList, TVDoc.ScanSettings settings) { BulkAddManager bam = new BulkAddManager(MDoc); bam.CheckFolders(settings.Token, prog, false, !settings.Unattended); AskUserAboutShows(settings, bam); if (!bam.AddItems.Any(s => s.CodeKnown)) { return; } List <int> idsToAdd = bam.AddItems.Where(s => s.CodeKnown).Select(folder => folder.TVDBCode).ToList(); bam.AddAllToMyShows(); MDoc.SetDirty(); MDoc.DoDownloadsFG(settings.Unattended, settings.Hidden); List <ShowItem> addedShows = idsToAdd.Select(s => MDoc.Library.ShowItem(s)).ToList(); //add each new show into the shows being scanned foreach (ShowItem si in addedShows) { showList.Add(si); } LOGGER.Info("Added new shows called: {0}", addedShows.Select(si => si?.ShowName).ToCsv()); MDoc.DoWhenToWatch(true, settings.Unattended, settings.Hidden); MDoc.WriteUpcoming(); MDoc.WriteRecent(); }
private int BuildDirCache(SetProgressDelegate prog, int count, int totalFiles, string folder, bool subFolders) { if (!Directory.Exists(folder)) { logger.Error("The search folder \"" + folder + " does not exist."); return(count); } try { /* * if (folder.Length >= 248) * * { * logger.Error ("Skipping folder that has a name longer than the Windows permitted 247 characters: " + folder); * return count; * } * */ DirectoryInfo di = new DirectoryInfo(folder); if (!di.Exists) { return(count); } // DirectorySecurity ^ds = di->GetAccessControl(); FileInfo[] f2 = di.GetFiles(); foreach (FileInfo ff in f2) { count++; // if ((ff.Name.Length + folder.Length) >= 260) // logger.Error("Skipping file that has a path+name longer than the Windows permitted 259 characters: " + ff.Name + " in " + folder); // else this.Add(new DirCacheEntry(ff)); if ((prog != null) && (totalFiles != 0)) { prog.Invoke(100 * (count) / totalFiles); } } if (subFolders) { DirectoryInfo[] dirs = di.GetDirectories(); foreach (DirectoryInfo di2 in dirs) { count = this.BuildDirCache(prog, count, totalFiles, di2.FullName, subFolders); } } } catch (UnauthorizedAccessException e) { logger.Info(e); } catch (Exception exception) { logger.Error(exception); } return(count); }
protected override void DoCheck(SetProgressDelegate prog, TVDoc.ScanSettings settings) { if (TVSettings.Instance.SearchJSONManualScanOnly && settings.Unattended) { LOGGER.Info("Searching JSON Wepages is cancelled as this is an unattended scan"); return; } int c = ActionList.Missing.Count + 1; int n = 0; UpdateStatus(n, c, "Searching on JSON Page..."); ItemList newItems = new ItemList(); ItemList toRemove = new ItemList(); UrlCache cache = new UrlCache(); try { foreach (ShowItemMissing action in ActionList.MissingEpisodes.ToList()) { if (settings.Token.IsCancellationRequested) { return; } UpdateStatus(n++, c, action.Filename); FindMissingEpisode(action, toRemove, newItems, cache); } } catch (WebException e) { LOGGER.LogWebException( $"Failed to access: {TVSettings.Instance.SearchJSONURL} got the following message:", e); } catch (AggregateException aex) when(aex.InnerException is WebException ex) { LOGGER.LogWebException( $"Failed to access: {TVSettings.Instance.SearchJSONURL} got the following message:", ex); } catch (AggregateException ex) when(ex.InnerException is HttpRequestException hex) { LOGGER.LogHttpRequestException($"Could not download RSS page at: {TVSettings.Instance.SearchJSONURL} got the following message: ", hex); } catch (HttpRequestException htec) when(htec.InnerException is WebException ex) { LOGGER.LogWebException( $"Failed to access: {TVSettings.Instance.SearchJSONURL} got the following message:", ex); } catch (HttpRequestException htec) { LOGGER.Warn($"Failed to access: {TVSettings.Instance.SearchJSONURL} got the following message: {htec.Message}"); } catch (JsonReaderException ex) { LOGGER.Warn(ex, $"Failed to Parse {TVSettings.Instance.SearchJSONURL} into JSON - Please check that the URL is valid JSON format."); } ActionList.Replace(toRemove, newItems); }
private void ScanWorker(object o) { try { ScanSettings settings = (ScanSettings)o; //When doing a full scan the show list is null indicating that all shows should be checked List <ShowItem> specific = settings.Shows ?? Library.Values.ToList(); while (!Args.Hide && Environment.UserInteractive && ((scanProgDlg is null) || (!scanProgDlg.Ready))) { Thread.Sleep(10); // wait for thread to create the dialog } TheActionList = new ItemList(); SetProgressDelegate noProgress = NoProgress; if (!settings.Unattended && settings.Type != TVSettings.ScanType.SingleShow) { new FindNewShowsInDownloadFolders(this).Check((scanProgDlg is null) ? noProgress : scanProgDlg.AddNewProg, 0, 50, specific, settings); new FindNewShowsInLibrary(this).Check((scanProgDlg is null) ? noProgress : scanProgDlg.AddNewProg, 50, 100, specific, settings); } new CheckShows(this).Check((scanProgDlg is null) ? noProgress : scanProgDlg.MediaLibProg, specific, settings); new CleanDownloadDirectory(this).Check((scanProgDlg is null) ? noProgress : scanProgDlg.DownloadFolderProg, specific, settings); localFinders.Check((scanProgDlg is null) ? noProgress : scanProgDlg.LocalSearchProg, specific, settings); downloadFinders.Check((scanProgDlg is null) ? noProgress : scanProgDlg.DownloadingProg, specific, settings); searchFinders.Check((scanProgDlg is null)? noProgress : scanProgDlg.ToBeDownloadedProg, specific, settings); if (settings.Token.IsCancellationRequested) { TheActionList.Clear(); LastScanComplete = false; return; } // sort Action list by type TheActionList.Sort(new ActionItemSorter()); // was new ActionSorter() Stats().FindAndOrganisesDone++; lastScanType = settings.Type; LastScanComplete = true; } catch (TVRenameOperationInterruptedException) { Logger.Warn("Scan cancelled by user"); TheActionList.Clear(); LastScanComplete = false; } catch (Exception e) { Logger.Fatal(e, "Unhandled Exception in ScanWorker"); LastScanComplete = false; } finally { scanProgDlg?.Done(); } }
private int BuildDirCache(SetProgressDelegate prog, int count, int totalFiles, string folder, bool subFolders) { if (!Directory.Exists(folder)) { MessageBox.Show("The search folder \"" + folder + " does not exist.\n", "Folder does not exist", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(count); } try { if (folder.Length >= 248) { MessageBox.Show("Skipping folder that has a name longer than the Windows permitted 247 characters: " + folder, "Path name too long", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(count); } DirectoryInfo di = new DirectoryInfo(folder); if (!di.Exists) { return(count); } // DirectorySecurity ^ds = di->GetAccessControl(); FileInfo[] f2 = di.GetFiles(); foreach (FileInfo ff in f2) { count++; if ((ff.Name.Length + folder.Length) >= 260) { MessageBox.Show("Skipping file that has a path+name longer than the Windows permitted 259 characters: " + ff.Name + " in " + folder, "File+Path name too long", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { this.Add(new DirCacheEntry(ff)); } if ((prog != null) && (totalFiles != 0)) { prog.Invoke(100 * (count) / totalFiles); } } if (subFolders) { DirectoryInfo[] dirs = di.GetDirectories(); foreach (DirectoryInfo di2 in dirs) { count = this.BuildDirCache(prog, count, totalFiles, di2.FullName, subFolders); } } } catch (UnauthorizedAccessException) { } catch { } return(count); }
public override void Check(SetProgressDelegate prog, int startpct, int totPct) { int c = this.TheActionList.Count + 2; int n = 1; prog.Invoke(100 * n / c); RSSItemList RSSList = new RSSItemList(); foreach (string s in TVSettings.Instance.RSSURLs) { RSSList.DownloadRSS(s, TVSettings.Instance.FNPRegexs); } ItemList newItems = new ItemList(); ItemList toRemove = new ItemList(); foreach (Item Action1 in this.TheActionList) { if (this.ActionCancel) { return; } n++; prog.Invoke(100 * n / c); if (!(Action1 is ItemMissing)) { continue; } ItemMissing Action = (ItemMissing)(Action1); ProcessedEpisode pe = Action.Episode; string simpleShowName = Helpers.SimplifyName(pe.SI.ShowName); string simpleSeriesName = Helpers.SimplifyName(pe.TheSeries.Name); foreach (RSSItem rss in RSSList) { if ((FileHelper.SimplifyAndCheckFilename(rss.ShowName, simpleShowName, true, false) || (string.IsNullOrEmpty(rss.ShowName) && FileHelper.SimplifyAndCheckFilename(rss.Title, simpleSeriesName, true, false))) && (rss.Season == pe.SeasonNumber) && (rss.Episode == pe.EpNum)) { newItems.Add(new ActionRSS(rss, Action.TheFileNoExt, pe)); toRemove.Add(Action1); } } } foreach (Item i in toRemove) { this.TheActionList.Remove(i); } foreach (Item Action in newItems) { this.TheActionList.Add(Action); } prog.Invoke(100); }
protected override void DoCheck(SetProgressDelegate prog, TVDoc.ScanSettings settings) { if (settings.Unattended && TVSettings.Instance.SearchJackettManualScanOnly) { LOGGER.Info("Searching Jackett is cancelled as this is an unattended scan"); return; } if (settings.Type == TVSettings.ScanType.Full && TVSettings.Instance.StopJackettSearchOnFullScan && settings.Shows.Any()) { LOGGER.Info("Searching Jackett is cancelled as this is a full scan"); return; } int c = ActionList.Missing.Count + 2; int n = 1; UpdateStatus(n, c, "Searching with Jackett..."); ItemList newItems = new ItemList(); ItemList toRemove = new ItemList(); try { foreach (ItemMissing action in ActionList.Missing.ToList()) { if (settings.Token.IsCancellationRequested) { return; } UpdateStatus(n++, c, action.Filename); if (action is ShowItemMissing showItemMissing) { FindMissingEpisode(showItemMissing, toRemove, newItems); } else { FindMissingEpisode((MovieItemMissing)action, toRemove, newItems); } } } catch (WebException e) { LOGGER.LogWebException($"Failed to access: {e.Response.ResponseUri} got the following message:", e); } catch (AggregateException aex) when(aex.InnerException is WebException ex) { LOGGER.LogWebException($"Failed to access: {ex.Response.ResponseUri} got the following message:", ex); } catch (HttpRequestException htec) when(htec.InnerException is WebException ex) { LOGGER.LogWebException($"Failed to access: {ex.Response.ResponseUri} got the following message:", ex); } ActionList.Replace(toRemove, newItems); }
public TorrentMatch(TVDoc doc, SetProgressDelegate prog) { SetProgress = prog; mDoc = doc; InitializeComponent(); TabBTEnableDisable(); }
protected BTCore(SetProgressDelegate setprog) { SetProg = setprog; HashCache = new Dictionary <string, List <HashCacheItem> >(); FileCache = null; FileCacheIsFor = null; FileCacheWithSubFolders = false; }
protected override void DoCheck(SetProgressDelegate prog, TVDoc.ScanSettings settings) { ItemList newList = new ItemList(); ItemList toRemove = new ItemList(); DirFilesCache dfc = new DirFilesCache(); int currentItem = 0; int totalN = ActionList.Missing.Count + 1; UpdateStatus(currentItem, totalN, "Starting searching through library looking for files"); LOGGER.Info("Starting to look for missing items in the library"); foreach (var me in ActionList.MissingEpisodes.ToList()) { if (settings.Token.IsCancellationRequested) { return; } UpdateStatus(currentItem++, totalN, me.Filename); ItemList thisRound = new ItemList(); if (me.Episode?.Show is null) { LOGGER.Info($"Not looking for {me.Filename} in the library as the show/episode is null"); continue; } string baseFolder = me.Episode.Show.AutoAddFolderBase; LOGGER.Info($"Starting to look for {me.Filename} in the library: {baseFolder}"); List <FileInfo> matchedFiles = GetMatchingFilesFromFolder(baseFolder, dfc, me, settings, thisRound); foreach (string folderName in me.Episode.Show.AllFolderLocationsEpCheck(false) .Where(folders => folders.Value != null) .Where(folders => folders.Key == me.Episode.AppropriateProcessedSeason.SeasonNumber) .SelectMany(seriesFolders => seriesFolders.Value .Where(f => !string.IsNullOrWhiteSpace(f)) //No point looking here .Where(f => f != baseFolder))) { ProcessFolder(settings, me, folderName, dfc, thisRound, matchedFiles); } ProcessMissingItem(settings, newList, toRemove, me, thisRound, matchedFiles, TVSettings.Instance.UseFullPathNameToMatchLibraryFolders); } if (TVSettings.Instance.KeepTogether) { KeepTogether(newList, true); } ReorganiseToLeaveOriginals(newList); ActionList.Replace(toRemove, newList); }
public TorrentMatch(TVDoc doc, SetProgressDelegate prog) { this.SetProgress = prog; this.mDoc = doc; this.InitializeComponent(); this.TabBTEnableDisable(); }
protected override void DoCheck(SetProgressDelegate prog, TVDoc.ScanSettings settings) { //for each directory in settings directory //for each file in directory //for each saved show (order by recent) //does show match selected file? //if so add cachedSeries to list of cachedSeries scanned if (!Active()) { LOGGER.Info("Not looking for new media as 'Auto-Add' is turned off"); return; } //Don't support unattended mode if (settings.Unattended || settings.Hidden) { LOGGER.Info("Not looking for new media as app is unattended"); return; } IEnumerable <FileInfo> possibleShowNames = GetPossibleShowNameStrings(); List <MediaConfiguration> addedShows = FinderHelper.FindMedia(possibleShowNames, MDoc, settings.Owner); IEnumerable <ShowConfiguration> addedTVShows = addedShows.OfType <ShowConfiguration>(); if (addedTVShows.Any()) { MDoc.TvLibrary.AddRange(addedTVShows); MDoc.ShowAddedOrEdited(false, false, false, settings.Owner); MDoc.ShowAddedOrEdited(true, false, false, settings.Owner); //add each new show into the shows being scanned foreach (ShowConfiguration si in addedTVShows) { settings.Shows.Add(si); } LOGGER.Info("Added new shows called: {0}", addedTVShows.Select(s => s.ShowName).ToCsv()); } IEnumerable <MovieConfiguration> addedMovies = addedShows.OfType <MovieConfiguration>(); if (addedMovies.Any()) { MDoc.FilmLibrary.AddRange(addedMovies); MDoc.MovieAddedOrEdited(false, false, false, settings.Owner); MDoc.MovieAddedOrEdited(true, false, false, settings.Owner); foreach (MovieConfiguration si in addedMovies) { settings.Movies.Add(si); } LOGGER.Info("Added new movies called: {0}", addedMovies.Select(s => s.ShowName).ToCsv()); } }
private void SetProgress(long percent) { if (this.progressBar.InvokeRequired) { SetProgressDelegate callback = new SetProgressDelegate(SetProgress); this.Invoke(callback, new object[] { percent }); return; } this.progressBar.Value = (int)percent; }
protected override void DoCheck(SetProgressDelegate prog, TVDoc.ScanSettings settings) { List <TorrentEntry>?downloading = source.GetTorrentDownloads(); if (downloading is null) { LOGGER.Warn($"Failed to get current downloads from {source.Name()}"); return; } SearchForAppropriateDownloads(downloading, DownloadApp.qBitTorrent, settings); }
protected override void DoCheck(SetProgressDelegate prog, TVDoc.ScanSettings settings) { if (TVSettings.Instance.SearchRSSManualScanOnly && settings.Unattended) { LOGGER.Info("Searching RSS Feeds is cancelled as this is an unattended scan"); return; } int c = ActionList.Missing.Count + 2; int n = 1; UpdateStatus(n, c, "Searching on RSS Feed..."); // ReSharper disable once InconsistentNaming RssItemList RSSList = new RssItemList(); foreach (string s in TVSettings.Instance.RSSURLs) { RSSList.DownloadRSS(s, TVSettings.Instance.RSSUseCloudflare, "RSS"); } ItemList newItems = new ItemList(); ItemList toRemove = new ItemList(); foreach (ShowItemMissing action in ActionList.MissingEpisodes.ToList()) { if (settings.Token.IsCancellationRequested) { return; } UpdateStatus(n++, c, action.Filename); ProcessedEpisode pe = action.MissingEpisode; ItemList newItemsForThisMissingEpisode = new ItemList(); foreach (RSSItem rss in RSSList.Where(rss => RssMatch(rss, pe))) { LOGGER.Info( $"Adding {rss.URL} from RSS feed as it appears to be match for {pe.Show.ShowName} {pe}"); ItemDownloading eventualItem = new ItemDownloading(new FutureTorrentEntry(rss.URL, action.TheFileNoExt), action.MissingEpisode, action.TheFileNoExt, DownloadingFinder.DownloadApp.qBitTorrent, action); newItemsForThisMissingEpisode.Add(new ActionTDownload(rss, action, eventualItem)); toRemove.Add(action); } foreach (ActionTDownload x in FindDuplicates(newItemsForThisMissingEpisode)) { newItemsForThisMissingEpisode.Remove(x); } newItems.AddNullableRange(newItemsForThisMissingEpisode); } ActionList.Replace(toRemove, newItems); }
protected void SearchForAppropriateDownloads(SetProgressDelegate prog, int startpct, int totPct, List <TorrentEntry> downloading, DownloadApp tApp) { ItemList newList = new ItemList(); ItemList toRemove = new ItemList(); int c = ActionList.Count + 2; int n = 1; prog.Invoke(startpct); foreach (ItemMissing action in ActionList.MissingItems()) { if (ActionCancel) { return; } prog.Invoke(startpct + ((totPct - startpct) * (++n) / (c))); foreach (TorrentEntry te in downloading) { FileInfo file = new FileInfo(te.DownloadingTo); if (!TVSettings.Instance.UsefulExtension(file.Extension, false)) // not a usefile file extension { continue; } //do any of the possible names for the series match the filename? bool matched = (action.Episode.Show.GetSimplifiedPossibleShowNames().Any(name => FileHelper.SimplifyAndCheckFilename(file.FullName, name))); if (!matched) { continue; } if (TVDoc.FindSeasEp(file, out int seasF, out int epF, out int _, action.Episode.Show) && (seasF == action.Episode.AppropriateSeasonNumber) && (epF == action.Episode.AppropriateEpNum)) { toRemove.Add(action); newList.Add(new ItemDownloading(te, action.Episode, action.TheFileNoExt, tApp)); break; } } } foreach (Item i in toRemove) { ActionList.Remove(i); } foreach (Item action in newList) { ActionList.Add(action); } prog.Invoke(totPct); }
protected override void DoCheck(SetProgressDelegate prog, ICollection <ShowItem> showList, TVDoc.ScanSettings settings) { MDoc.TheActionList = new ItemList(); if (TVSettings.Instance.RenameCheck) { MDoc.Stats().RenameChecksDone++; } if (TVSettings.Instance.MissingCheck) { MDoc.Stats().MissingChecksDone++; } if (settings.Type == TVSettings.ScanType.Full) { // only do episode count if we're doing all shows and seasons MDoc.CurrentStats.NsNumberOfEpisodes = 0; showList = MDoc.Library.Values; } DirFilesCache dfc = new DirFilesCache(); int c = 0; UpdateStatus(c, showList.Count, "Checking shows"); foreach (ShowItem si in showList.OrderBy(item => item.ShowName)) { UpdateStatus(c++, showList.Count, si.ShowName); if (settings.Token.IsCancellationRequested) { return; } LOGGER.Info("Rename and missing check: " + si.ShowName); try { new CheckAllFoldersExist(MDoc).CheckIfActive(si, dfc, settings); new MergeLibraryEpisodes(MDoc).CheckIfActive(si, dfc, settings); new RenameAndMissingCheck(MDoc).CheckIfActive(si, dfc, settings); } catch (TVRenameOperationInterruptedException) { throw; } catch (Exception e) { LOGGER.Error(e, $"Failed to scan {si.ShowName}. Please double check settings for this show: {si.TvdbCode}: {si.AutoAddFolderBase}"); } } // for each show MDoc.RemoveIgnored(); }
private void SetMax(ProgressBar p, int value) { if (p.InvokeRequired) { var d = new SetProgressDelegate(SetMax); this.Invoke(d, new object[] { p, value }); } else { p.Maximum = value; } }
public void SetProgress(int val) { if (progressBar1.InvokeRequired) { SetProgressDelegate del = new SetProgressDelegate(SetProgress); this.Invoke(del, new object[] { val }); } else { progressBar1.Value = val; } }
protected override void DoCheck(SetProgressDelegate prog, ICollection <ShowItem> showList, TVDoc.ScanSettings settings) { if (string.IsNullOrEmpty(TVSettings.Instance.SABAPIKey) || string.IsNullOrEmpty(TVSettings.Instance.SABHostPort)) { LOGGER.Info("Searching SABnzxdb Feeds is cancelled as the key and host/port are notprovided in Preferences."); return; } // get list of files being downloaded by SABnzbd XElement x = GetSabDownload(TVSettings.Instance.SABAPIKey, TVSettings.Instance.SABHostPort); if (x is null) { return; } ItemList newList = new ItemList(); ItemList toRemove = new ItemList(); int c = ActionList.MissingItems().Count() + 1; int n = 0; foreach (ItemMissing action in ActionList.MissingItems().ToList()) { if (settings.Token.IsCancellationRequested) { return; } UpdateStatus(n++, c, action.Filename); if (action.Episode?.Show is null) { continue; } string simpleShowName = Helpers.SimplifyName(action.Episode.Show.ShowName); if (string.IsNullOrWhiteSpace(simpleShowName)) { continue; } foreach (QueueSlotsSlot te in x.Descendants("slots").Select(slot => CreateQueueSlotsSlot(slot, simpleShowName, action)).Where(te => !(te is null))) { toRemove.Add(action); newList.Add(new ItemDownloading(te, action.Episode, action.TheFileNoExt, DownloadApp.SABnzbd)); break; } } ActionList.Replace(toRemove, newList); }
protected override void DoCheck(SetProgressDelegate prog, ICollection <ShowItem> showList, TVDoc.ScanSettings settings) { ItemList newList = new ItemList(); ItemList toRemove = new ItemList(); int fileCount = CountFilesInDownloadDirs(); DirCache dirCache = new DirCache(); foreach (string s in TVSettings.Instance.DownloadFolders.ToList()) { if (settings.Token.IsCancellationRequested) { return; } dirCache.AddFolder(prog, 0, fileCount, s, true); } int currentItem = 0; int totalN = ActionList.MissingItems().Count() + 1; UpdateStatus(currentItem, totalN, "Starting searching through files"); foreach (ItemMissing me in ActionList.MissingItems().ToList()) { if (settings.Token.IsCancellationRequested) { return; } UpdateStatus(currentItem++, totalN, me.Filename); ItemList thisRound = new ItemList(); List <FileInfo> matchedFiles = FindMatchedFiles(settings, dirCache, me, thisRound); ProcessMissingItem(settings, newList, toRemove, me, thisRound, matchedFiles, TVSettings.Instance.UseFullPathNameToMatchSearchFolders); } if (TVSettings.Instance.KeepTogether) { KeepTogether(newList, false); } if (!TVSettings.Instance.LeaveOriginals) { ReorganiseToLeaveOriginals(newList); } ActionList.Replace(toRemove, newList); }
public void LookForMissingEps(SetProgressDelegate prog) { // for each ep we have noticed as being missing // look through the monitored folders for it this.Stats().FindAndOrganisesDone++; prog.Invoke(0); ItemList newList = new ItemList(); ItemList toRemove = new ItemList(); int fileCount = 0; foreach (string s in this.SearchFolders) fileCount += DirCache.CountFiles(s, true); int c = 0; DirCache dirCache = new DirCache(); foreach (String s in this.SearchFolders) { if (this.ActionCancel) return; c = dirCache.AddFolder(prog, c, fileCount, s, true, this.Settings); } c = 0; int totalN = this.TheActionList.Count; foreach (Item action1 in this.TheActionList) { if (this.ActionCancel) return; prog.Invoke(50 + 50 * (++c) / (totalN + 1)); // second 50% of progress bar if (action1 is ItemMissing) { if (this.FindMissingEp(dirCache, (ItemMissing) (action1), newList, ActionCopyMoveRename.Op.Copy)) toRemove.Add(action1); } } if (this.Settings.KeepTogether) this.KeepTogether(newList); prog.Invoke(100); if (!this.Settings.LeaveOriginals) { // go through and change last of each operation on a given source file to a 'Move' // ideally do that move within same filesystem // sort based on source file, and destination drive, putting last if destdrive == sourcedrive newList.Sort(new ActionItemSorter()); // sort puts all the CopyMoveRenames together // then set the last of each source file to be a move for (int i = 0; i < newList.Count; i++) { ActionCopyMoveRename cmr1 = newList[i] as ActionCopyMoveRename; bool ok1 = cmr1 != null; if (!ok1) continue; bool last = i == (newList.Count - 1); ActionCopyMoveRename cmr2 = !last ? newList[i + 1] as ActionCopyMoveRename : null; bool ok2 = cmr2 != null; if (ok2) { ActionCopyMoveRename a1 = cmr1; ActionCopyMoveRename a2 = cmr2; if (!Helpers.Same(a1.From, a2.From)) a1.Operation = ActionCopyMoveRename.Op.Move; } else { // last item, or last copymoverename item in the list ActionCopyMoveRename a1 = cmr1; a1.Operation = ActionCopyMoveRename.Op.Move; } } } foreach (Item i in toRemove) this.TheActionList.Remove(i); foreach (Item i in newList) this.TheActionList.Add(i); // if (Settings->ExportFOXML) // ExportFOXML(Settings->ExportFOXMLTo); }
public abstract void Check(SetProgressDelegate prog, int startpct, int totPct);
public static bool DownloadVersion(string URL, string outputPath, SetToolTipDelegate SetToolTip, SetProgressDelegate SetProgressMax, SetProgressDelegate AddProgressValue) { try { SetToolTip("Downloading " + URL); WebRequest objRequest = System.Net.HttpWebRequest.Create(URL); WebResponse objResponse = objRequest.GetResponse(); SetProgressMax((int)objResponse.ContentLength); using (BinaryReader inputReader = new BinaryReader(objResponse.GetResponseStream())) { using (FileStream outputStream = new FileStream(outputPath, FileMode.CreateNew)) { byte[] buffer = new byte[32768]; int read; while ((read = inputReader.Read(buffer, 0, buffer.Length)) > 0) { AddProgressValue(read); outputStream.Write(buffer, 0, read); } } } return true; } catch (Exception e) { SetToolTip("Unable to download " + URL + ": " + e.Message); SystemSounds.Beep.Play(); return false; } }
protected void _SetProgress(int sent, int total) { if( InvokeRequired ) { object[] args = new object[2]; args[0] = sent; args[1] = total; SetProgressDelegate d = new SetProgressDelegate(_SetProgressCallBack); BeginInvoke(d, args); } else { _SetProgressCallBack( sent,total ); } }
public void CheckAgainstuTorrent(SetProgressDelegate prog, int startpct, int totPct) { // get list of files being downloaded by uTorrent string resDatFile = this.Settings.ResumeDatPath; if (string.IsNullOrEmpty(resDatFile) || !File.Exists(resDatFile)) return; BTResume btr = new BTResume(prog, resDatFile); if (!btr.LoadResumeDat(Args)) return; List<TorrentEntry> downloading = btr.AllFilesBeingDownloaded(this.Settings, Args); ItemList newList = new ItemList(); ItemList toRemove = new ItemList(); int c = this.TheActionList.Count + 2; int n = 1; prog.Invoke(startpct + totPct * n / c); foreach (Item Action1 in this.TheActionList) { if (this.ActionCancel) return; n++; prog.Invoke(100 * n / c); if (!(Action1 is ItemMissing)) continue; ItemMissing Action = (ItemMissing) (Action1); string showname = Helpers.SimplifyName(Action.Episode.SI.ShowName); foreach (TorrentEntry te in downloading) { FileInfo file = new FileInfo(te.DownloadingTo); if (!this.Settings.UsefulExtension(file.Extension, false)) // not a usefile file extension continue; if (this.SimplifyAndCheckFilename(file.FullName, showname, true, false)) // if (Regex::Match(simplifiedfname,"\\b"+showname+"\\b",RegexOptions::IgnoreCase)->Success) { int seasF; int epF; if (this.FindSeasEp(file, out seasF, out epF, Action.Episode.SI) && (seasF == Action.Episode.SeasonNumber) && (epF == Action.Episode.EpNum)) { toRemove.Add(Action1); newList.Add(new ItemuTorrenting(te, Action.Episode, Action.TheFileNoExt)); break; } } } } foreach (Item i in toRemove) this.TheActionList.Remove(i); foreach (Item Action in newList) this.TheActionList.Add(Action); prog.Invoke(startpct + totPct); }
public void CheckAgainstSABnzbd(SetProgressDelegate prog, int startpct, int totPct) { if (String.IsNullOrEmpty(Settings.SABAPIKey) || String.IsNullOrEmpty(Settings.SABHostPort)) { prog.Invoke(startpct + totPct); return; } // get list of files being downloaded by SABnzbd // Something like: // http://localhost:8080/sabnzbd/api?mode=queue&apikey=xxx&start=0&limit=8888&output=xml String theURL = "http://" + Settings.SABHostPort + "/sabnzbd/api?mode=queue&start=0&limit=8888&output=xml&apikey=" + Settings.SABAPIKey; WebClient wc = new WebClient(); byte[] r = null; try { r = wc.DownloadData(theURL); } catch (WebException) { } if (r == null) { prog.Invoke(startpct + totPct); return; } try { SAB.result res = SAB.result.Deserialize(r); if (res.status == "False") { MessageBox.Show(res.error, "SABnzbd Queue Check", MessageBoxButtons.OK, MessageBoxIcon.Error); prog.Invoke(startpct + totPct); return; } } catch { // wasn't a result/error combo. this is good! } SAB.queue sq = null; try { sq = SAB.queue.Deserialize(r); } catch (Exception) { MessageBox.Show("Error processing data from SABnzbd", "SABnzbd Queue Check", MessageBoxButtons.OK, MessageBoxIcon.Error); prog.Invoke(startpct + totPct); return; } System.Diagnostics.Debug.Assert(sq != null); // shouldn't happen if (sq == null || sq.slots==null || sq.slots.Length == 0) // empty queue return; ItemList newList = new ItemList(); ItemList toRemove = new ItemList(); int c = this.TheActionList.Count + 2; int n = 1; foreach (Item Action1 in this.TheActionList) { if (this.ActionCancel) return; n++; prog.Invoke(startpct + totPct * n / c); if (!(Action1 is ItemMissing)) continue; ItemMissing Action = (ItemMissing) (Action1); string showname = Helpers.SimplifyName(Action.Episode.SI.ShowName); foreach (SAB.queueSlotsSlot te in sq.slots) { //foreach (queueSlotsSlot te in qs) { FileInfo file = new FileInfo(te.filename); //if (!this.Settings.UsefulExtension(file.Extension, false)) // not a usefile file extension // continue; if (this.SimplifyAndCheckFilename(file.FullName, showname, true, false)) // if (Regex::Match(simplifiedfname,"\\b"+showname+"\\b",RegexOptions::IgnoreCase)->Success) { int seasF; int epF; if (this.FindSeasEp(file, out seasF, out epF, Action.Episode.SI) && (seasF == Action.Episode.SeasonNumber) && (epF == Action.Episode.EpNum)) { toRemove.Add(Action1); newList.Add(new ItemSABnzbd(te, Action.Episode, Action.TheFileNoExt)); break; } } } } } foreach (Item i in toRemove) this.TheActionList.Remove(i); foreach (Item Action in newList) this.TheActionList.Add(Action); prog.Invoke(startpct+totPct); }
public void RSSSearch(SetProgressDelegate prog) { int c = this.TheActionList.Count + 2; int n = 1; prog.Invoke(100 * n / c); this.RSSList = new RSSItemList(); foreach (string s in this.Settings.RSSURLs) this.RSSList.DownloadRSS(s, this.Settings.FNPRegexs); ItemList newItems = new ItemList(); ItemList toRemove = new ItemList(); foreach (Item Action1 in this.TheActionList) { if (this.ActionCancel) return; n++; prog.Invoke(100 * n / c); if (!(Action1 is ItemMissing)) continue; ItemMissing Action = (ItemMissing) (Action1); ProcessedEpisode pe = Action.Episode; string simpleShowName = Helpers.SimplifyName(pe.SI.ShowName); string simpleSeriesName = Helpers.SimplifyName(pe.TheSeries.Name); foreach (RSSItem rss in this.RSSList) { if ((this.SimplifyAndCheckFilename(rss.ShowName, simpleShowName, true, false) || (string.IsNullOrEmpty(rss.ShowName) && this.SimplifyAndCheckFilename(rss.Title, simpleSeriesName, true, false))) && (rss.Season == pe.SeasonNumber) && (rss.Episode == pe.EpNum)) { newItems.Add(new ActionRSS(rss, Action.TheFileNoExt, pe)); toRemove.Add(Action1); } } } foreach (Item i in toRemove) this.TheActionList.Remove(i); foreach (Item Action in newItems) this.TheActionList.Add(Action); prog.Invoke(100); }
public bool RenameFilesToMatchTorrent(string torrent, string folder, TreeView tvTree, SetProgressDelegate prog, bool copyNotMove, string copyDest, CommandLineArgs args) { if (string.IsNullOrEmpty(folder)) return false; if (string.IsNullOrEmpty(torrent)) return false; if (copyNotMove) { if (string.IsNullOrEmpty(copyDest)) return false; if (!Directory.Exists(copyDest)) return false; } this.Stats().TorrentsMatched++; BTFileRenamer btp = new BTFileRenamer(prog); ItemList newList = new ItemList(); bool r = btp.RenameFilesOnDiskToMatchTorrent(torrent, folder, tvTree, newList, copyNotMove, copyDest, args); foreach (Item i in newList) this.TheActionList.Add(i); return r; }
public void InitializeAdvancedSearch() { setProgress = new SetProgressDelegate(this.SetProgressValue); enableControls = new EnableControlsDelegate(this.EnableControls); showResults = new ShowResultsDelegate(this.ShowSearchResult); }
public UI(TVDoc doc) { this.mDoc = doc; this.Busy = 0; this.mLastEpClicked = null; this.mLastFolderClicked = null; this.mLastSeasonClicked = null; this.mLastShowsClicked = null; this.mLastActionsClicked = null; this.mInternalChange = 0; this.mFoldersToOpen = new List<String>(); this.InternalCheckChange = false; this.InitializeComponent(); this.SetupIPC(); try { this.LoadLayoutXML(); } catch { // silently fail, doesn't matter too much } this.SetProgress += this.SetProgressActual; this.lvWhenToWatch.ListViewItemSorter = new DateSorterWTW(); if (this.mDoc.Args.Hide) { this.WindowState = FormWindowState.Minimized; this.Visible = false; this.Hide(); } this.Text = this.Text + " " + Version.DisplayVersionString(); this.FillMyShows(); this.UpdateSearchButton(); this.SetGuideHTMLbody(""); this.mDoc.DoWhenToWatch(true); this.FillWhenToWatchList(); this.mDoc.WriteUpcomingRSSandXML(); this.ShowHideNotificationIcon(); int t = this.mDoc.Settings.StartupTab; if (t < this.tabControl1.TabCount) this.tabControl1.SelectedIndex = this.mDoc.Settings.StartupTab; this.tabControl1_SelectedIndexChanged(null, null); this.mAutoFolderMonitor = new TVRename.AutoFolderMonitor(mDoc,this); if (this.mDoc.Settings.MonitorFolders) this.mAutoFolderMonitor.StartMonitor(); }
public BTFileRenamer(SetProgressDelegate setprog) : base(setprog) { }
protected BTCore(SetProgressDelegate setprog) { this.SetProg = setprog; this.HashCache = new System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<HashCacheItem>>(); this.CacheChecks = this.CacheItems = this.CacheHits = 0; this.FileCache = null; this.FileCacheIsFor = null; this.FileCacheWithSubFolders = false; }
public BTResume(SetProgressDelegate setprog, string resumeDatFile) : base(setprog) { this.ResumeDatPath = resumeDatFile; }
public void RenameAndMissingCheck(SetProgressDelegate prog, List<ShowItem> showList) { this.TheActionList = new ItemList(); //int totalEps = 0; this.LockShowItems(); if (showList == null) showList = ShowItems; //foreach (ShowItem si in showlist) // if (si.DoRename) // totalEps += si.SeasonEpisodes.Count; if (this.Settings.RenameCheck) this.Stats().RenameChecksDone++; if (this.Settings.MissingCheck) this.Stats().MissingChecksDone++; prog.Invoke(0); if (showList == null) // only do episode count if we're doing all shows and seasons this.mStats.NS_NumberOfEpisodes = 0; int c = 0; foreach (ShowItem si in showList) { if (this.ActionCancel) return; System.Diagnostics.Debug.Print(DateTime.Now.ToLongTimeString()+ " Rename and missing check: " + si.ShowName); c++; prog.Invoke(100 * c / showList.Count); if (si.AllFolderLocations(this.Settings).Count == 0) // no folders defined for this show continue; // so, nothing to do. // for each tv show, optionally write a tvshow.nfo file if (this.Settings.NFOs && !string.IsNullOrEmpty(si.AutoAdd_FolderBase) && (si.AllFolderLocations(this.Settings).Count > 0)) { FileInfo tvshownfo = Helpers.FileInFolder(si.AutoAdd_FolderBase, "tvshow.nfo"); bool needUpdate = !tvshownfo.Exists || (si.TheSeries().Srv_LastUpdated > TimeZone.Epoch(tvshownfo.LastWriteTime)); // was it written before we fixed the bug in <episodeguideurl> ? needUpdate = needUpdate || (tvshownfo.LastWriteTime.ToUniversalTime().CompareTo(new DateTime(2009, 9, 13, 7, 30, 0, 0, DateTimeKind.Utc)) < 0); if (needUpdate) this.TheActionList.Add(new ActionNFO(tvshownfo, si)); } // process each folder for each season... int[] numbers = new int[si.SeasonEpisodes.Keys.Count]; si.SeasonEpisodes.Keys.CopyTo(numbers, 0); Dictionary<int, List<string>> allFolders = si.AllFolderLocations(this.Settings); int lastSeason = 0; foreach (int n in numbers) if (n > lastSeason) lastSeason = n; foreach (int snum in numbers) { if (this.ActionCancel) return; if ((si.IgnoreSeasons.Contains(snum)) || (!allFolders.ContainsKey(snum))) continue; // ignore/skip this season if ((snum == 0) && (si.CountSpecials)) continue; // don't process the specials season, as they're merged into the seasons themselves // all the folders for this particular season List<string> folders = allFolders[snum]; bool folderNotDefined = (folders.Count == 0); if (folderNotDefined && (this.Settings.MissingCheck && !si.AutoAddNewSeasons)) continue; // folder for the season is not defined, and we're not auto-adding it List<ProcessedEpisode> eps = si.SeasonEpisodes[snum]; int maxEpisodeNumber = 0; foreach (ProcessedEpisode episode in eps) { if (episode.EpNum > maxEpisodeNumber) maxEpisodeNumber = episode.EpNum; } List<string> doneFolderJPG = new List<String>(); if (this.Settings.FolderJpg) { // main image for the folder itself // base folder: if (!string.IsNullOrEmpty(si.AutoAdd_FolderBase) && (si.AllFolderLocations(this.Settings, false).Count > 0)) { FileInfo fi = Helpers.FileInFolder(si.AutoAdd_FolderBase, "folder.jpg"); if (!fi.Exists) { string bannerPath = si.TheSeries().GetItem(this.Settings.ItemForFolderJpg()); if (!string.IsNullOrEmpty(bannerPath)) this.TheActionList.Add(new ActionDownload(si, null, fi, bannerPath)); } doneFolderJPG.Add(si.AutoAdd_FolderBase); } } foreach (string folder in folders) { if (this.ActionCancel) return; // generate new filename info DirectoryInfo di; try { di = new DirectoryInfo(folder); } catch { continue; } bool renCheck = this.Settings.RenameCheck && si.DoRename && di.Exists; // renaming check needs the folder to exist bool missCheck = this.Settings.MissingCheck && si.DoMissingCheck; if (this.Settings.FolderJpg) { // season folders JPGs if (!doneFolderJPG.Contains(folder)) // some folders may come up multiple times { doneFolderJPG.Add(folder); FileInfo fi = Helpers.FileInFolder(folder, "folder.jpg"); if (!fi.Exists) { string bannerPath = si.TheSeries().GetItem(this.Settings.ItemForFolderJpg()); if (!string.IsNullOrEmpty(bannerPath)) this.TheActionList.Add(new ActionDownload(si, null, fi, bannerPath)); } } } FileInfo[] files = di.GetFiles(); // all the files in the folder FileInfo[] localEps = new FileInfo[maxEpisodeNumber + 1]; int maxEpNumFound = 0; if (!renCheck && !missCheck) continue; foreach (FileInfo fi in files) { if (this.ActionCancel) return; int seasNum; int epNum; if (!this.FindSeasEp(fi, out seasNum, out epNum, si)) continue; // can't find season & episode, so this file is of no interest to us if (seasNum == -1) seasNum = snum; #if !NOLAMBDA int epIdx = eps.FindIndex(x => ((x.EpNum == epNum) && (x.SeasonNumber == seasNum))); if (epIdx == -1) continue; // season+episode number don't correspond to any episode we know of from thetvdb ProcessedEpisode ep = eps[epIdx]; #else // equivalent of the 4 lines above, if compiling on MonoDevelop on Windows which, for // some reason, doesn't seem to support lambda functions (the => thing) ProcessedEpisode ep = null; foreach (ProcessedEpisode x in eps) { if (((x.EpNum == epNum) && (x.SeasonNumber == seasNum))) { ep = x; break; } } if (ep == null) continue; // season+episode number don't correspond to any episode we know of from thetvdb #endif FileInfo actualFile = fi; if (renCheck && this.Settings.UsefulExtension(fi.Extension, true)) // == RENAMING CHECK == { string newname = this.Settings.FilenameFriendly(this.Settings.NamingStyle.NameForExt(ep, fi.Extension, folder.Length)); if (newname != actualFile.Name) { actualFile = Helpers.FileInFolder(folder, newname); // rename updates the filename this.TheActionList.Add(new ActionCopyMoveRename(ActionCopyMoveRename.Op.Rename, fi, actualFile, ep)); } } if (missCheck && this.Settings.UsefulExtension(fi.Extension, false)) // == MISSING CHECK part 1/2 == { // first pass of missing check is to tally up the episodes we do have localEps[epNum] = actualFile; if (epNum > maxEpNumFound) maxEpNumFound = epNum; } } // foreach file in folder if (missCheck) // == MISSING CHECK part 2/2 (includes NFO and Thumbnails) == { // second part of missing check is to see what is missing! // look at the offical list of episodes, and look to see if we have any gaps DateTime today = DateTime.Now; TheTVDB db = this.GetTVDB(true, "UpToDateCheck"); foreach (ProcessedEpisode dbep in eps) { if ((dbep.EpNum > maxEpNumFound) || (localEps[dbep.EpNum] == null)) // not here locally { DateTime? dt = dbep.GetAirDateDT(true); bool dtOK = dt != null; bool notFuture = (dtOK && (dt.Value.CompareTo(today) < 0)); // isn't an episode yet to be aired bool noAirdatesUntilNow = true; // for specials "season", see if any season has any airdates // otherwise, check only up to the season we are considering for (int i = 1; i <= ((snum == 0) ? lastSeason : snum); i++) { if (this.HasAnyAirdates(si, i)) { noAirdatesUntilNow = false; break; } } // only add to the missing list if, either: // - force check is on // - there are no airdates at all, for up to and including this season // - there is an airdate, and it isn't in the future if (noAirdatesUntilNow || ((si.ForceCheckFuture || notFuture) && dtOK) || (si.ForceCheckNoAirdate && !dtOK)) { // then add it as officially missing this.TheActionList.Add(new ItemMissing(dbep, folder + System.IO.Path.DirectorySeparatorChar + this.Settings.FilenameFriendly(this.Settings.NamingStyle.NameForExt(dbep, null, folder.Length)))); } } else { // the file is here if (showList == null) this.mStats.NS_NumberOfEpisodes++; // do NFO and thumbnail checks if required FileInfo filo = localEps[dbep.EpNum]; // filename (or future filename) of the file this.ThumbnailAndNFOCheck(dbep, filo, this.TheActionList); } } // up to date check, for each episode in thetvdb db.Unlock("UpToDateCheck"); } // if doing missing check } // for each folder for this season of this show } // for each season of this show } // for each show this.UnlockShowItems(); this.RemoveIgnored(); }
public void RenameAndMissingCheck(SetProgressDelegate prog, List<ShowItem> showList) { this.TheActionList = new ItemList(); //int totalEps = 0; this.LockShowItems(); if (showList == null) showList = ShowItems; //foreach (ShowItem si in showlist) // if (si.DoRename) // totalEps += si.SeasonEpisodes.Count; if (TVSettings.Instance.RenameCheck) this.Stats().RenameChecksDone++; if (TVSettings.Instance.MissingCheck) this.Stats().MissingChecksDone++; prog.Invoke(0); if (showList == null) // only do episode count if we're doing all shows and seasons this.mStats.NS_NumberOfEpisodes = 0; DirFilesCache dfc = new DirFilesCache(); int c = 0; foreach (ShowItem si in showList) { if (this.ActionCancel) return; System.Diagnostics.Debug.Print(DateTime.Now.ToLongTimeString()+ " Rename and missing check: " + si.ShowName); c++; prog.Invoke(100 * c / showList.Count); if (si.AllFolderLocations().Count == 0) // no folders defined for this show continue; // so, nothing to do. //This is the code that will iterate over the DownloadIdentifiers and ask each to ensure that //it has all the required files for that show if (!string.IsNullOrEmpty(si.AutoAdd_FolderBase) && (si.AllFolderLocations().Count > 0)) { this.TheActionList.Add(DownloadIdentifiers.ProcessShow(si)); } //MS_TODO Put the bannerrefresh period into the settings file, we'l default to 3 months DateTime cutOff = System.DateTime.Now.AddMonths(-3); DateTime lastUpdate = si.BannersLastUpdatedOnDisk ?? System.DateTime.Now.AddMonths(-4); bool timeForBannerUpdate = (cutOff.CompareTo(lastUpdate) == 1); if (TVSettings.Instance.NeedToDownloadBannerFile() && timeForBannerUpdate) { this.TheActionList.Add(DownloadIdentifiers.ForceUpdateShow(DownloadIdentifier.DownloadType.downloadImage, si)); si.BannersLastUpdatedOnDisk = DateTime.Now; this.SetDirty(); } // process each folder for each season... int[] numbers = new int[si.SeasonEpisodes.Keys.Count]; si.SeasonEpisodes.Keys.CopyTo(numbers, 0); Dictionary<int, List<string>> allFolders = si.AllFolderLocations(); int lastSeason = 0; foreach (int n in numbers) if (n > lastSeason) lastSeason = n; foreach (int snum in numbers) { if (this.ActionCancel) return; if ((si.IgnoreSeasons.Contains(snum)) || (!allFolders.ContainsKey(snum))) continue; // ignore/skip this season if ((snum == 0) && (si.CountSpecials)) continue; // don't process the specials season, as they're merged into the seasons themselves // all the folders for this particular season List<string> folders = allFolders[snum]; bool folderNotDefined = (folders.Count == 0); if (folderNotDefined && (TVSettings.Instance.MissingCheck && !si.AutoAddNewSeasons)) continue; // folder for the season is not defined, and we're not auto-adding it List<ProcessedEpisode> eps = si.SeasonEpisodes[snum]; int maxEpisodeNumber = 0; foreach (ProcessedEpisode episode in eps) { if (episode.EpNum > maxEpisodeNumber) maxEpisodeNumber = episode.EpNum; } // base folder: if (!string.IsNullOrEmpty(si.AutoAdd_FolderBase) && (si.AllFolderLocations(false).Count > 0)) { // main image for the folder itself this.TheActionList.Add(DownloadIdentifiers.ProcessShow(si)); } foreach (string folder in folders) { if (this.ActionCancel) return; FileInfo[] files = dfc.Get(folder); if (files == null) continue; if (TVSettings.Instance.NeedToDownloadBannerFile() && timeForBannerUpdate) { //Image series checks here this.TheActionList.Add(DownloadIdentifiers.ForceUpdateSeason(DownloadIdentifier.DownloadType.downloadImage, si, folder, snum)); } bool renCheck = TVSettings.Instance.RenameCheck && si.DoRename && Directory.Exists(folder); // renaming check needs the folder to exist bool missCheck = TVSettings.Instance.MissingCheck && si.DoMissingCheck; //Image series checks here this.TheActionList.Add(DownloadIdentifiers.ProcessSeason(si,folder,snum)); FileInfo[] localEps = new FileInfo[maxEpisodeNumber + 1]; int maxEpNumFound = 0; if (!renCheck && !missCheck) continue; foreach (FileInfo fi in files) { if (this.ActionCancel) return; int seasNum; int epNum; if (!FindSeasEp(fi, out seasNum, out epNum, si)) continue; // can't find season & episode, so this file is of no interest to us if (seasNum == -1) seasNum = snum; #if !NOLAMBDA int epIdx = eps.FindIndex(x => ((x.EpNum == epNum) && (x.SeasonNumber == seasNum))); if (epIdx == -1) continue; // season+episode number don't correspond to any episode we know of from thetvdb ProcessedEpisode ep = eps[epIdx]; #else // equivalent of the 4 lines above, if compiling on MonoDevelop on Windows which, for // some reason, doesn't seem to support lambda functions (the => thing) ProcessedEpisode ep = null; foreach (ProcessedEpisode x in eps) { if (((x.EpNum == epNum) && (x.SeasonNumber == seasNum))) { ep = x; break; } } if (ep == null) continue; // season+episode number don't correspond to any episode we know of from thetvdb #endif FileInfo actualFile = fi; if (renCheck && TVSettings.Instance.UsefulExtension(fi.Extension, true)) // == RENAMING CHECK == { string newname = TVSettings.Instance.FilenameFriendly(TVSettings.Instance.NamingStyle.NameForExt(ep, fi.Extension, folder.Length)); if (newname != actualFile.Name) { actualFile = FileHelper.FileInFolder(folder, newname); // rename updates the filename this.TheActionList.Add(new ActionCopyMoveRename(ActionCopyMoveRename.Op.Rename, fi, actualFile, ep, null)); //The following section informs the DownloadIdentifers that we already plan to //copy a file inthe appropriate place and they do not need to worry about downloading //one for that purpse DownloadIdentifiers.notifyComplete(actualFile); } } if (missCheck && TVSettings.Instance.UsefulExtension(fi.Extension, false)) // == MISSING CHECK part 1/2 == { // first pass of missing check is to tally up the episodes we do have localEps[epNum] = actualFile; if (epNum > maxEpNumFound) maxEpNumFound = epNum; } } // foreach file in folder if (missCheck) // == MISSING CHECK part 2/2 (includes NFO and Thumbnails) == { // second part of missing check is to see what is missing! // look at the offical list of episodes, and look to see if we have any gaps DateTime today = DateTime.Now; TheTVDB.Instance.GetLock("UpToDateCheck"); foreach (ProcessedEpisode dbep in eps) { if ((dbep.EpNum > maxEpNumFound) || (localEps[dbep.EpNum] == null)) // not here locally { DateTime? dt = dbep.GetAirDateDT(true); bool dtOK = dt != null; bool notFuture = (dtOK && (dt.Value.CompareTo(today) < 0)); // isn't an episode yet to be aired bool noAirdatesUntilNow = true; // for specials "season", see if any season has any airdates // otherwise, check only up to the season we are considering for (int i = 1; i <= ((snum == 0) ? lastSeason : snum); i++) { if (this.HasAnyAirdates(si, i)) { noAirdatesUntilNow = false; break; } } // only add to the missing list if, either: // - force check is on // - there are no airdates at all, for up to and including this season // - there is an airdate, and it isn't in the future if (noAirdatesUntilNow || ((si.ForceCheckFuture || notFuture) && dtOK) || (si.ForceCheckNoAirdate && !dtOK)) { // then add it as officially missing this.TheActionList.Add(new ItemMissing(dbep, folder + System.IO.Path.DirectorySeparatorChar + TVSettings.Instance.FilenameFriendly(TVSettings.Instance.NamingStyle.NameForExt(dbep, null, folder.Length)))); } } else { // the file is here if (showList == null) this.mStats.NS_NumberOfEpisodes++; // do NFO and thumbnail checks if required FileInfo filo = localEps[dbep.EpNum]; // filename (or future filename) of the file this.TheActionList.Add(DownloadIdentifiers.ProcessEpisode(dbep, filo)); } } // up to date check, for each episode in thetvdb TheTVDB.Instance.Unlock("UpToDateCheck"); } // if doing missing check } // for each folder for this season of this show } // for each season of this show } // for each show this.UnlockShowItems(); this.RemoveIgnored(); }