Skip to content

Commit

Permalink
Merge branch 'master' into 10-9-support
Browse files Browse the repository at this point in the history
  • Loading branch information
MBR-0001 committed Jul 11, 2023
2 parents 9dbfea0 + 81f5bb9 commit 61706d7
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions Jellyfin.Plugin.OpenSubtitles/OpenSubtitleDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,33 @@ public async Task<IEnumerable<RemoteSubtitleInfo>> Search(SubtitleSearchRequest

var language = await GetLanguage(request.TwoLetterISOLanguageName, cancellationToken).ConfigureAwait(false);

string hash;
try
{
#pragma warning disable CA2007
await using var fileStream = File.OpenRead(request.MediaPath);
#pragma warning restore CA2007
string? hash = null;
if (!Path.GetExtension(request.MediaPath).Equals(".strm", StringComparison.OrdinalIgnoreCase))
{
try
{
#pragma warning disable CA2007
await using var fileStream = File.OpenRead(request.MediaPath);
#pragma warning restore CA2007

hash = OpenSubtitlesRequestHelper.ComputeHash(fileStream);
}
catch (IOException ex)
{
throw new IOException(string.Format(CultureInfo.InvariantCulture, "IOException while computing hash for {0}", request.MediaPath), ex);
}
hash = OpenSubtitlesRequestHelper.ComputeHash(fileStream);
}
catch (IOException ex)
{
throw new IOException(string.Format(CultureInfo.InvariantCulture, "IOException while computing hash for {0}", request.MediaPath), ex);
}
}

var options = new Dictionary<string, string>
{
{ "languages", language },
{ "moviehash", hash },
{ "type", request.ContentType == VideoContentType.Episode ? "episode" : "movie" }
};
var options = new Dictionary<string, string>
{
{ "languages", language },
{ "type", request.ContentType == VideoContentType.Episode ? "episode" : "movie" }
};

if (hash is not null)
{
options.Add("moviehash", hash);
}

// If we have the IMDb ID we use that, otherwise query with the details
if (imdbId != 0)
Expand All @@ -155,10 +162,10 @@ public async Task<IEnumerable<RemoteSubtitleInfo>> Search(SubtitleSearchRequest
}
}

if (request.IsPerfectMatch)
{
options.Add("moviehash_match", "only");
}
if (request.IsPerfectMatch && hash is not null)
{
options.Add("moviehash_match", "only");
}

_logger.LogDebug("Search query: {Query}", options);

Expand Down

0 comments on commit 61706d7

Please sign in to comment.