Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSparkles authored Feb 18, 2018
2 parents 8fe9d8a + cebb3e1 commit d09187c
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 6 deletions.
13 changes: 13 additions & 0 deletions TVRename#/DownloadIdentifers/IncorrectFileDates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public override ItemList ProcessShow(ShowItem si, bool forceRefresh)
DateTime? newUpdateTime = si.TheSeries().LastAiredDate();
if (TVSettings.Instance.CorrectFileDates && newUpdateTime.HasValue)
{
//Any series before 1970 will get 1970 as the timestamp
if (newUpdateTime.Value.CompareTo(Helpers.FromUnixTime(0)) < 0)
newUpdateTime = Helpers.FromUnixTime(0);

DirectoryInfo di = new DirectoryInfo(si.AutoAdd_FolderBase);
if ((di.LastWriteTimeUtc != newUpdateTime.Value)&&(!this.doneFilesAndFolders.Contains(di.FullName)))
{
Expand All @@ -33,6 +37,10 @@ public override ItemList ProcessSeason(ShowItem si, string folder, int snum, boo

if (TVSettings.Instance.CorrectFileDates && newUpdateTime.HasValue)
{
//Any series before 1970 will get 1970 as the timestamp
if (newUpdateTime.Value.CompareTo(Helpers.FromUnixTime(0)) < 0)
newUpdateTime = Helpers.FromUnixTime(0);

DirectoryInfo di = new DirectoryInfo(folder);
if ((di.LastWriteTimeUtc != newUpdateTime.Value) &&(!this.doneFilesAndFolders.Contains(di.FullName)))
{
Expand All @@ -49,6 +57,11 @@ public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo, bo
if (TVSettings.Instance.CorrectFileDates && dbep.FirstAired.HasValue)
{
DateTime newUpdateTime = dbep.FirstAired.Value;

//Any series before 1970 will get 1970 as the timestamp
if (newUpdateTime.CompareTo(Helpers.FromUnixTime(0)) < 0)
newUpdateTime = Helpers.FromUnixTime(0);

if ((filo.LastWriteTimeUtc != newUpdateTime) && (!this.doneFilesAndFolders.Contains(filo.FullName)))
{
this.doneFilesAndFolders.Add(filo.FullName);
Expand Down
9 changes: 9 additions & 0 deletions TVRename#/TVRename#.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Microsoft.WindowsAPICodePack, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.WindowsAPICodePack-Core.1.1.0.2\lib\Microsoft.WindowsAPICodePack.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAPICodePack.Shell, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAPICodePack.ShellExtensions, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.ShellExtensions.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
Expand Down
56 changes: 52 additions & 4 deletions TVRename#/TVRename/TVDoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1810,11 +1810,12 @@ protected internal void findDoubleEps()
{
StringBuilder output = new StringBuilder();

output.AppendLine("");
output.AppendLine("##################################################");
output.AppendLine("DUPLICATE FINDER - Part one");
output.AppendLine("DUPLICATE FINDER - Start");
output.AppendLine("##################################################");


DirFilesCache dfc = new DirFilesCache();
foreach (ShowItem si in this.ShowItems)
{
foreach (KeyValuePair<int, List<ProcessedEpisode>> kvp in si.SeasonEpisodes)
Expand Down Expand Up @@ -1845,11 +1846,58 @@ protected internal void findDoubleEps()
{
if (pep.FirstAired.HasValue && comparePep.FirstAired.HasValue && pep.FirstAired == comparePep.FirstAired && pep.EpisodeID < comparePep.EpisodeID)
{
// Tell user about this possibility
output.AppendLine($"{si.ShowName} - Season: {kvp.Key} - {pep.FirstAired.ToString()} - {pep.EpNum}({pep.Name}) - {comparePep.EpNum}({comparePep.Name})");

//do the 'name' test
string root = Helpers.GetCommonStartString(pep.Name, comparePep.Name);
bool sameLength = (pep.Name.Length == comparePep.Name.Length);
if (!root.Trim().Equals("Episode") && sameLength && root.Length>3 && root.Length > pep.Name.Length/2)
output.AppendLine("####### POSSIBLE DUPLICATE ##########");
if (!root.Trim().Equals("Episode") && sameLength && root.Length>3 && root.Length > pep.Name.Length / 2) {
output.AppendLine("####### POSSIBLE DUPLICATE DUE TO NAME##########");

//Do the missing Test (ie is one missing and not the other)
bool pepFound = FindEpOnDisk(dfc,pep ).Count>0;
bool comparePepFound = FindEpOnDisk(dfc, comparePep).Count > 0;

if (pepFound ^ comparePepFound)
{
output.AppendLine(
"####### POSSIBLE DUPLICATE DUE TO ONE MISSING AND ONE FOUND ##########");

ProcessedEpisode possibleDupEpisode = pepFound ? pep : comparePep;
//Test the file sizes in the season
//More than 40% longer
FileInfo possibleDupFile = FindEpOnDisk(dfc, possibleDupEpisode)[0];
int dupMovieLength = possibleDupFile.GetFilmLength();
System.Collections.Generic.List<int> otherMovieLengths =
new System.Collections.Generic.List<int>();

foreach (FileInfo file in possibleDupFile.Directory.EnumerateFiles())
{
if (TVSettings.Instance.UsefulExtension(file.Extension, false))
{
otherMovieLengths.Add(file.GetFilmLength());
}
}

int averageMovieLength =
(otherMovieLengths.Sum() - dupMovieLength) / (otherMovieLengths.Count - 1);

if (dupMovieLength > averageMovieLength * 1.4)
{
output.AppendLine(
"######################################################################");
output.AppendLine(
"####### SURELY WE HAVE ONE NOW ##########");
output.AppendLine(
$"####### {possibleDupEpisode.EpNum}({possibleDupEpisode.Name}) has length {dupMovieLength} greater than the average in the directory of {averageMovieLength}");
output.AppendLine(
"######################################################################");
}
}
}


}
}
}
Expand Down
34 changes: 33 additions & 1 deletion TVRename#/Utility/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
using Microsoft.Win32;
using System.Security;
using System.Windows.Forms;
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
using NLog;

// Helpful functions and classes
Expand Down Expand Up @@ -204,7 +206,37 @@ public FileSystemProperties(long? totalBytes, long? freeBytes, long? availableB

public static class FileHelper
{
public static bool IsSubfolderOf(this string thisOne, string ofThat)
public static int GetFilmLength(this FileInfo movieFile)
{
string duration;
using (ShellObject shell = ShellObject.FromParsingName(movieFile.FullName))
{
// alternatively: shell.Properties.GetProperty("System.Media.Duration");
IShellProperty prop = shell.Properties.System.Media.Duration;
// Duration will be formatted as 00:44:08
duration = prop.FormatForDisplay(PropertyDescriptionFormatOptions.None);
}

return 3600 * int.Parse(duration.Split(':')[0]) + 60 * int.Parse(duration.Split(':')[1]) +
int.Parse(duration.Split(':')[2]);

}

public static void GetFilmDetails(this FileInfo movieFile)
{
using (ShellPropertyCollection properties = new ShellPropertyCollection(movieFile.FullName))
{
foreach (IShellProperty prop in properties)
{
string value = (prop.ValueAsObject == null)
? ""
: prop.FormatForDisplay(PropertyDescriptionFormatOptions.None);
Console.WriteLine("{0} = {1}", prop.CanonicalName, value);
}
}
}

public static bool IsSubfolderOf(this string thisOne, string ofThat)
{
// need terminating slash, otherwise "c:\abc def" will match "c:\abc"
thisOne += System.IO.Path.DirectorySeparatorChar.ToString();
Expand Down
4 changes: 3 additions & 1 deletion TVRename#/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AlphaFS" version="2.1.3" targetFramework="net4" />
<package id="Microsoft.WindowsAPICodePack-Core" version="1.1.0.2" targetFramework="net40" />
<package id="Microsoft.WindowsAPICodePack-Shell" version="1.1.0.0" targetFramework="net40" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net4" />
<package id="NLog" version="4.4.12" targetFramework="net40" />
<package id="SourceGrid" version="4.4.0" targetFramework="net40" />
Expand Down

0 comments on commit d09187c

Please sign in to comment.