From 22bb49daf633a194a525d98901a24d8609d16e3a Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 8 Feb 2022 09:34:53 +0800 Subject: [PATCH] Improvements to jpg copying/moving to remove duplicate downloads --- TVRename/Forms/Preferences/Preferences.cs | 18 ++++++++++++- .../DownloadIdentifers/DownloadEpisodeJPG.cs | 26 +++++++++++++++---- .../DownloadIdentifers/DownloadKodiImages.cs | 5 +--- TVRename/ScanActivity/ScanActivity.cs | 2 +- TVRename/Settings/CustomEpisodeName.cs | 7 ----- TVRename/Settings/TVSettings.cs | 25 ++++++++++++++++-- 6 files changed, 63 insertions(+), 20 deletions(-) diff --git a/TVRename/Forms/Preferences/Preferences.cs b/TVRename/Forms/Preferences/Preferences.cs index 1e6df109..2071014a 100644 --- a/TVRename/Forms/Preferences/Preferences.cs +++ b/TVRename/Forms/Preferences/Preferences.cs @@ -156,7 +156,7 @@ private void ValidateFileExtensions() ValidateExtensions(txtEmptyIgnoreExtensions, tbFolderDeleting); ValidateExtensions(txtVideoExtensions, tbFilesAndFolders); ValidateExtensions(txtSubtitleExtensions, tbFilesAndFolders); - ValidateExtensions(txtOtherExtensions, tbFilesAndFolders); + ValidateExtensionsWithoutDot(txtOtherExtensions, tbFilesAndFolders); ValidateExtensions(txtKeepTogether, tbFilesAndFolders); } @@ -225,6 +225,22 @@ private void ValidateExtensions([NotNull] Control validateField, TabPage focusTa throw new FailedValidationException(); } + private void ValidateExtensionsWithoutDot([NotNull] Control validateField, TabPage focusTabPage) + { + if (TVSettings.OKExtensionsStringNoDotCheck(validateField.Text)) + { + return; + } + + MessageBox.Show( + "Extensions list must be separated by semicolons.", + "Preferences", MessageBoxButtons.OK, MessageBoxIcon.Warning); + + tcTabs.SelectedTab = focusTabPage; + validateField.Focus(); + throw new FailedValidationException(); + } + #region Update Settings // ReSharper disable once FunctionComplexityOverflow diff --git a/TVRename/ScanActivity/DownloadIdentifers/DownloadEpisodeJPG.cs b/TVRename/ScanActivity/DownloadIdentifers/DownloadEpisodeJPG.cs index 6d4ca2f5..a50d51a4 100644 --- a/TVRename/ScanActivity/DownloadIdentifers/DownloadEpisodeJPG.cs +++ b/TVRename/ScanActivity/DownloadIdentifers/DownloadEpisodeJPG.cs @@ -1,4 +1,6 @@ +using System.Collections.Generic; using Alphaleonis.Win32.Filesystem; +using JetBrains.Annotations; namespace TVRename { @@ -7,7 +9,13 @@ internal class DownloadEpisodeJpg : DownloadIdentifier private const string DEFAULT_EXTENSION = ".jpg"; public override DownloadType GetDownloadType() => DownloadType.downloadImage; + private List doneTbn = new(); + public override void NotifyComplete([NotNull] FileInfo file) + { + doneTbn.Add(file.FullName); + base.NotifyComplete(file); + } public override ItemList? ProcessEpisode(ProcessedEpisode episode, FileInfo file, bool forceRefresh) { if (!TVSettings.Instance.EpJPGs) @@ -15,8 +23,6 @@ internal class DownloadEpisodeJpg : DownloadIdentifier return null; } - ItemList theActionList = new(); - string ban = episode.Filename; if (string.IsNullOrEmpty(ban)) { @@ -27,12 +33,22 @@ internal class DownloadEpisodeJpg : DownloadIdentifier FileInfo imgjpg = FileHelper.FileInFolder(file.Directory, basefn + DEFAULT_EXTENSION); - if (forceRefresh || !imgjpg.Exists) + if (doneTbn.Contains(imgjpg.FullName)) { - theActionList.Add(new ActionDownloadImage(episode.Show, episode, imgjpg, ban, TVSettings.Instance.ShrinkLargeMede8erImages)); + return null; } - return theActionList; + if (!forceRefresh && imgjpg.Exists) + { + return null; + } + + return new ItemList { new ActionDownloadImage(episode.Show, episode, imgjpg, ban, TVSettings.Instance.ShrinkLargeMede8erImages) }; + } + + public sealed override void Reset() + { + doneTbn = new List(); } } } diff --git a/TVRename/ScanActivity/DownloadIdentifers/DownloadKodiImages.cs b/TVRename/ScanActivity/DownloadIdentifers/DownloadKodiImages.cs index 6bc925eb..b6c1ae60 100644 --- a/TVRename/ScanActivity/DownloadIdentifers/DownloadKodiImages.cs +++ b/TVRename/ScanActivity/DownloadIdentifers/DownloadKodiImages.cs @@ -26,10 +26,7 @@ internal class DownloadKodiImages : DownloadIdentifier public override void NotifyComplete([NotNull] FileInfo file) { - if (file.Name.EndsWith(".tbn", true, new CultureInfo("en"))) - { - doneTbn.Add(file.FullName); - } + doneTbn.Add(file.FullName); base.NotifyComplete(file); } diff --git a/TVRename/ScanActivity/ScanActivity.cs b/TVRename/ScanActivity/ScanActivity.cs index f9a5319f..ef0c76cb 100644 --- a/TVRename/ScanActivity/ScanActivity.cs +++ b/TVRename/ScanActivity/ScanActivity.cs @@ -96,7 +96,7 @@ private void LogActionListSummary() } catch (InvalidOperationException) { - //someties get this if enumeration updates + //sometimes get this if enumeration updates } } } diff --git a/TVRename/Settings/CustomEpisodeName.cs b/TVRename/Settings/CustomEpisodeName.cs index c710d851..63e8af84 100644 --- a/TVRename/Settings/CustomEpisodeName.cs +++ b/TVRename/Settings/CustomEpisodeName.cs @@ -105,13 +105,6 @@ public string NameFor([NotNull] ProcessedEpisode pe, string? extension, int fold return r.Substring(0, Math.Min(maxFilenameLength, r.Length)); } - bool needsSpacer = !extension.StartsWith(".", StringComparison.Ordinal); - - if (needsSpacer) - { - return r.Substring(0, Math.Min(r.Length, maxFilenameLength)) + "." + extension; - } - return r.Substring(0, Math.Min(r.Length, maxFilenameLength)) + extension; } diff --git a/TVRename/Settings/TVSettings.cs b/TVRename/Settings/TVSettings.cs index adb2fba4..9ddd0b8a 100644 --- a/TVRename/Settings/TVSettings.cs +++ b/TVRename/Settings/TVSettings.cs @@ -909,6 +909,25 @@ public static bool OKExtensionsString(string? s) return true; } + public static bool OKExtensionsStringNoDotCheck(string? s) + { + if (string.IsNullOrEmpty(s)) + { + return true; + } + + string[] t = s.Split(';'); + foreach (string s2 in t) + { + if (string.IsNullOrEmpty(s2) || s2.ContainsAnyCharactersFrom(CompulsoryReplacements()) || s2.ContainsAnyCharactersFrom(Path.GetInvalidFileNameChars())) + { + return false; + } + } + + return true; + } + public static bool OKExporterLocation(string? s) { if (string.IsNullOrEmpty(s)) @@ -1067,7 +1086,8 @@ public string FileHasUsefulExtensionDetails(FileInfo file, bool otherExtensionsT { foreach (string s in VideoExtensionsArray .Where(s => !string.IsNullOrWhiteSpace(s)) - .Where(s => file.Name.EndsWith(s, StringComparison.InvariantCultureIgnoreCase))) + .Where(s => file.Name.EndsWith(s, StringComparison.InvariantCultureIgnoreCase)) + .OrderByDescending(s=>s.Length)) { return s; } @@ -1076,7 +1096,8 @@ public string FileHasUsefulExtensionDetails(FileInfo file, bool otherExtensionsT { foreach (string s in OtherExtensionsArray .Where(s => !string.IsNullOrWhiteSpace(s)) - .Where(s => file.Name.EndsWith(s, StringComparison.InvariantCultureIgnoreCase))) + .Where(s => file.Name.EndsWith(s, StringComparison.InvariantCultureIgnoreCase)) + .OrderByDescending(s=>s.Length)) { return s; }