add open subtitle option to only download subtitles that are a perfect match

This commit is contained in:
Luke Pulverenti 2016-04-07 00:09:32 -04:00
parent c27e60d2d8
commit 8e0c9c53bc
6 changed files with 14 additions and 4 deletions

View File

@ -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<string, string> ProviderIds { get; set; }
public bool SearchAllProviders { get; set; }

View File

@ -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;
}
}
}

View File

@ -532,6 +532,7 @@ namespace MediaBrowser.Providers.MediaInfo
currentStreams.Concat(externalSubtitleStreams).ToList(),
subtitleOptions.SkipIfEmbeddedSubtitlesPresent,
subtitleOptions.SkipIfAudioTrackMatches,
subtitleOptions.RequirePerfectMatch,
subtitleOptions.DownloadLanguages,
cancellationToken).ConfigureAwait(false);

View File

@ -28,6 +28,7 @@ namespace MediaBrowser.Providers.MediaInfo
List<MediaStream> mediaStreams,
bool skipIfEmbeddedSubtitlesPresent,
bool skipIfAudioTrackMatches,
bool requirePerfectMatch,
IEnumerable<string> 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<MediaStream> 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;

View File

@ -116,6 +116,7 @@ namespace MediaBrowser.Providers.MediaInfo
mediaStreams,
options.SkipIfEmbeddedSubtitlesPresent,
options.SkipIfAudioTrackMatches,
options.RequirePerfectMatch,
options.DownloadLanguages,
cancellationToken).ConfigureAwait(false);

View File

@ -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))