Skip to content

Commit

Permalink
Add handling for .strm files (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
MBR-0001 authored May 30, 2023
1 parent 2fe219f commit 81f5bb9
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions Jellyfin.Plugin.OpenSubtitles/OpenSubtitleDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,27 +116,34 @@ public async Task<IEnumerable<RemoteSubtitleInfo>> Search(SubtitleSearchRequest

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

string hash;
try
string? hash = null;
if (!Path.GetExtension(request.MediaPath).Equals(".strm", StringComparison.OrdinalIgnoreCase))
{
#pragma warning disable CA2007
await using var fileStream = File.OpenRead(request.MediaPath);
#pragma warning restore CA2007
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" }
};

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 @@ -160,7 +167,7 @@ public async Task<IEnumerable<RemoteSubtitleInfo>> Search(SubtitleSearchRequest
}
}

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

0 comments on commit 81f5bb9

Please sign in to comment.