From ac69327f1fa866c20630d9d0e0c663472b726c79 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 5 May 2014 00:36:45 -0400 Subject: check in open subtitles stub --- .../SubtitleTypes/CheckSubHashResult.cs | 31 +++++ .../SubtitleTypes/SubtitleDownloadResult.cs | 44 +++++++ .../SubtitleTypes/SubtitleLanguage.cs | 39 ++++++ .../SubtitleTypes/SubtitleSearchParameters.cs | 115 +++++++++++++++++ .../SubtitleTypes/SubtitleSearchResult.cs | 137 +++++++++++++++++++++ .../SubtitleTypes/TryUploadSubtitlesParameters.cs | 48 ++++++++ .../SubtitleTypes/UploadSubtitleInfoParameter.cs | 46 +++++++ .../SubtitleTypes/UploadSubtitleParameters.cs | 53 ++++++++ 8 files changed, 513 insertions(+) create mode 100644 OpenSubtitlesHandler/SubtitleTypes/CheckSubHashResult.cs create mode 100644 OpenSubtitlesHandler/SubtitleTypes/SubtitleDownloadResult.cs create mode 100644 OpenSubtitlesHandler/SubtitleTypes/SubtitleLanguage.cs create mode 100644 OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs create mode 100644 OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchResult.cs create mode 100644 OpenSubtitlesHandler/SubtitleTypes/TryUploadSubtitlesParameters.cs create mode 100644 OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleInfoParameter.cs create mode 100644 OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleParameters.cs (limited to 'OpenSubtitlesHandler/SubtitleTypes') diff --git a/OpenSubtitlesHandler/SubtitleTypes/CheckSubHashResult.cs b/OpenSubtitlesHandler/SubtitleTypes/CheckSubHashResult.cs new file mode 100644 index 000000000..0e77601ba --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/CheckSubHashResult.cs @@ -0,0 +1,31 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + public struct CheckSubHashResult + { + private string _hash; + private string _id; + + public string Hash { get { return _hash; } set { _hash = value; } } + public string SubID { get { return _id; } set { _id = value; } } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleDownloadResult.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleDownloadResult.cs new file mode 100644 index 000000000..35bf796e6 --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/SubtitleDownloadResult.cs @@ -0,0 +1,44 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + public struct SubtitleDownloadResult + { + private string idsubtitlefile; + private string data; + + public string IdSubtitleFile + { get { return idsubtitlefile; } set { idsubtitlefile = value; } } + /// + /// Get or set the data of subtitle file. To decode, decode the string to base64 and then decompress with GZIP. + /// + public string Data + { get { return data; } set { data = value; } } + /// + /// IdSubtitleFile + /// + /// + public override string ToString() + { + return idsubtitlefile.ToString(); + } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleLanguage.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleLanguage.cs new file mode 100644 index 000000000..511c98670 --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/SubtitleLanguage.cs @@ -0,0 +1,39 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +namespace OpenSubtitlesHandler +{ + public struct SubtitleLanguage + { + private string _SubLanguageID; + private string _LanguageName; + private string _ISO639; + + public string SubLanguageID { get { return _SubLanguageID; } set { _SubLanguageID = value; } } + public string LanguageName { get { return _LanguageName; } set { _LanguageName = value; } } + public string ISO639 { get { return _ISO639; } set { _ISO639 = value; } } + /// + /// LanguageName [SubLanguageID] + /// + /// LanguageName [SubLanguageID] + public override string ToString() + { + return _LanguageName + " [" + _SubLanguageID + "]"; + } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs new file mode 100644 index 000000000..e11ff1b9a --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs @@ -0,0 +1,115 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + /// + /// Paramaters for subtitle search call + /// + public struct SubtitleSearchParameters + { + /// + /// Paramaters for subtitle search call + /// + /// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo') + /// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes + /// Size of video file in bytes + 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, string season, string episode) + { + this.subLanguageId = subLanguageId; + this.movieHash = ""; + this.movieByteSize = 0; + this.imdbid = ""; + this._episode = episode; + this._season = season; + this._query = query; + } + + /// + /// Paramaters for subtitle search call + /// + /// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo') + /// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes + /// Size of video file in bytes + /// IMDb ID of movie this video is part of, belongs to. + public SubtitleSearchParameters(string subLanguageId, string movieHash, long movieByteSize, string imdbid) + { + this.subLanguageId = subLanguageId; + this.movieHash = movieHash; + this.movieByteSize = movieByteSize; + this.imdbid = imdbid; + this._episode = ""; + this._season = ""; + this._query = ""; + } + + private string subLanguageId; + private string movieHash; + private long movieByteSize; + private string imdbid; + private string _query; + private string _episode; + + public string Episode { + get { return _episode; } + set { _episode = value; } + } + + public string Season { + get { return _season; } + set { _season = value; } + } + + private string _season; + + public string Query { + get { return _query; } + set { _query = value; } + } + + /// + /// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo') + /// + public string SubLangaugeID { get { return subLanguageId; } set { subLanguageId = value; } } + /// + /// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes + /// + public string MovieHash { get { return movieHash; } set { movieHash = value; } } + /// + /// Size of video file in bytes + /// + public long MovieByteSize { get { return movieByteSize; } set { movieByteSize = value; } } + /// + /// ​IMDb ID of movie this video is part of, belongs to. + /// + public string IMDbID { get { return imdbid; } set { imdbid = value; } } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchResult.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchResult.cs new file mode 100644 index 000000000..a56a6edab --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchResult.cs @@ -0,0 +1,137 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + /// + /// The subtitle search result that comes with server response on SearchSubtitles successed call + /// + public struct SubtitleSearchResult + { + private string _IDSubMovieFile; + private string _MovieHash; + private string _MovieByteSize; + private string _MovieTimeMS; + private string _IDSubtitleFile; + private string _SubFileName; + private string _SubActualCD; + private string _SubSize; + private string _SubHash; + private string _IDSubtitle; + private string _UserID; + private string _SubLanguageID; + private string _SubFormat; + private string _SeriesSeason; + private string _SeriesEpisode; + private string _SubSumCD; + private string _SubAuthorComment; + private string _SubAddDate; + private string _SubBad; + private string _SubRating; + private string _SubDownloadsCnt; + private string _MovieReleaseName; + private string _IDMovie; + private string _IDMovieImdb; + private string _MovieName; + private string _MovieNameEng; + private string _MovieYear; + private string _MovieImdbRating; + private string _UserNickName; + private string _ISO639; + private string _LanguageName; + private string _SubDownloadLink; + private string _ZipDownloadLink; + + public string IDSubMovieFile + { get { return _IDSubMovieFile; } set { _IDSubMovieFile = value; } } + public string MovieHash + { get { return _MovieHash; } set { _MovieHash = value; } } + public string MovieByteSize + { get { return _MovieByteSize; } set { _MovieByteSize = value; } } + public string MovieTimeMS + { get { return _MovieTimeMS; } set { _MovieTimeMS = value; } } + public string IDSubtitleFile + { get { return _IDSubtitleFile; } set { _IDSubtitleFile = value; } } + public string SubFileName + { get { return _SubFileName; } set { _SubFileName = value; } } + public string SubActualCD + { get { return _SubActualCD; } set { _SubActualCD = value; } } + public string SubSize + { get { return _SubSize; } set { _SubSize = value; } } + public string SubHash + { get { return _SubHash; } set { _SubHash = value; } } + public string IDSubtitle + { get { return _IDSubtitle; } set { _IDSubtitle = value; } } + public string UserID + { get { return _UserID; } set { _UserID = value; } } + public string SubLanguageID + { get { return _SubLanguageID; } set { _SubLanguageID = value; } } + public string SubFormat + { get { return _SubFormat; } set { _SubFormat = value; } } + public string SubSumCD + { get { return _SubSumCD; } set { _SubSumCD = value; } } + public string SubAuthorComment + { get { return _SubAuthorComment; } set { _SubAuthorComment = value; } } + public string SubAddDate + { get { return _SubAddDate; } set { _SubAddDate = value; } } + public string SubBad + { get { return _SubBad; } set { _SubBad = value; } } + public string SubRating + { get { return _SubRating; } set { _SubRating = value; } } + public string SubDownloadsCnt + { get { return _SubDownloadsCnt; } set { _SubDownloadsCnt = value; } } + public string MovieReleaseName + { get { return _MovieReleaseName; } set { _MovieReleaseName = value; } } + public string IDMovie + { get { return _IDMovie; } set { _IDMovie = value; } } + public string IDMovieImdb + { get { return _IDMovieImdb; } set { _IDMovieImdb = value; } } + public string MovieName + { get { return _MovieName; } set { _MovieName = value; } } + public string MovieNameEng + { get { return _MovieNameEng; } set { _MovieNameEng = value; } } + public string MovieYear + { get { return _MovieYear; } set { _MovieYear = value; } } + public string MovieImdbRating + { get { return _MovieImdbRating; } set { _MovieImdbRating = value; } } + public string UserNickName + { get { return _UserNickName; } set { _UserNickName = value; } } + public string ISO639 + { get { return _ISO639; } set { _ISO639 = value; } } + public string LanguageName + { get { return _LanguageName; } set { _LanguageName = value; } } + public string SubDownloadLink + { get { return _SubDownloadLink; } set { _SubDownloadLink = value; } } + public string ZipDownloadLink + { get { return _ZipDownloadLink; } set { _ZipDownloadLink = value; } } + public string SeriesSeason + { get { return _SeriesSeason; } set { _SeriesSeason = value; } } + public string SeriesEpisode + { get { return _SeriesEpisode; } set { _SeriesEpisode = value; } } + /// + /// SubFileName + " (" + SubFormat + ")" + /// + /// + public override string ToString() + { + return _SubFileName + " (" + _SubFormat + ")"; + } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/TryUploadSubtitlesParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/TryUploadSubtitlesParameters.cs new file mode 100644 index 000000000..a95d151eb --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/TryUploadSubtitlesParameters.cs @@ -0,0 +1,48 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + public class TryUploadSubtitlesParameters + { + private string _subhash = ""; + private string _subfilename = ""; + private string _moviehash = ""; + private string _moviebytesize = ""; + private int _movietimems = 0; + private int _movieframes = 0; + private double _moviefps = 0; + private string _moviefilename = ""; + + public string subhash { get { return _subhash; } set { _subhash = value; } } + public string subfilename { get { return _subfilename; } set { _subfilename = value; } } + public string moviehash { get { return _moviehash; } set { _moviehash = value; } } + public string moviebytesize { get { return _moviebytesize; } set { _moviebytesize = value; } } + public int movietimems { get { return _movietimems; } set { _movietimems = value; } } + public int movieframes { get { return _movieframes; } set { _movieframes = value; } } + public double moviefps { get { return _moviefps; } set { _moviefps = value; } } + public string moviefilename { get { return _moviefilename; } set { _moviefilename = value; } } + + public override string ToString() + { + return _subfilename + " (" + _subhash + ")"; + } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleInfoParameter.cs b/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleInfoParameter.cs new file mode 100644 index 000000000..8e147878b --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleInfoParameter.cs @@ -0,0 +1,46 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace OpenSubtitlesHandler +{ + public class UploadSubtitleInfoParameters + { + private string _idmovieimdb; + private string _moviereleasename; + private string _movieaka; + private string _sublanguageid; + private string _subauthorcomment; + private bool _hearingimpaired; + private bool _highdefinition; + private bool _automatictranslation; + private List cds; + + public string idmovieimdb { get { return _idmovieimdb; } set { _idmovieimdb = value; } } + public string moviereleasename { get { return _moviereleasename; } set { _moviereleasename = value; } } + public string movieaka { get { return _movieaka; } set { _movieaka = value; } } + public string sublanguageid { get { return _sublanguageid; } set { _sublanguageid = value; } } + public string subauthorcomment { get { return _subauthorcomment; } set { _subauthorcomment = value; } } + public bool hearingimpaired { get { return _hearingimpaired; } set { _hearingimpaired = value; } } + public bool highdefinition { get { return _highdefinition; } set { _highdefinition = value; } } + public bool automatictranslation { get { return _automatictranslation; } set { _automatictranslation = value; } } + public List CDS { get { return cds; } set { cds = value; } } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleParameters.cs new file mode 100644 index 000000000..90a273959 --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleParameters.cs @@ -0,0 +1,53 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + public struct UploadSubtitleParameters + { + private string _subhash; + private string _subfilename; + private string _moviehash; + private double _moviebytesize; + private int _movietimems; + private int _movieframes; + private double _moviefps; + private string _moviefilename; + private string _subcontent; + + public string subhash { get { return _subhash; } set { _subhash = value; } } + public string subfilename { get { return _subfilename; } set { _subfilename = value; } } + public string moviehash { get { return _moviehash; } set { _moviehash = value; } } + public double moviebytesize { get { return _moviebytesize; } set { _moviebytesize = value; } } + public int movietimems { get { return _movietimems; } set { _movietimems = value; } } + public int movieframes { get { return _movieframes; } set { _movieframes = value; } } + public double moviefps { get { return _moviefps; } set { _moviefps = value; } } + public string moviefilename { get { return _moviefilename; } set { _moviefilename = value; } } + /// + /// Sub content. Note: this value must be the subtitle file gziped and then base64 decoded. + /// + public string subcontent { get { return _subcontent; } set { _subcontent = value; } } + + public override string ToString() + { + return _subfilename + " (" + _subhash + ")"; + } + } +} -- cgit v1.2.3 From 9ef0793b28cfc69ef73838523860a92b8c50b724 Mon Sep 17 00:00:00 2001 From: Luis Miguel Almánzar Date: Mon, 5 May 2014 03:36:26 -0400 Subject: finish implementation of opensubtitles downloader --- .../Providers/ISubtitleProvider.cs | 2 + .../Subtitles/OpenSubtitleDownloader.cs | 47 ++++++++++++++-------- .../SubtitleTypes/SubtitleSearchParameters.cs | 11 +++++ 3 files changed, 44 insertions(+), 16 deletions(-) (limited to 'OpenSubtitlesHandler/SubtitleTypes') diff --git a/MediaBrowser.Controller/Providers/ISubtitleProvider.cs b/MediaBrowser.Controller/Providers/ISubtitleProvider.cs index a3aaaf298..adefea84d 100644 --- a/MediaBrowser.Controller/Providers/ISubtitleProvider.cs +++ b/MediaBrowser.Controller/Providers/ISubtitleProvider.cs @@ -49,7 +49,9 @@ namespace MediaBrowser.Controller.Providers public string MediaPath { get; set; } public string SeriesName { get; set; } + public string Name { get; set; } public int? IndexNumber { get; set; } public int? ParentIndexNumber { get; set; } + public long ImdbId { get; set; } } } diff --git a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs index 12d8b8fc6..6025493e7 100644 --- a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs +++ b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs @@ -37,25 +37,31 @@ namespace MediaBrowser.Providers.Subtitles public Task GetSubtitles(SubtitleRequest request, CancellationToken cancellationToken) { - return request.ContentType == SubtitleMediaType.Episode - ? GetEpisodeSubtitles(request, cancellationToken) - : GetMovieSubtitles(request, cancellationToken); + return GetMediaSubtitleSubtitles(request, cancellationToken); } - public async Task GetMovieSubtitles(SubtitleRequest request, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - - public async Task GetEpisodeSubtitles(SubtitleRequest request, CancellationToken cancellationToken) + public async Task GetMediaSubtitleSubtitles(SubtitleRequest request, CancellationToken cancellationToken) { var response = new SubtitleResponse(); - if (!request.IndexNumber.HasValue || !request.ParentIndexNumber.HasValue) + switch (request.ContentType) { - _logger.Debug("Information Missing"); - return response; + case SubtitleMediaType.Episode: + if (!request.IndexNumber.HasValue || !request.ParentIndexNumber.HasValue || string.IsNullOrEmpty(request.SeriesName)) + { + _logger.Debug("Information Missing"); + return response; + } + break; + case SubtitleMediaType.Movie: + if (string.IsNullOrEmpty(request.Name)) + { + _logger.Debug("Information Missing"); + return response; + } + break; } + if (string.IsNullOrEmpty(request.MediaPath)) { _logger.Debug("Path Missing"); @@ -76,10 +82,13 @@ namespace MediaBrowser.Providers.Subtitles var fileInfo = new FileInfo(request.MediaPath); var movieByteSize = fileInfo.Length; + var subtitleSearchParameters = request.ContentType == SubtitleMediaType.Episode + ? new SubtitleSearchParameters(subLanguageId, request.SeriesName, request.ParentIndexNumber.Value.ToString(_usCulture), request.IndexNumber.Value.ToString(_usCulture)) + : new SubtitleSearchParameters(subLanguageId, request.Name); + var parms = new List { new SubtitleSearchParameters(subLanguageId, hash, movieByteSize), - new SubtitleSearchParameters(subLanguageId, request.SeriesName, request.ParentIndexNumber.Value.ToString(_usCulture), request.IndexNumber.Value.ToString(_usCulture)), - + subtitleSearchParameters }; var result = OpenSubtitles.SearchSubtitles(parms.ToArray()); @@ -89,8 +98,14 @@ namespace MediaBrowser.Providers.Subtitles return null; } + Predicate mediaFilter = + x => + request.ContentType == SubtitleMediaType.Episode + ? int.Parse(x.SeriesSeason) == request.ParentIndexNumber && int.Parse(x.SeriesEpisode) == request.IndexNumber + : long.Parse(x.IDMovieImdb) == request.ImdbId; + var results = ((MethodResponseSubtitleSearch)result).Results; - var bestResult = results.Where(x => x.SubBad == "0" && int.Parse(x.SeriesSeason) == request.ParentIndexNumber && int.Parse(x.SeriesEpisode) == request.IndexNumber) + var bestResult = results.Where(x => x.SubBad == "0" && mediaFilter(x)) .OrderBy(x => x.MovieHash == hash) .ThenBy(x => Math.Abs(long.Parse(x.MovieByteSize) - movieByteSize)) .ThenByDescending(x => int.Parse(x.SubDownloadsCnt)) @@ -124,7 +139,7 @@ namespace MediaBrowser.Providers.Subtitles var data = Convert.FromBase64String(res.Data); response.HasContent = true; - response.Format = SubtitleFormat.SRT; + response.Format = subtitle.SubFormat.ToUpper(); response.Stream = new MemoryStream(Utilities.Decompress(new MemoryStream(data))); return response; } diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs index e11ff1b9a..f2e70ef81 100644 --- a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs +++ b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs @@ -42,6 +42,17 @@ namespace OpenSubtitlesHandler 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; -- cgit v1.2.3 From ad7af6355db70793b7302be8202962b4ab300076 Mon Sep 17 00:00:00 2001 From: Luis Miguel Almánzar Date: Thu, 8 May 2014 23:24:58 -0400 Subject: fix episodes subtitles --- .../Subtitles/OpenSubtitleDownloader.cs | 37 +++++++++------- .../SubtitleTypes/SubtitleSearchParameters.cs | 50 +--------------------- 2 files changed, 24 insertions(+), 63 deletions(-) (limited to 'OpenSubtitlesHandler/SubtitleTypes') diff --git a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs index 7b40b5673..a8e9ff4a8 100644 --- a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs +++ b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs @@ -166,14 +166,7 @@ namespace MediaBrowser.Providers.Subtitles public async Task> SearchSubtitles(SubtitleSearchRequest request, CancellationToken cancellationToken) { var imdbIdText = request.GetProviderId(MetadataProviders.Imdb); - long imdbId; - - if (string.IsNullOrWhiteSpace(imdbIdText) || - !long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId)) - { - _logger.Debug("Imdb id missing"); - return new List(); - } + long imdbId = 0; switch (request.ContentType) { @@ -190,6 +183,11 @@ namespace MediaBrowser.Providers.Subtitles _logger.Debug("Movie name missing"); return new List(); } + if (string.IsNullOrWhiteSpace(imdbIdText) || !long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId)) + { + _logger.Debug("Imdb id missing"); + return new List(); + } break; } @@ -208,16 +206,25 @@ namespace MediaBrowser.Providers.Subtitles var hash = Utilities.ComputeHash(request.MediaPath); var fileInfo = new FileInfo(request.MediaPath); var movieByteSize = fileInfo.Length; - + var searchImdbId = request.ContentType == SubtitleMediaType.Movie ? imdbId.ToString(_usCulture) : ""; var subtitleSearchParameters = request.ContentType == SubtitleMediaType.Episode - ? new SubtitleSearchParameters(subLanguageId, request.SeriesName, request.ParentIndexNumber.Value.ToString(_usCulture), request.IndexNumber.Value.ToString(_usCulture)) - : new SubtitleSearchParameters(subLanguageId, request.Name); - + ? new List { + new SubtitleSearchParameters(subLanguageId, + query: request.SeriesName, + season: request.ParentIndexNumber.Value.ToString(_usCulture), + episode: request.IndexNumber.Value.ToString(_usCulture)) + } + : new List { + new SubtitleSearchParameters(subLanguageId, imdbid: searchImdbId), + new SubtitleSearchParameters(subLanguageId, query: request.Name, imdbid: searchImdbId) + }; var parms = new List { - new SubtitleSearchParameters(subLanguageId, hash, movieByteSize), - subtitleSearchParameters + new SubtitleSearchParameters( subLanguageId, + movieHash: hash, + movieByteSize: movieByteSize, + imdbid: searchImdbId ), }; - + parms.AddRange(subtitleSearchParameters); var result = OpenSubtitles.SearchSubtitles(parms.ToArray()); if (!(result is MethodResponseSubtitleSearch)) { diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs index f2e70ef81..46af6215b 100644 --- a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs +++ b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs @@ -25,63 +25,17 @@ namespace OpenSubtitlesHandler /// public struct SubtitleSearchParameters { - /// - /// Paramaters for subtitle search call - /// - /// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo') - /// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes - /// Size of video file in bytes - public SubtitleSearchParameters(string subLanguageId, string movieHash, long movieByteSize) + public SubtitleSearchParameters(string subLanguageId, string query = "", string season = "", string episode = "", string movieHash = "", long movieByteSize = 0, string imdbid = "") { 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.imdbid = imdbid; this._episode = episode; this._season = season; this._query = query; } - /// - /// Paramaters for subtitle search call - /// - /// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo') - /// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes - /// Size of video file in bytes - /// IMDb ID of movie this video is part of, belongs to. - public SubtitleSearchParameters(string subLanguageId, string movieHash, long movieByteSize, string imdbid) - { - this.subLanguageId = subLanguageId; - this.movieHash = movieHash; - this.movieByteSize = movieByteSize; - this.imdbid = imdbid; - this._episode = ""; - this._season = ""; - this._query = ""; - } - private string subLanguageId; private string movieHash; private long movieByteSize; -- cgit v1.2.3