aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Emby.Naming/Common/NamingOptions.cs4
-rw-r--r--Emby.Naming/ExternalFiles/ExternalPathParser.cs8
-rw-r--r--Emby.Server.Implementations/IO/ManagedFileSystem.cs12
-rw-r--r--Emby.Server.Implementations/Localization/Core/cy.json54
-rw-r--r--Emby.Server.Implementations/Localization/Core/es.json4
-rw-r--r--Emby.Server.Implementations/Localization/Core/zh-HK.json2
-rw-r--r--Emby.Server.Implementations/TV/TVSeriesManager.cs15
-rw-r--r--Jellyfin.Api/Controllers/TvShowsController.cs6
-rw-r--r--MediaBrowser.Controller/Entities/BaseItem.cs2
-rw-r--r--MediaBrowser.Model/IO/IFileSystem.cs14
-rw-r--r--MediaBrowser.Model/Querying/NextUpQuery.cs4
-rw-r--r--MediaBrowser.Providers/MediaInfo/AudioResolver.cs12
-rw-r--r--MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs7
-rw-r--r--MediaBrowser.Providers/MediaInfo/MediaInfoResolver.cs36
-rw-r--r--MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs12
-rw-r--r--tests/Jellyfin.Providers.Tests/MediaInfo/AudioResolverTests.cs9
-rw-r--r--tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs107
-rw-r--r--tests/Jellyfin.Providers.Tests/MediaInfo/SubtitleResolverTests.cs9
-rw-r--r--tests/Jellyfin.Providers.Tests/Test Data/Video/My.Video.mkv0
19 files changed, 248 insertions, 69 deletions
diff --git a/Emby.Naming/Common/NamingOptions.cs b/Emby.Naming/Common/NamingOptions.cs
index a79153e86..de9c75da2 100644
--- a/Emby.Naming/Common/NamingOptions.cs
+++ b/Emby.Naming/Common/NamingOptions.cs
@@ -266,7 +266,7 @@ namespace Emby.Naming.Common
MediaFlagDelimiters = new[]
{
- "."
+ '.'
};
MediaForcedFlags = new[]
@@ -715,7 +715,7 @@ namespace Emby.Naming.Common
/// <summary>
/// Gets or sets list of external media flag delimiters.
/// </summary>
- public string[] MediaFlagDelimiters { get; set; }
+ public char[] MediaFlagDelimiters { get; set; }
/// <summary>
/// Gets or sets list of external media forced flags.
diff --git a/Emby.Naming/ExternalFiles/ExternalPathParser.cs b/Emby.Naming/ExternalFiles/ExternalPathParser.cs
index 9d07dc2f9..3bde3a1cf 100644
--- a/Emby.Naming/ExternalFiles/ExternalPathParser.cs
+++ b/Emby.Naming/ExternalFiles/ExternalPathParser.cs
@@ -61,11 +61,11 @@ namespace Emby.Naming.ExternalFiles
{
var languageString = extraString;
var titleString = string.Empty;
- int separatorLength = separator.Length;
+ const int SeparatorLength = 1;
while (languageString.Length > 0)
{
- int lastSeparator = languageString.LastIndexOf(separator, StringComparison.OrdinalIgnoreCase);
+ int lastSeparator = languageString.LastIndexOf(separator);
if (lastSeparator == -1)
{
@@ -73,7 +73,7 @@ namespace Emby.Naming.ExternalFiles
}
string currentSlice = languageString[lastSeparator..];
- string currentSliceWithoutSeparator = currentSlice[separatorLength..];
+ string currentSliceWithoutSeparator = currentSlice[SeparatorLength..];
if (_namingOptions.MediaDefaultFlags.Any(s => currentSliceWithoutSeparator.Contains(s, StringComparison.OrdinalIgnoreCase)))
{
@@ -107,7 +107,7 @@ namespace Emby.Naming.ExternalFiles
languageString = languageString[..lastSeparator];
}
- pathInfo.Title = separatorLength <= titleString.Length ? titleString[separatorLength..] : null;
+ pathInfo.Title = titleString.Length >= SeparatorLength ? titleString[SeparatorLength..] : null;
}
return pathInfo;
diff --git a/Emby.Server.Implementations/IO/ManagedFileSystem.cs b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
index 4f8a52f41..399ece7fd 100644
--- a/Emby.Server.Implementations/IO/ManagedFileSystem.cs
+++ b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
@@ -704,6 +704,18 @@ namespace Emby.Server.Implementations.IO
return Directory.EnumerateFileSystemEntries(path, "*", GetEnumerationOptions(recursive));
}
+ /// <inheritdoc />
+ public virtual bool DirectoryExists(string path)
+ {
+ return Directory.Exists(path);
+ }
+
+ /// <inheritdoc />
+ public virtual bool FileExists(string path)
+ {
+ return File.Exists(path);
+ }
+
private EnumerationOptions GetEnumerationOptions(bool recursive)
{
return new EnumerationOptions
diff --git a/Emby.Server.Implementations/Localization/Core/cy.json b/Emby.Server.Implementations/Localization/Core/cy.json
index 7fc27e18a..981614005 100644
--- a/Emby.Server.Implementations/Localization/Core/cy.json
+++ b/Emby.Server.Implementations/Localization/Core/cy.json
@@ -54,5 +54,57 @@
"Undefined": "Heb ddiffiniad",
"TvShows": "Rhaglenni teledu",
"HeaderLiveTV": "Teledu Byw",
- "User": "Defnyddiwr"
+ "User": "Defnyddiwr",
+ "TaskCleanLogsDescription": "Dileu ffeiliau log sy'n fwy na {0} diwrnod oed.",
+ "TaskCleanLogs": "Glanhau ffolder log",
+ "TaskRefreshLibraryDescription": "Sganio'ch llyfrgell gyfryngau am ffeiliau newydd ac yn adnewyddu metaddata.",
+ "TaskRefreshLibrary": "Sganwich Llyfrgell Cyfryngau",
+ "TaskCleanActivityLogDescription": "Yn dileu cofnodion log gweithgaredd sy'n hŷn na'r oedran a nodwyd.",
+ "TaskCleanActivityLog": "Glanhau Log Gweithgaredd",
+ "SubtitleDownloadFailureFromForItem": "Methodd is-deitlau lawrlwytho o {0} ar gyfer {1}",
+ "NotificationOptionPluginError": "Methodd ategyn",
+ "NotificationOptionAudioPlaybackStopped": "Stopiwyd chwarae sain",
+ "NotificationOptionAudioPlayback": "Dechreuwyd chwarae sain",
+ "MessageServerConfigurationUpdated": "Mae ffurfweddiad gweinydd wedi'i ddiweddaru",
+ "MessageNamedServerConfigurationUpdatedWithValue": "Mae adran ffurfweddu gweinydd {0} wedi'i diweddaru",
+ "FailedLoginAttemptWithUserName": "Cais mewngofnodi wedi methu gan {0}",
+ "ValueHasBeenAddedToLibrary": "{0} wedi'i hychwanegu at eich llyfrgell gyfryngau",
+ "UserStoppedPlayingItemWithValues": "{0} wedi gorffen chwarae {1} ar {2}",
+ "UserStartedPlayingItemWithValues": "{0} yn chwarae {1} ar {2}",
+ "UserPolicyUpdatedWithName": "Polisi defnyddiwr wedi'i newid ar gyfer {0}",
+ "UserPasswordChangedWithName": "Cyfrinair wedi'i newid ar gyfer defnyddiwr {0}",
+ "UserOnlineFromDevice": "Mae {0} ar-lein o {1}",
+ "UserOfflineFromDevice": "Mae {0} wedi datgysylltu o {1}",
+ "UserLockedOutWithName": "Mae defnyddiwr {0} wedi'i gloi allan",
+ "UserDownloadingItemWithValues": "Mae {0} yn lawrlwytho {1}",
+ "UserDeletedWithName": "Defnyddiwr {0} wedi'i ddileu",
+ "UserCreatedWithName": "Defnyddiwr {0} wedi'i greu",
+ "StartupEmbyServerIsLoading": "Gweinydd Jellyfin yn llwytho. Triwch eto mewn ychydig.",
+ "ServerNameNeedsToBeRestarted": "Mae angen ailddechrau {0}",
+ "PluginUpdatedWithName": "{0} wedi'i ddiweddaru",
+ "PluginUninstalledWithName": "{0} wedi'i ddadosod",
+ "PluginInstalledWithName": "{0} wedi'i osod",
+ "NotificationOptionVideoPlaybackStopped": "Stopiwyd chwarae fideo",
+ "NotificationOptionVideoPlayback": "Dechreuwyd chwarae fideo",
+ "NotificationOptionUserLockedOut": "Defnyddiwr wedi'i gloi allan",
+ "NotificationOptionTaskFailed": "Methwyd cyflawni y dasg a drefnwyd",
+ "NotificationOptionServerRestartRequired": "Mae angen ailgychwyn y gweinydd",
+ "NotificationOptionPluginUpdateInstalled": "Diweddariad ategyn wedi'i osod",
+ "NotificationOptionPluginUninstalled": "Ategyn wedi'i ddadosod",
+ "NotificationOptionPluginInstalled": "Ategyn wedi'i osod",
+ "NotificationOptionNewLibraryContent": "Cynnwys newydd ar gael",
+ "NotificationOptionCameraImageUploaded": "Llun camera wedi'i huwchlwytho",
+ "NotificationOptionApplicationUpdateInstalled": "Diweddariad ap wedi'i osod",
+ "NotificationOptionApplicationUpdateAvailable": "Diweddariad ap ar gael",
+ "NewVersionIsAvailable": "Mae fersiwn diweddarach o'r gweinydd Jellyfin ar gael.",
+ "NameInstallFailed": "Gosodiad {0} wedi methu",
+ "MessageApplicationUpdatedTo": "Gweinydd Jellyfin wedi'i ddiweddaru i {0}",
+ "MessageApplicationUpdated": "Gweinydd Jellyfin wedi'i ddiweddaru",
+ "LabelIpAddressValue": "Cyfeiriad IP: {0}",
+ "ItemRemovedWithName": "{0} wedi'i dynnu o'r llyfrgell",
+ "ItemAddedWithName": "{0} wedi'i adio i'r llyfrgell",
+ "HeaderRecordingGroups": "Grwpiau Recordio",
+ "HeaderFavoriteSongs": "Ffefryn Ganeuon",
+ "HeaderFavoriteShows": "Ffefryn Shoeau",
+ "HeaderFavoriteEpisodes": "Ffefryn Rhaglenni"
}
diff --git a/Emby.Server.Implementations/Localization/Core/es.json b/Emby.Server.Implementations/Localization/Core/es.json
index f8c69712e..4918f468b 100644
--- a/Emby.Server.Implementations/Localization/Core/es.json
+++ b/Emby.Server.Implementations/Localization/Core/es.json
@@ -120,5 +120,7 @@
"Forced": "Forzado",
"Default": "Predeterminado",
"TaskOptimizeDatabase": "Optimizar la base de datos",
- "TaskOptimizeDatabaseDescription": "Compacta y libera el espacio libre en la base de datos. Ejecutar esta tarea tras escanear la biblioteca o hacer cambios que impliquen modificaciones en la base de datos puede mejorar el rendimiento."
+ "TaskOptimizeDatabaseDescription": "Compacta y libera el espacio libre en la base de datos. Ejecutar esta tarea tras escanear la biblioteca o hacer cambios que impliquen modificaciones en la base de datos puede mejorar el rendimiento.",
+ "TaskKeyframeExtractorDescription": "Extrae los fotogramas clave de los archivos de vídeo para crear listas HLS más precisas. Esta tarea puede tardar mucho tiempo.",
+ "TaskKeyframeExtractor": "Extractor de Fotogramas Clave"
}
diff --git a/Emby.Server.Implementations/Localization/Core/zh-HK.json b/Emby.Server.Implementations/Localization/Core/zh-HK.json
index 1cc97bc27..ac74da67d 100644
--- a/Emby.Server.Implementations/Localization/Core/zh-HK.json
+++ b/Emby.Server.Implementations/Localization/Core/zh-HK.json
@@ -103,7 +103,7 @@
"TaskCleanTranscodeDescription": "刪除超過一天的轉碼文件。",
"TaskCleanTranscode": "清理轉碼目錄",
"TaskUpdatePluginsDescription": "下載並安裝配置為自動更新的插件的更新。",
- "TaskRefreshPeopleDescription": "更新媒體庫中演員和導演的metadata。",
+ "TaskRefreshPeopleDescription": "更新媒體庫中演員和導演的元數據。",
"TaskCleanLogsDescription": "刪除超過{0}天的日誌文件。",
"TaskCleanLogs": "清理日誌目錄",
"TaskRefreshLibrary": "掃描媒體庫",
diff --git a/Emby.Server.Implementations/TV/TVSeriesManager.cs b/Emby.Server.Implementations/TV/TVSeriesManager.cs
index a47650a32..f8ba85af1 100644
--- a/Emby.Server.Implementations/TV/TVSeriesManager.cs
+++ b/Emby.Server.Implementations/TV/TVSeriesManager.cs
@@ -126,7 +126,8 @@ namespace Emby.Server.Implementations.TV
parentsFolders.ToList())
.Cast<Episode>()
.Where(episode => !string.IsNullOrEmpty(episode.SeriesPresentationUniqueKey))
- .Select(GetUniqueSeriesKey);
+ .Select(GetUniqueSeriesKey)
+ .ToList();
// Avoid implicitly captured closure
var episodes = GetNextUpEpisodes(request, user, items, options);
@@ -134,13 +135,21 @@ namespace Emby.Server.Implementations.TV
return GetResult(episodes, request);
}
- public IEnumerable<Episode> GetNextUpEpisodes(NextUpQuery request, User user, IEnumerable<string> seriesKeys, DtoOptions dtoOptions)
+ public IEnumerable<Episode> GetNextUpEpisodes(NextUpQuery request, User user, IReadOnlyList<string> seriesKeys, DtoOptions dtoOptions)
{
// Avoid implicitly captured closure
var currentUser = user;
var allNextUp = seriesKeys
- .Select(i => GetNextUp(i, currentUser, dtoOptions, request.Rewatching));
+ .Select(i => GetNextUp(i, currentUser, dtoOptions, false));
+
+ if (request.EnableRewatching)
+ {
+ allNextUp = allNextUp.Concat(
+ seriesKeys.Select(i => GetNextUp(i, currentUser, dtoOptions, true))
+ )
+ .OrderByDescending(i => i.Item1);
+ }
// If viewing all next up for all series, remove first episodes
// But if that returns empty, keep those first episodes (avoid completely empty view)
diff --git a/Jellyfin.Api/Controllers/TvShowsController.cs b/Jellyfin.Api/Controllers/TvShowsController.cs
index 5d39d906f..636130543 100644
--- a/Jellyfin.Api/Controllers/TvShowsController.cs
+++ b/Jellyfin.Api/Controllers/TvShowsController.cs
@@ -68,7 +68,7 @@ namespace Jellyfin.Api.Controllers
/// <param name="nextUpDateCutoff">Optional. Starting date of shows to show in Next Up section.</param>
/// <param name="enableTotalRecordCount">Whether to enable the total records count. Defaults to true.</param>
/// <param name="disableFirstEpisode">Whether to disable sending the first episode in a series as next up.</param>
- /// <param name="rewatching">Whether to get a rewatching next up instead of standard next up.</param>
+ /// <param name="enableRewatching">Whether to include watched episode in next up results.</param>
/// <returns>A <see cref="QueryResult{BaseItemDto}"/> with the next up episodes.</returns>
[HttpGet("NextUp")]
[ProducesResponseType(StatusCodes.Status200OK)]
@@ -86,7 +86,7 @@ namespace Jellyfin.Api.Controllers
[FromQuery] DateTime? nextUpDateCutoff,
[FromQuery] bool enableTotalRecordCount = true,
[FromQuery] bool disableFirstEpisode = false,
- [FromQuery] bool rewatching = false)
+ [FromQuery] bool enableRewatching = false)
{
var options = new DtoOptions { Fields = fields }
.AddClientFields(Request)
@@ -103,7 +103,7 @@ namespace Jellyfin.Api.Controllers
EnableTotalRecordCount = enableTotalRecordCount,
DisableFirstEpisode = disableFirstEpisode,
NextUpDateCutoff = nextUpDateCutoff ?? DateTime.MinValue,
- Rewatching = rewatching
+ EnableRewatching = enableRewatching
},
options);
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index 0f62e8e1e..c52732858 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -887,7 +887,7 @@ namespace MediaBrowser.Controller.Entities
return Name;
}
- public string GetInternalMetadataPath()
+ public virtual string GetInternalMetadataPath()
{
var basePath = ConfigurationManager.ApplicationPaths.InternalMetadataPath;
diff --git a/MediaBrowser.Model/IO/IFileSystem.cs b/MediaBrowser.Model/IO/IFileSystem.cs
index 7207795b0..786b20e9e 100644
--- a/MediaBrowser.Model/IO/IFileSystem.cs
+++ b/MediaBrowser.Model/IO/IFileSystem.cs
@@ -200,5 +200,19 @@ namespace MediaBrowser.Model.IO
void SetAttributes(string path, bool isHidden, bool readOnly);
IEnumerable<FileSystemMetadata> GetDrives();
+
+ /// <summary>
+ /// Determines whether the directory exists.
+ /// </summary>
+ /// <param name="path">The path.</param>
+ /// <returns>Whether the path exists.</returns>
+ bool DirectoryExists(string path);
+
+ /// <summary>
+ /// Determines whether the file exists.
+ /// </summary>
+ /// <param name="path">The path.</param>
+ /// <returns>Whether the path exists.</returns>
+ bool FileExists(string path);
}
}
diff --git a/MediaBrowser.Model/Querying/NextUpQuery.cs b/MediaBrowser.Model/Querying/NextUpQuery.cs
index 7c65fda1a..133d6a916 100644
--- a/MediaBrowser.Model/Querying/NextUpQuery.cs
+++ b/MediaBrowser.Model/Querying/NextUpQuery.cs
@@ -14,7 +14,7 @@ namespace MediaBrowser.Model.Querying
EnableTotalRecordCount = true;
DisableFirstEpisode = false;
NextUpDateCutoff = DateTime.MinValue;
- Rewatching = false;
+ EnableRewatching = false;
}
/// <summary>
@@ -86,6 +86,6 @@ namespace MediaBrowser.Model.Querying
/// <summary>
/// Gets or sets a value indicating whether getting rewatching next up list.
/// </summary>
- public bool Rewatching { get; set; }
+ public bool EnableRewatching { get; set; }
}
}
diff --git a/MediaBrowser.Providers/MediaInfo/AudioResolver.cs b/MediaBrowser.Providers/MediaInfo/AudioResolver.cs
index ff90eeffb..0bdf447ba 100644
--- a/MediaBrowser.Providers/MediaInfo/AudioResolver.cs
+++ b/MediaBrowser.Providers/MediaInfo/AudioResolver.cs
@@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Globalization;
+using MediaBrowser.Model.IO;
namespace MediaBrowser.Providers.MediaInfo
{
@@ -16,13 +17,20 @@ namespace MediaBrowser.Providers.MediaInfo
/// </summary>
/// <param name="localizationManager">The localization manager.</param>
/// <param name="mediaEncoder">The media encoder.</param>
+ /// <param name="fileSystem">The file system.</param>
/// <param name="namingOptions">The <see cref="NamingOptions"/> object containing FileExtensions, MediaDefaultFlags, MediaForcedFlags and MediaFlagDelimiters.</param>
public AudioResolver(
ILocalizationManager localizationManager,
IMediaEncoder mediaEncoder,
+ IFileSystem fileSystem,
NamingOptions namingOptions)
- : base(localizationManager, mediaEncoder, namingOptions, DlnaProfileType.Audio)
- {
+ : base(
+ localizationManager,
+ mediaEncoder,
+ fileSystem,
+ namingOptions,
+ DlnaProfileType.Audio)
+ {
}
}
}
diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs
index 560e20dae..fcd3f28d4 100644
--- a/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs
+++ b/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs
@@ -19,9 +19,9 @@ using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Subtitles;
-using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
+using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using Microsoft.Extensions.Logging;
@@ -58,11 +58,12 @@ namespace MediaBrowser.Providers.MediaInfo
ISubtitleManager subtitleManager,
IChapterManager chapterManager,
ILibraryManager libraryManager,
+ IFileSystem fileSystem,
NamingOptions namingOptions)
{
_logger = logger;
- _audioResolver = new AudioResolver(localization, mediaEncoder, namingOptions);
- _subtitleResolver = new SubtitleResolver(localization, mediaEncoder, namingOptions);
+ _audioResolver = new AudioResolver(localization, mediaEncoder, fileSystem, namingOptions);
+ _subtitleResolver = new SubtitleResolver(localization, mediaEncoder, fileSystem, namingOptions);
_videoProber = new FFProbeVideoInfo(
_logger,
mediaSourceManager,
diff --git a/MediaBrowser.Providers/MediaInfo/MediaInfoResolver.cs b/MediaBrowser.Providers/MediaInfo/MediaInfoResolver.cs
index 40b45faf5..933827207 100644
--- a/MediaBrowser.Providers/MediaInfo/MediaInfoResolver.cs
+++ b/MediaBrowser.Providers/MediaInfo/MediaInfoResolver.cs
@@ -14,6 +14,7 @@ using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
+using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
namespace MediaBrowser.Providers.MediaInfo
@@ -24,16 +25,6 @@ namespace MediaBrowser.Providers.MediaInfo
public abstract class MediaInfoResolver
{
/// <summary>
- /// The <see cref="CompareOptions"/> instance.
- /// </summary>
- private const CompareOptions CompareOptions = System.Globalization.CompareOptions.IgnoreCase | System.Globalization.CompareOptions.IgnoreNonSpace | System.Globalization.CompareOptions.IgnoreSymbols;
-
- /// <summary>
- /// The <see cref="CompareInfo"/> instance.
- /// </summary>
- private readonly CompareInfo _compareInfo = CultureInfo.InvariantCulture.CompareInfo;
-
- /// <summary>
/// The <see cref="ExternalPathParser"/> instance.
/// </summary>
private readonly ExternalPathParser _externalPathParser;
@@ -43,6 +34,8 @@ namespace MediaBrowser.Providers.MediaInfo
/// </summary>
private readonly IMediaEncoder _mediaEncoder;
+ private readonly IFileSystem _fileSystem;
+
/// <summary>
/// The <see cref="NamingOptions"/> instance.
/// </summary>
@@ -58,15 +51,18 @@ namespace MediaBrowser.Providers.MediaInfo
/// </summary>
/// <param name="localizationManager">The localization manager.</param>
/// <param name="mediaEncoder">The media encoder.</param>
+ /// <param name="fileSystem">The file system.</param>
/// <param name="namingOptions">The <see cref="NamingOptions"/> object containing FileExtensions, MediaDefaultFlags, MediaForcedFlags and MediaFlagDelimiters.</param>
/// <param name="type">The <see cref="DlnaProfileType"/> of the parsed file.</param>
protected MediaInfoResolver(
ILocalizationManager localizationManager,
IMediaEncoder mediaEncoder,
+ IFileSystem fileSystem,
NamingOptions namingOptions,
DlnaProfileType type)
{
_mediaEncoder = mediaEncoder;
+ _fileSystem = fileSystem;
_namingOptions = namingOptions;
_type = type;
_externalPathParser = new ExternalPathParser(namingOptions, localizationManager, _type);
@@ -148,28 +144,32 @@ namespace MediaBrowser.Providers.MediaInfo
// Check if video folder exists
string folder = video.ContainingFolderPath;
- if (!Directory.Exists(folder))
+ if (!_fileSystem.DirectoryExists(folder))
{
return Array.Empty<ExternalPathParserResult>();
}
- var externalPathInfos = new List<ExternalPathParserResult>();
-
var files = directoryService.GetFilePaths(folder, clearCache).ToList();
- files.AddRange(directoryService.GetFilePaths(video.GetInternalMetadataPath(), clearCache));
+ var internalMetadataPath = video.GetInternalMetadataPath();
+ if (_fileSystem.DirectoryExists(internalMetadataPath))
+ {
+ files.AddRange(directoryService.GetFilePaths(internalMetadataPath, clearCache));
+ }
if (!files.Any())
{
return Array.Empty<ExternalPathParserResult>();
}
+ var externalPathInfos = new List<ExternalPathParserResult>();
+ ReadOnlySpan<char> prefix = video.FileNameWithoutExtension;
foreach (var file in files)
{
- var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
- if (_compareInfo.IsPrefix(fileNameWithoutExtension, video.FileNameWithoutExtension, CompareOptions, out int matchLength)
- && (fileNameWithoutExtension.Length == matchLength || _namingOptions.MediaFlagDelimiters.Contains(fileNameWithoutExtension[matchLength].ToString())))
+ var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.AsSpan());
+ if (prefix.Equals(fileNameWithoutExtension[..prefix.Length], StringComparison.OrdinalIgnoreCase)
+ && (fileNameWithoutExtension.Length == prefix.Length || _namingOptions.MediaFlagDelimiters.Contains(fileNameWithoutExtension[prefix.Length])))
{
- var externalPathInfo = _externalPathParser.ParseFile(file, fileNameWithoutExtension[matchLength..]);
+ var externalPathInfo = _externalPathParser.ParseFile(file, fileNameWithoutExtension[prefix.Length..].ToString());
if (externalPathInfo != null)
{
diff --git a/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs b/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs
index 289036fda..4b9ba944a 100644
--- a/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs
+++ b/MediaBrowser.Providers/MediaInfo/SubtitleResolver.cs
@@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Globalization;
+using MediaBrowser.Model.IO;
namespace MediaBrowser.Providers.MediaInfo
{
@@ -16,13 +17,20 @@ namespace MediaBrowser.Providers.MediaInfo
/// </summary>
/// <param name="localizationManager">The localization manager.</param>
/// <param name="mediaEncoder">The media encoder.</param>
+ /// <param name="fileSystem">The file system.</param>
/// <param name="namingOptions">The <see cref="NamingOptions"/> object containing FileExtensions, MediaDefaultFlags, MediaForcedFlags and MediaFlagDelimiters.</param>
public SubtitleResolver(
ILocalizationManager localizationManager,
IMediaEncoder mediaEncoder,
+ IFileSystem fileSystem,
NamingOptions namingOptions)
- : base(localizationManager, mediaEncoder, namingOptions, DlnaProfileType.Subtitle)
- {
+ : base(
+ localizationManager,
+ mediaEncoder,
+ fileSystem,
+ namingOptions,
+ DlnaProfileType.Subtitle)
+ {
}
}
}
diff --git a/tests/Jellyfin.Providers.Tests/MediaInfo/AudioResolverTests.cs b/tests/Jellyfin.Providers.Tests/MediaInfo/AudioResolverTests.cs
index 381d6c72d..aec523882 100644
--- a/tests/Jellyfin.Providers.Tests/MediaInfo/AudioResolverTests.cs
+++ b/tests/Jellyfin.Providers.Tests/MediaInfo/AudioResolverTests.cs
@@ -11,6 +11,7 @@ using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
+using MediaBrowser.Model.IO;
using MediaBrowser.Providers.MediaInfo;
using Moq;
using Xunit;
@@ -45,7 +46,13 @@ public class AudioResolverTests
}
}));
- _audioResolver = new AudioResolver(localizationManager, mediaEncoder.Object, new NamingOptions());
+ var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
+ fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.VideoDirectoryRegex)))
+ .Returns(true);
+ fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.MetadataDirectoryRegex)))
+ .Returns(true);
+
+ _audioResolver = new AudioResolver(localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
}
[Theory]
diff --git a/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs b/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs
index 926ec5c91..9bd02d956 100644
--- a/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs
+++ b/tests/Jellyfin.Providers.Tests/MediaInfo/MediaInfoResolverTests.cs
@@ -15,6 +15,7 @@ using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
+using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Providers.MediaInfo;
using Moq;
@@ -25,9 +26,9 @@ namespace Jellyfin.Providers.Tests.MediaInfo;
public class MediaInfoResolverTests
{
public const string VideoDirectoryPath = "Test Data/Video";
- private const string VideoDirectoryRegex = @"Test Data[/\\]Video";
- private const string MetadataDirectoryPath = "library/00/00000000000000000000000000000000";
- private const string MetadataDirectoryRegex = @"library.*";
+ public const string VideoDirectoryRegex = @"Test Data[/\\]Video";
+ public const string MetadataDirectoryPath = "library/00/00000000000000000000000000000000";
+ public const string MetadataDirectoryRegex = @"library.*";
private readonly ILocalizationManager _localizationManager;
private readonly MediaInfoResolver _subtitleResolver;
@@ -61,13 +62,19 @@ public class MediaInfoResolverTests
}
}));
- _subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, new NamingOptions());
+ var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
+ fileSystem.Setup(fs => fs.DirectoryExists(It.IsAny<string>()))
+ .Returns(false);
+ fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(VideoDirectoryRegex)))
+ .Returns(true);
+ fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MetadataDirectoryRegex)))
+ .Returns(true);
+
+ _subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
}
- [Theory]
- [InlineData("https://url.com/My.Video.mkv")]
- [InlineData("non-existent/path")]
- public void GetExternalFiles_BadPaths_ReturnsNoSubtitles(string path)
+ [Fact]
+ public void GetExternalFiles_BadProtocol_ReturnsNoSubtitles()
{
// need a media source manager capable of returning something other than file protocol
var mediaSourceManager = new Mock<IMediaSourceManager>();
@@ -77,27 +84,67 @@ public class MediaInfoResolverTests
var video = new Movie
{
- Path = path
+ Path = "https://url.com/My.Video.mkv"
};
- var files = _subtitleResolver.GetExternalFiles(video, Mock.Of<IDirectoryService>(), false);
+ Assert.Empty(_subtitleResolver.GetExternalFiles(video, Mock.Of<IDirectoryService>(), false));
+ }
+
+ [Theory]
+ [InlineData(false)]
+ [InlineData(true)]
+ public void GetExternalFiles_MissingDirectory_DirectoryNotQueried(bool metadataDirectory)
+ {
+ BaseItem.MediaSourceManager = Mock.Of<IMediaSourceManager>();
+
+ string containingFolderPath, metadataPath;
+
+ if (metadataDirectory)
+ {
+ containingFolderPath = VideoDirectoryPath;
+ metadataPath = "invalid";
+ }
+ else
+ {
+ containingFolderPath = "invalid";
+ metadataPath = MetadataDirectoryPath;
+ }
+
+ var video = new Mock<Movie>();
+ video.Setup(m => m.Path)
+ .Returns(VideoDirectoryPath + "/My.Video.mkv");
+ video.Setup(m => m.ContainingFolderPath)
+ .Returns(containingFolderPath);
+ video.Setup(m => m.GetInternalMetadataPath())
+ .Returns(metadataPath);
- Assert.Empty(files);
+ string pathNotFoundRegex = metadataDirectory ? MetadataDirectoryRegex : VideoDirectoryRegex;
+
+ var directoryService = new Mock<IDirectoryService>(MockBehavior.Strict);
+ // any path other than test target exists and provides an empty listing
+ directoryService.Setup(ds => ds.GetFilePaths(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()))
+ .Returns(Array.Empty<string>());
+
+ _subtitleResolver.GetExternalFiles(video.Object, directoryService.Object, false);
+
+ directoryService.Verify(
+ ds => ds.GetFilePaths(It.IsRegex(pathNotFoundRegex), It.IsAny<bool>(), It.IsAny<bool>()),
+ Times.Never);
}
[Theory]
- [InlineData("My.Video.srt", null)] // exact
- [InlineData("My.Video.en.srt", "eng")]
- [InlineData("MyVideo.en.srt", "eng")] // shorter title
- [InlineData("My _ Video.en.srt", "eng")] // longer title
- [InlineData("My.Video.en.srt", "eng", true)]
- public void GetExternalFiles_FuzzyMatching_MatchesAndParsesToken(string file, string? language, bool metadataDirectory = false)
+ [InlineData("My.Video.mkv", "My.Video.srt", null)]
+ [InlineData("My.Video.mkv", "My.Video.en.srt", "eng")]
+ [InlineData("My.Video.mkv", "My.Video.en.srt", "eng", true)]
+ [InlineData("Example Movie (2021).mp4", "Example Movie (2021).English.Srt", "eng")]
+ [InlineData("[LTDB] Who Framed Roger Rabbit (1998) - [Bluray-1080p].mkv", "[LTDB] Who Framed Roger Rabbit (1998) - [Bluray-1080p].en.srt", "eng")]
+ public void GetExternalFiles_NameMatching_MatchesAndParsesToken(string movie, string file, string? language, bool metadataDirectory = false)
{
BaseItem.MediaSourceManager = Mock.Of<IMediaSourceManager>();
var video = new Movie
{
- Path = VideoDirectoryPath + "/My.Video.mkv"
+ Path = VideoDirectoryPath + "/" + movie
};
var directoryService = GetDirectoryServiceForExternalFile(file, metadataDirectory);
@@ -115,7 +162,7 @@ public class MediaInfoResolverTests
[InlineData("My.Video.txt")]
[InlineData("My.Video Sequel.srt")]
[InlineData("Some.Other.Video.srt")]
- public void GetExternalFiles_FuzzyMatching_RejectsNonMatches(string file)
+ public void GetExternalFiles_NameMatching_RejectsNonMatches(string file)
{
BaseItem.MediaSourceManager = Mock.Of<IMediaSourceManager>();
@@ -132,7 +179,6 @@ public class MediaInfoResolverTests
[Theory]
[InlineData("https://url.com/My.Video.mkv")]
- [InlineData("non-existent/path")]
[InlineData(VideoDirectoryPath)] // valid but no files found for this test
public async void GetExternalStreams_BadPaths_ReturnsNoSubtitles(string path)
{
@@ -152,8 +198,9 @@ public class MediaInfoResolverTests
.Returns(Array.Empty<string>());
var mediaEncoder = Mock.Of<IMediaEncoder>(MockBehavior.Strict);
+ var fileSystem = Mock.Of<IFileSystem>();
- var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder, new NamingOptions());
+ var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder, fileSystem, new NamingOptions());
var streams = await subtitleResolver.GetExternalStreamsAsync(video, 0, directoryService.Object, false, CancellationToken.None);
@@ -252,7 +299,13 @@ public class MediaInfoResolverTests
MediaStreams = inputStreams.ToList()
}));
- var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, new NamingOptions());
+ var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
+ fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(VideoDirectoryRegex)))
+ .Returns(true);
+ fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MetadataDirectoryRegex)))
+ .Returns(true);
+
+ var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
var directoryService = GetDirectoryServiceForExternalFile(file);
var streams = await subtitleResolver.GetExternalStreamsAsync(video, 0, directoryService, false, CancellationToken.None);
@@ -291,7 +344,7 @@ public class MediaInfoResolverTests
var files = new string[fileCount];
for (int i = 0; i < fileCount; i++)
{
- files[i] = $"{VideoDirectoryPath}/MyVideo.{i}.srt";
+ files[i] = $"{VideoDirectoryPath}/My.Video.{i}.srt";
}
var directoryService = new Mock<IDirectoryService>(MockBehavior.Strict);
@@ -318,7 +371,13 @@ public class MediaInfoResolverTests
MediaStreams = GenerateMediaStreams()
}));
- var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, new NamingOptions());
+ var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
+ fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(VideoDirectoryRegex)))
+ .Returns(true);
+ fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MetadataDirectoryRegex)))
+ .Returns(true);
+
+ var subtitleResolver = new SubtitleResolver(_localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
int startIndex = 1;
var streams = await subtitleResolver.GetExternalStreamsAsync(video, startIndex, directoryService.Object, false, CancellationToken.None);
diff --git a/tests/Jellyfin.Providers.Tests/MediaInfo/SubtitleResolverTests.cs b/tests/Jellyfin.Providers.Tests/MediaInfo/SubtitleResolverTests.cs
index 0f1086f59..0e6457ce3 100644
--- a/tests/Jellyfin.Providers.Tests/MediaInfo/SubtitleResolverTests.cs
+++ b/tests/Jellyfin.Providers.Tests/MediaInfo/SubtitleResolverTests.cs
@@ -11,6 +11,7 @@ using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
+using MediaBrowser.Model.IO;
using MediaBrowser.Providers.MediaInfo;
using Moq;
using Xunit;
@@ -45,7 +46,13 @@ public class SubtitleResolverTests
}
}));
- _subtitleResolver = new SubtitleResolver(localizationManager, mediaEncoder.Object, new NamingOptions());
+ var fileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
+ fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.VideoDirectoryRegex)))
+ .Returns(true);
+ fileSystem.Setup(fs => fs.DirectoryExists(It.IsRegex(MediaInfoResolverTests.MetadataDirectoryRegex)))
+ .Returns(true);
+
+ _subtitleResolver = new SubtitleResolver(localizationManager, mediaEncoder.Object, fileSystem.Object, new NamingOptions());
}
[Theory]
diff --git a/tests/Jellyfin.Providers.Tests/Test Data/Video/My.Video.mkv b/tests/Jellyfin.Providers.Tests/Test Data/Video/My.Video.mkv
deleted file mode 100644
index e69de29bb..000000000
--- a/tests/Jellyfin.Providers.Tests/Test Data/Video/My.Video.mkv
+++ /dev/null