|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using System.Globalization; |
|
|
|
using System.Globalization; |
|
|
|
|
|
|
|
using System.IO.Abstractions; |
|
|
|
using ErsatzTV.Core.Domain; |
|
|
|
using ErsatzTV.Core.Domain; |
|
|
|
using ErsatzTV.Core.Extensions; |
|
|
|
using ErsatzTV.Core.Extensions; |
|
|
|
using ErsatzTV.Core.Interfaces.Metadata; |
|
|
|
using ErsatzTV.Core.Interfaces.Metadata; |
|
|
|
@ -15,6 +16,7 @@ public class LocalSubtitlesProvider : ILocalSubtitlesProvider |
|
|
|
private readonly ILogger<LocalSubtitlesProvider> _logger; |
|
|
|
private readonly ILogger<LocalSubtitlesProvider> _logger; |
|
|
|
private readonly IMediaItemRepository _mediaItemRepository; |
|
|
|
private readonly IMediaItemRepository _mediaItemRepository; |
|
|
|
private readonly IMetadataRepository _metadataRepository; |
|
|
|
private readonly IMetadataRepository _metadataRepository; |
|
|
|
|
|
|
|
private readonly IFileSystem _fileSystem; |
|
|
|
|
|
|
|
|
|
|
|
private readonly SemaphoreSlim _slim = new(1, 1); |
|
|
|
private readonly SemaphoreSlim _slim = new(1, 1); |
|
|
|
private bool _disposedValue; |
|
|
|
private bool _disposedValue; |
|
|
|
@ -22,11 +24,13 @@ public class LocalSubtitlesProvider : ILocalSubtitlesProvider |
|
|
|
public LocalSubtitlesProvider( |
|
|
|
public LocalSubtitlesProvider( |
|
|
|
IMediaItemRepository mediaItemRepository, |
|
|
|
IMediaItemRepository mediaItemRepository, |
|
|
|
IMetadataRepository metadataRepository, |
|
|
|
IMetadataRepository metadataRepository, |
|
|
|
|
|
|
|
IFileSystem fileSystem, |
|
|
|
ILocalFileSystem localFileSystem, |
|
|
|
ILocalFileSystem localFileSystem, |
|
|
|
ILogger<LocalSubtitlesProvider> logger) |
|
|
|
ILogger<LocalSubtitlesProvider> logger) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_mediaItemRepository = mediaItemRepository; |
|
|
|
_mediaItemRepository = mediaItemRepository; |
|
|
|
_metadataRepository = metadataRepository; |
|
|
|
_metadataRepository = metadataRepository; |
|
|
|
|
|
|
|
_fileSystem = fileSystem; |
|
|
|
_localFileSystem = localFileSystem; |
|
|
|
_localFileSystem = localFileSystem; |
|
|
|
_logger = logger; |
|
|
|
_logger = logger; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -108,19 +112,19 @@ public class LocalSubtitlesProvider : ILocalSubtitlesProvider |
|
|
|
{ |
|
|
|
{ |
|
|
|
var result = new List<Subtitle>(); |
|
|
|
var result = new List<Subtitle>(); |
|
|
|
|
|
|
|
|
|
|
|
string? folder = Path.GetDirectoryName(mediaItemPath); |
|
|
|
string? folder = _fileSystem.Path.GetDirectoryName(mediaItemPath); |
|
|
|
string withoutExtension = Path.GetFileNameWithoutExtension(mediaItemPath); |
|
|
|
string withoutExtension = _fileSystem.Path.GetFileNameWithoutExtension(mediaItemPath); |
|
|
|
foreach (string file in _localFileSystem.ListFiles(folder, $"{withoutExtension}*")) |
|
|
|
foreach (string file in _localFileSystem.ListFiles(folder, $"{withoutExtension}*")) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string lowerFile = file.ToLowerInvariant(); |
|
|
|
string lowerFile = file.ToLowerInvariant(); |
|
|
|
|
|
|
|
|
|
|
|
string fileName = Path.GetFileName(file); |
|
|
|
string fileName = _fileSystem.Path.GetFileName(file); |
|
|
|
if (!fileName.StartsWith(withoutExtension, StringComparison.OrdinalIgnoreCase)) |
|
|
|
if (!fileName.StartsWith(withoutExtension, StringComparison.OrdinalIgnoreCase)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string extension = Path.GetExtension(lowerFile); |
|
|
|
string extension = _fileSystem.Path.GetExtension(lowerFile); |
|
|
|
string codec = extension switch |
|
|
|
string codec = extension switch |
|
|
|
{ |
|
|
|
{ |
|
|
|
".ssa" or ".ass" => "ass", |
|
|
|
".ssa" or ".ass" => "ass", |
|
|
|
@ -134,7 +138,7 @@ public class LocalSubtitlesProvider : ILocalSubtitlesProvider |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string language = Path.GetFileName(lowerFile); |
|
|
|
string language = _fileSystem.Path.GetFileName(lowerFile); |
|
|
|
var forced = false; |
|
|
|
var forced = false; |
|
|
|
var sdh = false; |
|
|
|
var sdh = false; |
|
|
|
|
|
|
|
|
|
|
|
@ -181,7 +185,7 @@ public class LocalSubtitlesProvider : ILocalSubtitlesProvider |
|
|
|
Forced = forced, |
|
|
|
Forced = forced, |
|
|
|
SDH = sdh, |
|
|
|
SDH = sdh, |
|
|
|
Language = language, |
|
|
|
Language = language, |
|
|
|
Path = saveFullPath ? file : Path.GetFileName(file), |
|
|
|
Path = saveFullPath ? file : _fileSystem.Path.GetFileName(file), |
|
|
|
DateAdded = DateTime.UtcNow, |
|
|
|
DateAdded = DateTime.UtcNow, |
|
|
|
DateUpdated = _localFileSystem.GetLastWriteTime(file) |
|
|
|
DateUpdated = _localFileSystem.GetLastWriteTime(file) |
|
|
|
}); |
|
|
|
}); |
|
|
|
@ -200,7 +204,7 @@ public class LocalSubtitlesProvider : ILocalSubtitlesProvider |
|
|
|
Forced = forced, |
|
|
|
Forced = forced, |
|
|
|
SDH = sdh, |
|
|
|
SDH = sdh, |
|
|
|
Language = culture.ThreeLetterISOLanguageName, |
|
|
|
Language = culture.ThreeLetterISOLanguageName, |
|
|
|
Path = saveFullPath ? file : Path.GetFileName(file), |
|
|
|
Path = saveFullPath ? file : _fileSystem.Path.GetFileName(file), |
|
|
|
DateAdded = DateTime.UtcNow, |
|
|
|
DateAdded = DateTime.UtcNow, |
|
|
|
DateUpdated = _localFileSystem.GetLastWriteTime(file) |
|
|
|
DateUpdated = _localFileSystem.GetLastWriteTime(file) |
|
|
|
}); |
|
|
|
}); |
|
|
|
|