From 8e0c9c53bc0a599aa90dc37ff040769653db5e7d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 7 Apr 2016 00:09:32 -0400 Subject: [PATCH] add open subtitle option to only download subtitles that are a perfect match --- .../Subtitles/SubtitleSearchRequest.cs | 1 + MediaBrowser.Model/Providers/SubtitleOptions.cs | 3 +++ MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs | 1 + MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs | 8 ++++++-- MediaBrowser.Providers/MediaInfo/SubtitleScheduledTask.cs | 1 + .../Subtitles/OpenSubtitleDownloader.cs | 4 ++-- 6 files changed, 14 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Controller/Subtitles/SubtitleSearchRequest.cs b/MediaBrowser.Controller/Subtitles/SubtitleSearchRequest.cs index e781c048b..a2371426a 100644 --- a/MediaBrowser.Controller/Subtitles/SubtitleSearchRequest.cs +++ b/MediaBrowser.Controller/Subtitles/SubtitleSearchRequest.cs @@ -19,6 +19,7 @@ namespace MediaBrowser.Controller.Subtitles public int? ParentIndexNumber { get; set; } public int? ProductionYear { get; set; } public long? RuntimeTicks { get; set; } + public bool IsPerfectMatch { get; set; } public Dictionary ProviderIds { get; set; } public bool SearchAllProviders { get; set; } diff --git a/MediaBrowser.Model/Providers/SubtitleOptions.cs b/MediaBrowser.Model/Providers/SubtitleOptions.cs index 2b15c0e1f..5587e897f 100644 --- a/MediaBrowser.Model/Providers/SubtitleOptions.cs +++ b/MediaBrowser.Model/Providers/SubtitleOptions.cs @@ -12,11 +12,14 @@ namespace MediaBrowser.Model.Providers public string OpenSubtitlesPasswordHash { get; set; } public bool IsOpenSubtitleVipAccount { get; set; } + public bool RequirePerfectMatch { get; set; } + public SubtitleOptions() { DownloadLanguages = new string[] { }; SkipIfAudioTrackMatches = true; + RequirePerfectMatch = true; } } } \ No newline at end of file diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs index 24bf8b497..621510028 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs @@ -532,6 +532,7 @@ namespace MediaBrowser.Providers.MediaInfo currentStreams.Concat(externalSubtitleStreams).ToList(), subtitleOptions.SkipIfEmbeddedSubtitlesPresent, subtitleOptions.SkipIfAudioTrackMatches, + subtitleOptions.RequirePerfectMatch, subtitleOptions.DownloadLanguages, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs b/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs index d82289032..9ae8413d1 100644 --- a/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs +++ b/MediaBrowser.Providers/MediaInfo/SubtitleDownloader.cs @@ -28,6 +28,7 @@ namespace MediaBrowser.Providers.MediaInfo List mediaStreams, bool skipIfEmbeddedSubtitlesPresent, bool skipIfAudioTrackMatches, + bool requirePerfectMatch, IEnumerable languages, CancellationToken cancellationToken) { @@ -59,7 +60,7 @@ namespace MediaBrowser.Providers.MediaInfo { try { - var downloaded = await DownloadSubtitles(video, mediaStreams, skipIfEmbeddedSubtitlesPresent, skipIfAudioTrackMatches, lang, mediaType, cancellationToken) + var downloaded = await DownloadSubtitles(video, mediaStreams, skipIfEmbeddedSubtitlesPresent, skipIfAudioTrackMatches, requirePerfectMatch, lang, mediaType, cancellationToken) .ConfigureAwait(false); if (downloaded) @@ -80,6 +81,7 @@ namespace MediaBrowser.Providers.MediaInfo List mediaStreams, bool skipIfEmbeddedSubtitlesPresent, bool skipIfAudioTrackMatches, + bool requirePerfectMatch, string language, VideoContentType mediaType, CancellationToken cancellationToken) @@ -125,7 +127,9 @@ namespace MediaBrowser.Providers.MediaInfo ProviderIds = video.ProviderIds, // Stop as soon as we find something - SearchAllProviders = false + SearchAllProviders = false, + + IsPerfectMatch = requirePerfectMatch }; var episode = video as Episode; diff --git a/MediaBrowser.Providers/MediaInfo/SubtitleScheduledTask.cs b/MediaBrowser.Providers/MediaInfo/SubtitleScheduledTask.cs index b8b17cefe..79da291b7 100644 --- a/MediaBrowser.Providers/MediaInfo/SubtitleScheduledTask.cs +++ b/MediaBrowser.Providers/MediaInfo/SubtitleScheduledTask.cs @@ -116,6 +116,7 @@ namespace MediaBrowser.Providers.MediaInfo mediaStreams, options.SkipIfEmbeddedSubtitlesPresent, options.SkipIfAudioTrackMatches, + options.RequirePerfectMatch, options.DownloadLanguages, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs index 2276e391d..271f8170f 100644 --- a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs +++ b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs @@ -308,8 +308,8 @@ namespace MediaBrowser.Providers.Subtitles // Avoid implicitly captured closure var hasCopy = hash; - return results.Where(x => x.SubBad == "0" && mediaFilter(x)) - .OrderBy(x => (x.MovieHash == hash ? 0 : 1)) + return results.Where(x => x.SubBad == "0" && mediaFilter(x) && (!request.IsPerfectMatch || string.Equals(x.MovieHash, hash, StringComparison.OrdinalIgnoreCase))) + .OrderBy(x => (string.Equals(x.MovieHash, hash, StringComparison.OrdinalIgnoreCase) ? 0 : 1)) .ThenBy(x => Math.Abs(long.Parse(x.MovieByteSize, _usCulture) - movieByteSize)) .ThenByDescending(x => int.Parse(x.SubDownloadsCnt, _usCulture)) .ThenByDescending(x => double.Parse(x.SubRating, _usCulture))