Example #1
0
        private async Task <IList <Subtitle> > SearchSubtitlesInternal(SearchSubtitlesRequest request)
        {
            var client = new RestClient(Constants.OpenSubtitlesRestApiEndpoint)
            {
                UserAgent = Constants.OsdbUa
            };
            var segment = "search/{imdbid}";

            if (request.Episode.HasValue)
            {
                segment += "/{episode}";
            }

            if (request.Season.HasValue)
            {
                segment += "/{season}";
            }

            var restRequest = new RestRequest(segment, Method.GET);

            restRequest.AddUrlSegment("imdbid", $"imdbid-{request.ImdbId}");
            if (request.Episode.HasValue)
            {
                restRequest.AddUrlSegment("episode", $"episode-{request.Episode.Value.ToString()}");
            }

            if (request.Season.HasValue)
            {
                restRequest.AddUrlSegment("season", $"season-{request.Season.Value.ToString()}");
            }
            var response = await client.ExecuteTaskAsync <IEnumerable <Subtitle> >(restRequest);

            return(response.Data.ToList());
        }
Example #2
0
        private Task <IList <Subtitle> > SearchSubtitlesInternal(SearchSubtitlesRequest request)
        {
            var tcs = new TaskCompletionSource <IList <Subtitle> >();

            try
            {
                var response = Proxy.SearchSubtitles(Token, new[] { request });
                VerifyResponseCode(response);

                var subtitles     = new List <Subtitle>();
                var subtitlesInfo = response.data as object[];
                if (null != subtitlesInfo)
                {
                    foreach (var infoObject in subtitlesInfo)
                    {
                        var subInfo = SimpleObjectMapper.MapToObject <SearchSubtitlesInfo>((XmlRpcStruct)infoObject);
                        subtitles.Add(BuildSubtitleObject(subInfo));
                    }
                }
                tcs.TrySetResult(subtitles);
            }
            catch (Exception ex)
            {
                tcs.TrySetException(ex);
            }

            return(tcs.Task);
        }
Example #3
0
        public async Task <IList <Subtitle> > SearchSubtitlesFromFile(string languages, string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException(nameof(filename));
            }

            var file = new FileInfo(filename);

            if (!file.Exists)
            {
                throw new ArgumentException("File doesn't exist", nameof(filename));
            }
            var request = new SearchSubtitlesRequest
            {
                sublanguageid = languages,
                moviehash     = HashHelper.ToHexadecimal(HashHelper.ComputeMovieHash(filename)),
                moviebytesize = file.Length.ToString(),
                imdbid        = string.Empty,
                query         = string.Empty
            };


            return(await SearchSubtitlesInternal(request));
        }
        public IEnumerable<OpenSubtitle> SearchSubtitlesFromFile(string token, IEnumerable<string> languages, string hash, long byteSize)
        {
            var request = new SearchSubtitlesRequest
            {
                sublanguageid = string.Join(",", languages),
                moviehash = hash,
                moviebytesize = byteSize.ToString()
            };

            return SearchSubtitlesInternal(token, request);
        }
Example #5
0
        public IList <Subtitle> SearchSubtitlesFromImdb(string languages, string imdbId)
        {
            if (string.IsNullOrEmpty(imdbId))
            {
                throw new ArgumentNullException(nameof(imdbId));
            }
            var request = new SearchSubtitlesRequest
            {
                sublanguageid = languages,
                imdbid        = imdbId
            };

            return(SearchSubtitlesInternal(request));
        }
Example #6
0
        public Task <IList <Subtitle> > SearchSubtitlesFromImdb(string languages, string imdbId, int?season, int?episode)
        {
            if (string.IsNullOrEmpty(imdbId))
            {
                throw new ArgumentNullException(nameof(imdbId));
            }

            var request = new SearchSubtitlesRequest
            {
                sublanguageid = languages,
                imdbid        = imdbId,
                episode       = episode,
                season        = season
            };

            return(SearchSubtitlesInternal(request));
        }
Example #7
0
        public async Task <IList <Subtitle> > SearchSubtitlesFromQuery(string languages, string query, int?season = null,
                                                                       int?episode = null)
        {
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentNullException(nameof(query));
            }
            var request = new SearchSubtitlesRequest
            {
                sublanguageid = languages,
                query         = query,
                season        = season,
                episode       = episode
            };

            return(await SearchSubtitlesInternal(request));
        }
Example #8
0
        private IList <Subtitle> SearchSubtitlesInternal(SearchSubtitlesRequest request)
        {
            var response = _proxy.SearchSubtitles(_token, new[] { request });

            VerifyResponseCode(response);

            var subtitles = new List <Subtitle>();

            var subtitlesInfo = response.data as object[];

            if (null != subtitlesInfo)
            {
                foreach (var infoObject in subtitlesInfo)
                {
                    var subInfo = SimpleObjectMapper.MapToObject <SearchSubtitlesInfo>((XmlRpcStruct)infoObject);
                    subtitles.Add(BuildSubtitleObject(subInfo));
                }
            }
            return(subtitles);
        }
        public IEnumerable<OpenSubtitle> SearchSubtitlesFromQuery(string token, IEnumerable<string> languages, string query, int? season = null, int? episode = null)
        {
            if (string.IsNullOrEmpty(query))
                throw new ArgumentNullException(nameof(query));

            var request = new SearchSubtitlesRequest
            {
                sublanguageid = string.Join(",", languages),
                query = query,
                season = season,
                episode = episode
            };
            return SearchSubtitlesInternal(token, request);
        }
        public IEnumerable<OpenSubtitle> SearchSubtitlesFromImdb(string token, IEnumerable<string> languages, string imdbId)
        {
            if (string.IsNullOrEmpty(imdbId))
                throw new ArgumentNullException(nameof(imdbId));

            var request = new SearchSubtitlesRequest
            {
                sublanguageid = string.Join(",", languages),
                imdbid = imdbId
            };
            return SearchSubtitlesInternal(token, request);
        }
        private IEnumerable<OpenSubtitle> SearchSubtitlesInternal(string token, SearchSubtitlesRequest request)
        {
            var response = _proxy.SearchSubtitles(token, new[] { request });
            AssertResponse(response);

            var subtitleData = response.data;
            if (subtitleData == null)
                return Enumerable.Empty<OpenSubtitle>();

            return subtitleData.Select(BuildSubtitle);
        }