|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
|
using NzbDrone.Common.Instrumentation.Extensions;
|
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
@ -25,6 +26,7 @@ namespace NzbDrone.Core.MediaFiles
|
|
|
|
|
private readonly IConfigService _configService;
|
|
|
|
|
private readonly IEpisodeService _episodeService;
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
private static readonly DateTime EpochTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
|
|
|
|
|
|
public UpdateEpisodeFileService(IDiskProvider diskProvider,
|
|
|
|
|
IConfigService configService,
|
|
|
|
@ -77,42 +79,6 @@ namespace NzbDrone.Core.MediaFiles
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Handle(SeriesScannedEvent message)
|
|
|
|
|
{
|
|
|
|
|
if (_configService.FileDate == FileDateType.None)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var episodes = _episodeService.EpisodesWithFiles(message.Series.Id);
|
|
|
|
|
|
|
|
|
|
var episodeFiles = new List<EpisodeFile>();
|
|
|
|
|
var updated = new List<EpisodeFile>();
|
|
|
|
|
|
|
|
|
|
foreach (var group in episodes.GroupBy(e => e.EpisodeFileId))
|
|
|
|
|
{
|
|
|
|
|
var episodesInFile = group.Select(e => e).ToList();
|
|
|
|
|
var episodeFile = episodesInFile.First().EpisodeFile;
|
|
|
|
|
|
|
|
|
|
episodeFiles.Add(episodeFile);
|
|
|
|
|
|
|
|
|
|
if (ChangeFileDate(episodeFile, message.Series, episodesInFile))
|
|
|
|
|
{
|
|
|
|
|
updated.Add(episodeFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (updated.Any())
|
|
|
|
|
{
|
|
|
|
|
_logger.ProgressDebug("Changed file date for {0} files of {1} in {2}", updated.Count, episodeFiles.Count, message.Series.Title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.ProgressDebug("No file dates changed for {0}", message.Series.Title);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ChangeFileDateToLocalAirDate(string filePath, string fileDate, string fileTime)
|
|
|
|
|
{
|
|
|
|
|
DateTime airDate;
|
|
|
|
@ -122,6 +88,12 @@ namespace NzbDrone.Core.MediaFiles
|
|
|
|
|
// avoiding false +ve checks and set date skewing by not using UTC (Windows)
|
|
|
|
|
DateTime oldDateTime = _diskProvider.FileGetLastWrite(filePath);
|
|
|
|
|
|
|
|
|
|
if (OsInfo.IsNotWindows && airDate < EpochTime)
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Setting date of file to 1970-01-01 as actual airdate is before that time and will not be set properly");
|
|
|
|
|
airDate = EpochTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!DateTime.Equals(airDate, oldDateTime))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@ -151,6 +123,12 @@ namespace NzbDrone.Core.MediaFiles
|
|
|
|
|
{
|
|
|
|
|
DateTime oldLastWrite = _diskProvider.FileGetLastWrite(filePath);
|
|
|
|
|
|
|
|
|
|
if (OsInfo.IsNotWindows && airDateUtc < EpochTime)
|
|
|
|
|
{
|
|
|
|
|
_logger.Debug("Setting date of file to 1970-01-01 as actual airdate is before that time and will not be set properly");
|
|
|
|
|
airDateUtc = EpochTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!DateTime.Equals(airDateUtc, oldLastWrite))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@ -169,5 +147,41 @@ namespace NzbDrone.Core.MediaFiles
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Handle(SeriesScannedEvent message)
|
|
|
|
|
{
|
|
|
|
|
if (_configService.FileDate == FileDateType.None)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var episodes = _episodeService.EpisodesWithFiles(message.Series.Id);
|
|
|
|
|
|
|
|
|
|
var episodeFiles = new List<EpisodeFile>();
|
|
|
|
|
var updated = new List<EpisodeFile>();
|
|
|
|
|
|
|
|
|
|
foreach (var group in episodes.GroupBy(e => e.EpisodeFileId))
|
|
|
|
|
{
|
|
|
|
|
var episodesInFile = group.Select(e => e).ToList();
|
|
|
|
|
var episodeFile = episodesInFile.First().EpisodeFile;
|
|
|
|
|
|
|
|
|
|
episodeFiles.Add(episodeFile);
|
|
|
|
|
|
|
|
|
|
if (ChangeFileDate(episodeFile, message.Series, episodesInFile))
|
|
|
|
|
{
|
|
|
|
|
updated.Add(episodeFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (updated.Any())
|
|
|
|
|
{
|
|
|
|
|
_logger.ProgressDebug("Changed file date for {0} files of {1} in {2}", updated.Count, episodeFiles.Count, message.Series.Title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_logger.ProgressDebug("No file dates changed for {0}", message.Series.Title);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|