mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.5 KiB
75 lines
2.5 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Threading.Tasks; |
|
using ErsatzTV.Core.Domain; |
|
using ErsatzTV.Core.Interfaces.Metadata; |
|
using LanguageExt; |
|
using Microsoft.Extensions.Logging; |
|
|
|
namespace ErsatzTV.Core.Metadata |
|
{ |
|
public abstract class LocalFolderScanner |
|
{ |
|
protected static readonly List<string> VideoFileExtensions = new() |
|
{ |
|
".mpg", ".mp2", ".mpeg", ".mpe", ".mpv", ".ogg", ".mp4", |
|
".m4p", ".m4v", ".avi", ".wmv", ".mov", ".mkv", ".ts" |
|
}; |
|
|
|
protected static readonly List<string> ImageFileExtensions = new() |
|
{ |
|
"jpg", "jpeg", "png", "gif", "tbn" |
|
}; |
|
|
|
protected static readonly List<string> ExtraFiles = new() |
|
{ |
|
"behindthescenes", "deleted", "featurette", |
|
"interview", "scene", "short", "trailer", "other" |
|
}; |
|
|
|
protected static readonly List<string> ExtraDirectories = new List<string> |
|
{ |
|
"behind the scenes", "deleted scenes", "featurettes", |
|
"interviews", "scenes", "shorts", "trailers", "other", |
|
"extras", "specials" |
|
} |
|
.Map(s => $"{Path.DirectorySeparatorChar}{s}{Path.DirectorySeparatorChar}") |
|
.ToList(); |
|
|
|
private readonly ILocalFileSystem _localFileSystem; |
|
private readonly ILocalStatisticsProvider _localStatisticsProvider; |
|
private readonly ILogger _logger; |
|
|
|
protected LocalFolderScanner( |
|
ILocalFileSystem localFileSystem, |
|
ILocalStatisticsProvider localStatisticsProvider, |
|
ILogger logger) |
|
{ |
|
_localFileSystem = localFileSystem; |
|
_localStatisticsProvider = localStatisticsProvider; |
|
_logger = logger; |
|
} |
|
|
|
protected async Task<Either<BaseError, T>> UpdateStatistics<T>(T mediaItem, string ffprobePath) |
|
where T : MediaItem |
|
{ |
|
try |
|
{ |
|
if (mediaItem.Statistics is null || |
|
mediaItem.LastWriteTime < _localFileSystem.GetLastWriteTime(mediaItem.Path)) |
|
{ |
|
_logger.LogDebug("Refreshing {Attribute} for {Path}", "Statistics", mediaItem.Path); |
|
await _localStatisticsProvider.RefreshStatistics(ffprobePath, mediaItem); |
|
} |
|
|
|
return mediaItem; |
|
} |
|
catch (Exception ex) |
|
{ |
|
return BaseError.New(ex.Message); |
|
} |
|
} |
|
} |
|
}
|
|
|