mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-07 03:48:06 +02:00
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Conflicts: MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs
This commit is contained in:
commit
b25bc74a7d
2 changed files with 27 additions and 67 deletions
|
@ -166,14 +166,7 @@ namespace MediaBrowser.Providers.Subtitles
|
||||||
public async Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitles(SubtitleSearchRequest request, CancellationToken cancellationToken)
|
public async Task<IEnumerable<RemoteSubtitleInfo>> SearchSubtitles(SubtitleSearchRequest request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var imdbIdText = request.GetProviderId(MetadataProviders.Imdb);
|
var imdbIdText = request.GetProviderId(MetadataProviders.Imdb);
|
||||||
long imdbId;
|
long imdbId = 0;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(imdbIdText) ||
|
|
||||||
!long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId))
|
|
||||||
{
|
|
||||||
_logger.Debug("Imdb id missing");
|
|
||||||
return new List<RemoteSubtitleInfo>();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (request.ContentType)
|
switch (request.ContentType)
|
||||||
{
|
{
|
||||||
|
@ -190,6 +183,11 @@ namespace MediaBrowser.Providers.Subtitles
|
||||||
_logger.Debug("Movie name missing");
|
_logger.Debug("Movie name missing");
|
||||||
return new List<RemoteSubtitleInfo>();
|
return new List<RemoteSubtitleInfo>();
|
||||||
}
|
}
|
||||||
|
if (string.IsNullOrWhiteSpace(imdbIdText) || !long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId))
|
||||||
|
{
|
||||||
|
_logger.Debug("Imdb id missing");
|
||||||
|
return new List<RemoteSubtitleInfo>();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,18 +206,26 @@ namespace MediaBrowser.Providers.Subtitles
|
||||||
var hash = Utilities.ComputeHash(request.MediaPath);
|
var hash = Utilities.ComputeHash(request.MediaPath);
|
||||||
var fileInfo = new FileInfo(request.MediaPath);
|
var fileInfo = new FileInfo(request.MediaPath);
|
||||||
var movieByteSize = fileInfo.Length;
|
var movieByteSize = fileInfo.Length;
|
||||||
|
var searchImdbId = request.ContentType == SubtitleMediaType.Movie ? imdbId.ToString(_usCulture) : "";
|
||||||
var subtitleSearchParameters = request.ContentType == SubtitleMediaType.Episode
|
var subtitleSearchParameters = request.ContentType == SubtitleMediaType.Episode
|
||||||
? new SubtitleSearchParameters(subLanguageId, request.SeriesName, request.ParentIndexNumber.Value.ToString(_usCulture), request.IndexNumber.Value.ToString(_usCulture))
|
? new List<SubtitleSearchParameters> {
|
||||||
: new SubtitleSearchParameters(subLanguageId, request.Name);
|
new SubtitleSearchParameters(subLanguageId,
|
||||||
|
query: request.SeriesName,
|
||||||
var parms = new List<SubtitleSearchParameters> {
|
season: request.ParentIndexNumber.Value.ToString(_usCulture),
|
||||||
new SubtitleSearchParameters(subLanguageId, hash, movieByteSize),
|
episode: request.IndexNumber.Value.ToString(_usCulture))
|
||||||
subtitleSearchParameters
|
}
|
||||||
|
: new List<SubtitleSearchParameters> {
|
||||||
|
new SubtitleSearchParameters(subLanguageId, imdbid: searchImdbId),
|
||||||
|
new SubtitleSearchParameters(subLanguageId, query: request.Name, imdbid: searchImdbId)
|
||||||
};
|
};
|
||||||
|
var parms = new List<SubtitleSearchParameters> {
|
||||||
var result = await OpenSubtitles.SearchSubtitlesAsync(parms.ToArray(), cancellationToken).ConfigureAwait(false);
|
new SubtitleSearchParameters( subLanguageId,
|
||||||
|
movieHash: hash,
|
||||||
|
movieByteSize: movieByteSize,
|
||||||
|
imdbid: searchImdbId ),
|
||||||
|
};
|
||||||
|
parms.AddRange(subtitleSearchParameters);
|
||||||
|
var result = OpenSubtitles.SearchSubtitles(parms.ToArray());
|
||||||
if (!(result is MethodResponseSubtitleSearch))
|
if (!(result is MethodResponseSubtitleSearch))
|
||||||
{
|
{
|
||||||
_logger.Debug("Invalid response type");
|
_logger.Debug("Invalid response type");
|
||||||
|
|
|
@ -25,61 +25,15 @@ namespace OpenSubtitlesHandler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct SubtitleSearchParameters
|
public struct SubtitleSearchParameters
|
||||||
{
|
{
|
||||||
/// <summary>
|
public SubtitleSearchParameters(string subLanguageId, string query = "", string season = "", string episode = "", string movieHash = "", long movieByteSize = 0, string imdbid = "")
|
||||||
/// Paramaters for subtitle search call
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="subLanguageId">List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo')</param>
|
|
||||||
/// <param name="movieHash">Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes</param>
|
|
||||||
/// <param name="movieByteSize">Size of video file in bytes </param>
|
|
||||||
public SubtitleSearchParameters(string subLanguageId, string movieHash, long movieByteSize)
|
|
||||||
{
|
|
||||||
this.subLanguageId = subLanguageId;
|
|
||||||
this.movieHash = movieHash;
|
|
||||||
this.movieByteSize = movieByteSize;
|
|
||||||
this.imdbid = "";
|
|
||||||
this._episode = "";
|
|
||||||
this._season = "";
|
|
||||||
this._query = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public SubtitleSearchParameters(string subLanguageId, string query)
|
|
||||||
{
|
|
||||||
this.subLanguageId = subLanguageId;
|
|
||||||
this.movieHash = "";
|
|
||||||
this.movieByteSize = 0;
|
|
||||||
this.imdbid = "";
|
|
||||||
this._episode = "";
|
|
||||||
this._season = "";
|
|
||||||
this._query = query;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SubtitleSearchParameters(string subLanguageId, string query, string season, string episode)
|
|
||||||
{
|
|
||||||
this.subLanguageId = subLanguageId;
|
|
||||||
this.movieHash = "";
|
|
||||||
this.movieByteSize = 0;
|
|
||||||
this.imdbid = "";
|
|
||||||
this._episode = episode;
|
|
||||||
this._season = season;
|
|
||||||
this._query = query;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Paramaters for subtitle search call
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="subLanguageId">List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo')</param>
|
|
||||||
/// <param name="movieHash">Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes</param>
|
|
||||||
/// <param name="movieByteSize">Size of video file in bytes </param>
|
|
||||||
/// <param name="imdbid"> IMDb ID of movie this video is part of, belongs to.</param>
|
|
||||||
public SubtitleSearchParameters(string subLanguageId, string movieHash, long movieByteSize, string imdbid)
|
|
||||||
{
|
{
|
||||||
this.subLanguageId = subLanguageId;
|
this.subLanguageId = subLanguageId;
|
||||||
this.movieHash = movieHash;
|
this.movieHash = movieHash;
|
||||||
this.movieByteSize = movieByteSize;
|
this.movieByteSize = movieByteSize;
|
||||||
this.imdbid = imdbid;
|
this.imdbid = imdbid;
|
||||||
this._episode = "";
|
this._episode = episode;
|
||||||
this._season = "";
|
this._season = season;
|
||||||
this._query = "";
|
this._query = query;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string subLanguageId;
|
private string subLanguageId;
|
||||||
|
|
Loading…
Reference in a new issue