Skip to content

Commit

Permalink
Improvements to jpg copying/moving to remove duplicate downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSparkles committed Feb 8, 2022
1 parent b3c67e9 commit 22bb49d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 20 deletions.
18 changes: 17 additions & 1 deletion TVRename/Forms/Preferences/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
26 changes: 21 additions & 5 deletions TVRename/ScanActivity/DownloadIdentifers/DownloadEpisodeJPG.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using Alphaleonis.Win32.Filesystem;
using JetBrains.Annotations;

namespace TVRename
{
Expand All @@ -7,16 +9,20 @@ internal class DownloadEpisodeJpg : DownloadIdentifier
private const string DEFAULT_EXTENSION = ".jpg";

public override DownloadType GetDownloadType() => DownloadType.downloadImage;
private List<string> 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)
{
return null;
}

ItemList theActionList = new();

string ban = episode.Filename;
if (string.IsNullOrEmpty(ban))
{
Expand All @@ -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<string>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion TVRename/ScanActivity/ScanActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void LogActionListSummary()
}
catch (InvalidOperationException)
{
//someties get this if enumeration updates
//sometimes get this if enumeration updates
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions TVRename/Settings/CustomEpisodeName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
25 changes: 23 additions & 2 deletions TVRename/Settings/TVSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 22bb49d

Please sign in to comment.