diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index e92d33574b..b2c499b9a9 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -318,7 +318,8 @@ namespace MediaBrowser.Model.Configuration public class SubtitleOptions { - public bool RequireTextSubtitles { get; set; } + public bool SkipIfGraphicalSubtitlesPresent { get; set; } + public bool SkipIfAudioTrackMatches { get; set; } public string[] DownloadLanguages { get; set; } public bool DownloadMovieSubtitles { get; set; } public bool DownloadEpisodeSubtitles { get; set; } @@ -329,6 +330,8 @@ namespace MediaBrowser.Model.Configuration public SubtitleOptions() { DownloadLanguages = new string[] { }; + + SkipIfAudioTrackMatches = true; } } } diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs index a78c27aa43..d2f8de8e4f 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs @@ -472,7 +472,8 @@ namespace MediaBrowser.Providers.MediaInfo .DownloadSubtitles(video, currentStreams, externalSubtitleStreams, - _config.Configuration.SubtitleOptions.RequireTextSubtitles, + _config.Configuration.SubtitleOptions.SkipIfGraphicalSubtitlesPresent, + _config.Configuration.SubtitleOptions.SkipIfAudioTrackMatches, _config.Configuration.SubtitleOptions.DownloadLanguages, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs b/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs index a20dc4d299..3e11fd85e3 100644 --- a/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs +++ b/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs @@ -26,7 +26,8 @@ namespace MediaBrowser.Providers.MediaInfo public async Task> DownloadSubtitles(Video video, List internalMediaStreams, List externalSubtitleStreams, - bool forceExternal, + bool skipIfGraphicalSubtitlesPresent, + bool skipIfAudioTrackMatches, IEnumerable languages, CancellationToken cancellationToken) { @@ -58,7 +59,7 @@ namespace MediaBrowser.Providers.MediaInfo { try { - var downloaded = await DownloadSubtitles(video, internalMediaStreams, externalSubtitleStreams, forceExternal, lang, mediaType, cancellationToken) + var downloaded = await DownloadSubtitles(video, internalMediaStreams, externalSubtitleStreams, skipIfGraphicalSubtitlesPresent, skipIfAudioTrackMatches, lang, mediaType, cancellationToken) .ConfigureAwait(false); if (downloaded) @@ -78,7 +79,8 @@ namespace MediaBrowser.Providers.MediaInfo private async Task DownloadSubtitles(Video video, List internalMediaStreams, IEnumerable externalSubtitleStreams, - bool forceExternal, + bool skipIfGraphicalSubtitlesPresent, + bool skipIfAudioTrackMatches, string language, SubtitleMediaType mediaType, CancellationToken cancellationToken) @@ -90,13 +92,14 @@ namespace MediaBrowser.Providers.MediaInfo } // There's already an audio stream for this language - if (internalMediaStreams.Any(i => i.Type == MediaStreamType.Audio && string.Equals(i.Language, language, StringComparison.OrdinalIgnoreCase))) + if (skipIfAudioTrackMatches && + internalMediaStreams.Any(i => i.Type == MediaStreamType.Audio && string.Equals(i.Language, language, StringComparison.OrdinalIgnoreCase))) { return false; } // There's an internal subtitle stream for this language - if (!forceExternal && + if (skipIfGraphicalSubtitlesPresent && internalMediaStreams.Any(i => i.Type == MediaStreamType.Subtitle && string.Equals(i.Language, language, StringComparison.OrdinalIgnoreCase))) { return false; diff --git a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs index ac0439737b..cfb322bc6f 100644 --- a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs +++ b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Events; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Security; @@ -115,8 +116,14 @@ namespace MediaBrowser.Providers.Subtitles throw new ApplicationException("Invalid response type"); } - var res = ((MethodResponseSubtitleDownload)resultDownLoad).Results.First(); - var data = Convert.FromBase64String(res.Data); + var results = ((MethodResponseSubtitleDownload)resultDownLoad).Results; + + if (results.Count == 0) + { + throw new ResourceNotFoundException("Subtitle with Id " + ossId + " was not found."); + } + + var data = Convert.FromBase64String(results.First().Data); return new SubtitleResponse { diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index fcdb0bf83e..8963bc0afe 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -707,13 +707,14 @@ "OptionReportByteRangeSeekingWhenTranscodingHelp": "This is required for some devices that don't time seek very well.", "HeaderSubtitleDownloadingHelp": "When Media Browser scans your video files it can search for missing subtitles, and download them using a subtitle provider such as OpenSubtitles.org.", "HeaderDownloadSubtitlesFor": "Download subtitles for:", - "LabelRequireTextSubtitles": "Download even if the video already contains graphical subtitles", - "LabelRequireTextSubtitlesHelp": "Keeping text versions of subtitles will result in more efficient delivery to mobile clients.", + "LabelSkipIfGraphicalSubsPresent": "Skip if the video already contains graphical subtitles", + "LabelSkipIfGraphicalSubsPresentHelp": "Keeping text versions of subtitles will result in more efficient delivery to mobile clients.", "TabSubtitles": "Subtitles", "LabelOpenSubtitlesUsername": "Open Subtitles username:", "LabelOpenSubtitlesPassword": "Open Subtitles password:", "LabelAudioLanguagePreferenceHelp": "If empty, the default audio track will be selected, regardless of language.", "LabelDownloadLanguages": "Download languages:", "ButtonRegister": "Register", - "HeaderSubtitleDownloadingMoreHelp": "Subtitles are considered missing when the audio track is in a foreign language, and there are no subtitles available in the preferred language." + "LabelSkipIfAudioTrackPresent": "Skip if the video has an audio track with the download language", + "LabelSkipIfAudioTrackPresentHelp": "Uncheck this to ensure all videos have subtitles, regardless of audio language." } \ No newline at end of file