Skip to content

Commit

Permalink
New Function: Copy/Move Downloaded Future Episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSparkles committed Dec 17, 2018
1 parent 29bc280 commit 8e25486
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 20 deletions.
29 changes: 22 additions & 7 deletions TVRename/Forms/Preferences/Preferences.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions TVRename/Forms/Preferences/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ private void UpdateSettings()
s.AutoMergeLibraryEpisodes = chkAutoMergeLibraryEpisodes.Checked;
s.RetainLanguageSpecificSubtitles = chkRetainLanguageSpecificSubtitles.Checked;
s.ForceBulkAddToUseSettingsOnly = chkForceBulkAddToUseSettingsOnly.Checked;
s.CopyFutureDatedEpsFromSearchFolders = cbCopyFutureDatedEps.Checked;

s.SearchJSON = cbSearchJSON.Checked;
s.SearchJSONManualScanOnly = cbSearchJSONManualScanOnly.Checked;
Expand Down Expand Up @@ -681,6 +682,7 @@ private void Preferences_Load(object sender, EventArgs e)
SetDropdownValue(domainUpDown1, s.periodCheckHours);
cbCleanUpDownloadDir.Checked = s.RemoveDownloadDirectoriesFiles;
cbDeleteShowFromDisk.Checked = s.DeleteShowFromDisk;
cbCopyFutureDatedEps.Checked = s.CopyFutureDatedEpsFromSearchFolders;

