Add Support for changing file date to either cinema or physical release.

Fixes #124
This commit is contained in:
Leonardo Galli
2017-01-17 15:02:48 +01:00
parent c64597c9f1
commit dd0a033b0f
6 changed files with 202 additions and 84 deletions

View File

@@ -20,7 +20,7 @@ namespace NzbDrone.Core.MediaFiles
}
public class UpdateMovieFileService : IUpdateMovieFileService,
IHandle<SeriesScannedEvent>
IHandle<MovieScannedEvent>
{
private readonly IDiskProvider _diskProvider;
private readonly IConfigService _configService;
@@ -47,10 +47,60 @@ namespace NzbDrone.Core.MediaFiles
{
var movieFilePath = Path.Combine(movie.Path, movieFile.RelativePath);
switch (_configService.FileDate)
{
case FileDateType.Release:
{
var airDate = movie.PhysicalRelease;
if (airDate == null)
{
return false;
}
return ChangeFileDate(movieFilePath, airDate.Value);
}
case FileDateType.Cinemas:
{
var airDate = movie.InCinemas;
if (airDate == null)
{
return false;
}
return ChangeFileDate(movieFilePath, airDate.Value);
}
}
return false;
}
public void Handle(SeriesScannedEvent message)
private bool ChangeFileDate(string filePath, DateTime date)
{
DateTime oldDateTime = _diskProvider.FileGetLastWrite(filePath);
if (!DateTime.Equals(date, oldDateTime))
{
try
{
_diskProvider.FileSetLastWriteTime(filePath, date);
_logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", filePath, oldDateTime, date);
return true;
}
catch (Exception ex)
{
_logger.Warn(ex, "Unable to set date of file [" + filePath + "]");
}
}
return false;
}
public void Handle(MovieScannedEvent message)
{
if (_configService.FileDate == FileDateType.None)
{