mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
Fixed: Regression setting file date
This commit is contained in:
parent
3a8920a1e9
commit
4025005251
@ -22,17 +22,17 @@ public class UpdateMovieFileService : IUpdateMovieFileService,
|
||||
{
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly IMovieService _movieService;
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public UpdateMovieFileService(IDiskProvider diskProvider,
|
||||
IConfigService configService,
|
||||
IMovieService movieService,
|
||||
Logger logger)
|
||||
IConfigService configService,
|
||||
IMediaFileService mediaFileService,
|
||||
Logger logger)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_configService = configService;
|
||||
_movieService = movieService;
|
||||
_mediaFileService = mediaFileService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -107,18 +107,11 @@ public void Handle(MovieScannedEvent message)
|
||||
return;
|
||||
}
|
||||
|
||||
var movies = _movieService.MoviesWithFiles(message.Movie.Id);
|
||||
|
||||
var movieFiles = new List<MovieFile>();
|
||||
var movieFiles = _mediaFileService.GetFilesByMovie(message.Movie.Id);
|
||||
var updated = new List<MovieFile>();
|
||||
|
||||
foreach (var group in movies.GroupBy(e => e.MovieFileId))
|
||||
foreach (var movieFile in movieFiles)
|
||||
{
|
||||
var moviesInFile = group.Select(e => e).ToList();
|
||||
var movieFile = moviesInFile.First().MovieFile;
|
||||
|
||||
movieFiles.Add(movieFile);
|
||||
|
||||
if (ChangeFileDate(movieFile, message.Movie))
|
||||
{
|
||||
updated.Add(movieFile);
|
||||
@ -134,59 +127,5 @@ public void Handle(MovieScannedEvent message)
|
||||
_logger.ProgressDebug("No file dates changed for {0}", message.Movie.Title);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ChangeFileDateToLocalAirDate(string filePath, string fileDate, string fileTime)
|
||||
{
|
||||
DateTime airDate;
|
||||
|
||||
if (DateTime.TryParse(fileDate + ' ' + fileTime, out airDate))
|
||||
{
|
||||
// avoiding false +ve checks and set date skewing by not using UTC (Windows)
|
||||
DateTime oldDateTime = _diskProvider.FileGetLastWrite(filePath);
|
||||
|
||||
if (!DateTime.Equals(airDate, oldDateTime))
|
||||
{
|
||||
try
|
||||
{
|
||||
_diskProvider.FileSetLastWriteTime(filePath, airDate);
|
||||
_logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", filePath, oldDateTime, airDate);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Unable to set date of file [" + filePath + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Debug("Could not create valid date to change file [{0}]", filePath);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ChangeFileDateToUtcAirDate(string filePath, DateTime airDateUtc)
|
||||
{
|
||||
DateTime oldLastWrite = _diskProvider.FileGetLastWrite(filePath);
|
||||
|
||||
if (!DateTime.Equals(airDateUtc, oldLastWrite))
|
||||
{
|
||||
try
|
||||
{
|
||||
_diskProvider.FileSetLastWriteTime(filePath, airDateUtc);
|
||||
_logger.Debug("Date of file [{0}] changed from '{1}' to '{2}'", filePath, oldLastWrite, airDateUtc);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warn(ex, "Unable to set date of file [" + filePath + "]");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ public interface IMovieRepository : IBasicRepository<Movie>
|
||||
List<Movie> FindByTmdbId(List<int> tmdbids);
|
||||
Movie FindByTitleSlug(string slug);
|
||||
List<Movie> MoviesBetweenDates(DateTime start, DateTime end, bool includeUnmonitored);
|
||||
List<Movie> MoviesWithFiles(int movieId);
|
||||
PagingSpec<Movie> MoviesWithoutFiles(PagingSpec<Movie> pagingSpec);
|
||||
List<Movie> GetMoviesByFileId(int fileId);
|
||||
void SetFileId(int fileId, int movieId);
|
||||
@ -164,11 +163,6 @@ public List<Movie> MoviesBetweenDates(DateTime start, DateTime end, bool include
|
||||
return Query(builder);
|
||||
}
|
||||
|
||||
public List<Movie> MoviesWithFiles(int movieId)
|
||||
{
|
||||
return Query(x => x.MovieFileId != 0);
|
||||
}
|
||||
|
||||
public SqlBuilder MoviesWithoutFilesBuilder() => BuilderBase().Where<Movie>(x => x.MovieFileId == 0);
|
||||
|
||||
public PagingSpec<Movie> MoviesWithoutFiles(PagingSpec<Movie> pagingSpec)
|
||||
|
@ -47,8 +47,6 @@ public interface IMovieService
|
||||
List<Movie> FilterExistingMovies(List<Movie> movies);
|
||||
bool MoviePathExists(string folder);
|
||||
void RemoveAddOptions(Movie movie);
|
||||
List<Movie> MoviesWithFiles(int movieId);
|
||||
System.Linq.Expressions.Expression<Func<Movie, bool>> ConstructFilterExpression(string filterKey, string filterValue, string filterType = null);
|
||||
}
|
||||
|
||||
public class MovieService : IMovieService, IHandle<MovieFileAddedEvent>,
|
||||
@ -76,64 +74,6 @@ public MovieService(IMovieRepository movieRepository,
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public System.Linq.Expressions.Expression<Func<Movie, bool>> ConstructFilterExpression(string filterKey, string filterValue, string filterType = null)
|
||||
{
|
||||
//if (FilterKey == "all" && FilterValue == "all")
|
||||
//{
|
||||
// return v => v.Monitored == true || v.Monitored == false;
|
||||
//}
|
||||
if (filterKey == "monitored" && filterValue == "false")
|
||||
{
|
||||
return v => v.Monitored == false;
|
||||
}
|
||||
else if (filterKey == "monitored" && filterValue == "true")
|
||||
{
|
||||
return v => v.Monitored == true;
|
||||
}
|
||||
else if (filterKey == "status")
|
||||
{
|
||||
switch (filterValue)
|
||||
{
|
||||
case "released":
|
||||
return v => v.Status == MovieStatusType.Released;
|
||||
case "inCinemas":
|
||||
return v => v.Status == MovieStatusType.InCinemas;
|
||||
case "announced":
|
||||
return v => v.Status == MovieStatusType.Announced;
|
||||
case "available":
|
||||
return v => v.Monitored == true &&
|
||||
((v.MinimumAvailability == MovieStatusType.Released && v.Status >= MovieStatusType.Released) ||
|
||||
(v.MinimumAvailability == MovieStatusType.InCinemas && v.Status >= MovieStatusType.InCinemas) ||
|
||||
(v.MinimumAvailability == MovieStatusType.Announced && v.Status >= MovieStatusType.Announced) ||
|
||||
((v.MinimumAvailability == MovieStatusType.PreDB && v.Status >= MovieStatusType.Released) || v.HasPreDBEntry == true));
|
||||
}
|
||||
}
|
||||
else if (filterKey == "downloaded")
|
||||
{
|
||||
return v => v.MovieFileId == 0;
|
||||
}
|
||||
else if (filterKey == "title")
|
||||
{
|
||||
if (filterValue == string.Empty || filterValue == null)
|
||||
{
|
||||
return v => true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (filterType == "contains")
|
||||
{
|
||||
return v => v.CleanTitle.Contains(filterValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return v => v.CleanTitle == filterValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return v => true;
|
||||
}
|
||||
|
||||
public Movie GetMovie(int movieId)
|
||||
{
|
||||
return _movieRepository.Get(movieId);
|
||||
@ -465,11 +405,6 @@ public List<Movie> GetMoviesBetweenDates(DateTime start, DateTime end, bool incl
|
||||
return movies;
|
||||
}
|
||||
|
||||
public List<Movie> MoviesWithFiles(int movieId)
|
||||
{
|
||||
return _movieRepository.MoviesWithFiles(movieId);
|
||||
}
|
||||
|
||||
public PagingSpec<Movie> MoviesWithoutFiles(PagingSpec<Movie> pagingSpec)
|
||||
{
|
||||
var movieResult = _movieRepository.MoviesWithoutFiles(pagingSpec);
|
||||
|
Loading…
Reference in New Issue
Block a user