cbMissing.Checked = s.MissingCheck;
cbxUpdateAirDate.Checked = s.CorrectFileDates;
Expand Down
36 changes: 30 additions & 6 deletions TVRename/ScanActivity/CleanDownloadDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace TVRename
internal class CleanDownloadDirectory:ScanActivity
{
// ReSharper disable once InconsistentNaming
private IEnumerable<Action> Go(ICollection<ShowItem> showList, bool unattended)
private IEnumerable<Item> Go(ICollection<ShowItem> showList, bool unattended)
{
//for each directory in settings directory
//for each file in directory
Expand All @@ -17,7 +17,7 @@ private IEnumerable<Action> Go(ICollection<ShowItem> showList, bool unattended)
//if so add show to list of files to be removed

DirFilesCache dfc = new DirFilesCache();
List<Action> returnActions =new List<Action>();
List<Item> returnActions =new List<Item>();

int totalDownloadFolders = TVSettings.Instance.DownloadFolders.Count;
int c = 1;
Expand Down Expand Up @@ -113,9 +113,9 @@ private static Action SetupDirectoryRemoval(DirectoryInfo di, List<ShowItem> mat
return new ActionDeleteDirectory(di, pep, TVSettings.Instance.Tidyup);
}

private static IEnumerable<Action> ReviewFilesInDownloadDirectory(ICollection<ShowItem> showList, bool unattended, DirFilesCache dfc, string dirPath, List<FileInfo> filesThatMayBeNeeded)
private static IEnumerable<Item> ReviewFilesInDownloadDirectory(ICollection<ShowItem> showList, bool unattended, DirFilesCache dfc, string dirPath, List<FileInfo> filesThatMayBeNeeded)
{
List<Action> returnActions = new List<Action>();
List<Item> returnActions = new List<Item>();
try
{
foreach (string filePath in Directory.GetFiles(dirPath, "*", System.IO.SearchOption.AllDirectories))
Expand Down Expand Up @@ -143,10 +143,10 @@ private static IEnumerable<Action> ReviewFilesInDownloadDirectory(ICollection<Sh
return returnActions;
}

private static List<Action> ReviewFileInDownloadDirectory(bool unattended, DirFilesCache dfc, ICollection<FileInfo> filesThatMayBeNeeded, FileInfo fi, List<ShowItem> matchingShows)
private static List<Item> ReviewFileInDownloadDirectory(bool unattended, DirFilesCache dfc, ICollection<FileInfo> filesThatMayBeNeeded, FileInfo fi, List<ShowItem> matchingShows)
{
bool fileCanBeDeleted = TVSettings.Instance.RemoveDownloadDirectoriesFiles;
List<Action> returnActions = new List<Action>();
List<Item> returnActions = new List<Item>();
ProcessedEpisode firstMatchingPep = null;

foreach (ShowItem si in matchingShows)
Expand All @@ -166,6 +166,30 @@ private static List<Action> ReviewFileInDownloadDirectory(bool unattended, DirFi
{
//File is needed as there are no files for that series/episode
fileCanBeDeleted = false;

//This episode may be a future dated one - process it now if the settings request that we do and it wont be picked up in a full scan
if (TVSettings.Instance.CopyFutureDatedEpsFromSearchFolders && !si.ForceCheckFuture && si.DoMissingCheck && TVSettings.Instance.MissingCheck && !TVSettings.Instance.PreventMove)
{
if (pep.IsInFuture())
{
LOGGER.Info(
$"Identified that {fi.FullName} matches S{seasF}E{epF} of show {si.ShowName}, that it's not already present and airs in the future. Copying across.");

string filename = TVSettings.Instance.FilenameFriendly(TVSettings.Instance.NamingStyle.NameFor(pep));
List<string> folders = si.AllFolderLocations()[seasF];
foreach (string folder in folders)
{
FileInfo targetFile = new FileInfo(folder + System.IO.Path.DirectorySeparatorChar + filename + fi.Extension);

if (fi.FullName == targetFile.FullName) continue;

returnActions.Add(new ActionCopyMoveRename(fi, targetFile, pep));

// if we're copying/moving a file across, we might also want to make a thumbnail or NFO for it
returnActions.AddRange(new DownloadIdentifiersController().ProcessEpisode(pep, targetFile));
}
}
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions TVRename/ScanActivity/ScanActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void Check(SetProgressDelegate prog, int startpct, int totPct, ICollectio
startPosition = startpct;
endPosition = totPct;
progressDelegate = prog;
progressDelegate.Invoke(startPosition, string.Empty);
Check(prog, showList,settings);
progressDelegate.Invoke(endPosition , string.Empty);
}
Expand Down
12 changes: 12 additions & 0 deletions TVRename/Settings/ProcessedEpisode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,17 @@ public bool WithinDays(int days)
TimeSpan ts = dt.Value.Subtract(DateTime.Now);
return (ts.TotalHours >= (-24 * days)) && (ts.TotalHours <= 0);
}

public bool IsInFuture()
{
DateTime? airsdt = GetAirDateDt(true);
if (airsdt == null)
return false;

DateTime dt = (DateTime)airsdt;

TimeSpan ts = dt.Subtract(DateTime.Now); // how long...
return ts.TotalHours > 0;
}
}
}
4 changes: 4 additions & 0 deletions TVRename/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ internal bool IncludeBetaUpdates()
public string SearchJSONFileSizeToken = "size_bytes";

public string[] VideoExtensionsArray => VideoExtensionsString.Split(';');

public bool CopyFutureDatedEpsFromSearchFolders = false;
public bool ForceBulkAddToUseSettingsOnly = false;
public bool RetainLanguageSpecificSubtitles = true;
public bool AutoMergeDownloadEpisodes = false;
Expand Down Expand Up @@ -441,6 +443,7 @@ public void WriteXML(XmlWriter writer)
XmlHelper.WriteElementToXml(writer, "SearchJSONURLToken", SearchJSONURLToken);
XmlHelper.WriteElementToXml(writer, "SearchJSONFileSizeToken", SearchJSONFileSizeToken);
XmlHelper.WriteElementToXml(writer, "PriorityReplaceTerms", PriorityReplaceTerms);
XmlHelper.WriteElementToXml(writer, "CopyFutureDatedEpsFromSearchFolders", CopyFutureDatedEpsFromSearchFolders);

TheSearchers.WriteXml(writer);
writer.WriteStartElement("Replacements");
Expand Down Expand Up @@ -1048,6 +1051,7 @@ public void load(XElement xmlSettings)
keepTogetherMode = xmlSettings.ExtractEnum("KeepTogetherType", KeepTogetherModes.All);
keepTogetherExtensionsString = xmlSettings.ExtractString("KeepTogetherExtensions", ".srt;.nfo;.txt;.tbn");
ExportWTWRSS = xmlSettings.ExtractBool("ExportWTWRSS") ?? false;
CopyFutureDatedEpsFromSearchFolders = xmlSettings.ExtractBool("CopyFutureDatedEpsFromSearchFolders") ?? false;

Tidyup.load(xmlSettings);
RSSURLs = xmlSettings.Descendants("RSSURLs").First().ReadStringsFromXml("URL");
Expand Down
6 changes: 0 additions & 6 deletions TVRename/Settings/ShowItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,6 @@ public int MaxSeason()
return max;
}

//StringNiceName(int season)
//{
// // something like "Simpsons (S3)"
// return String.Concat(ShowName," (S",season,")");
//}

public void WriteXmlSettings(XmlWriter writer)
{
writer.WriteStartElement("ShowItem");
Expand Down
3 changes: 2 additions & 1 deletion TVRename/TVRename/CacheUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public CacheUpdater()
{
DownloadDone = true;
downloadOk = true;
problematicSeriesIds = new List<int>();
}

public void StartBgDownloadThread(bool stopOnError, ICollection<SeriesSpecifier> shows)
Expand All @@ -45,7 +46,7 @@ public void StartBgDownloadThread(bool stopOnError, ICollection<SeriesSpecifier>
downloadOk = true;

downloadIds = shows;
problematicSeriesIds = new List<int>();
problematicSeriesIds.Clear();
mDownloaderThread = new Thread(Downloader) { Name = "Downloader" };
mDownloaderThread.Start();
}
Expand Down

0 comments on commit 8e25486

Please sign in to comment.