public override IEnumerable <SubtitlesDto> GetSubtitles(string subtitleSourceUrl)
        {
            var httpRequestHeaders = new List <KeyValuePair <string, string> >();

            httpRequestHeaders.Add(new KeyValuePair <string, string>("referer", baseUrl));

            DownloadSubtitlesZipFile(subtitleSourceUrl, httpRequestHeaders);
            var subtitlesFile = GetSubtitlesFile();

            return(SubtitlesConverter.GetSubtitles(subtitlesFile));
        }
        public async Task <SubtitleResponse> GetSubtitles(string hash, CancellationToken cancellationToken)
        {
            var opts = NapiCore.CreateRequest(hash, "PL");

            _logger.Info($"Requesting {opts.Url}");

            try
            {
                using (var response = await _httpClient.Post(opts).ConfigureAwait(false))
                {
                    using (var reader = new StreamReader(response.Content))
                    {
                        var xml = await reader.ReadToEndAsync().ConfigureAwait(false);

                        var status = XmlParser.GetStatusFromXml(xml);

                        if (status != null && status == "success")
                        {
                            var subtitlesBase64 = XmlParser.GetSubtitlesBase64(xml);
                            var stream          = XmlParser.GetSubtitlesStream(subtitlesBase64);
                            var subRip          = SubtitlesConverter.ConvertToSubRipStream(stream);

                            if (subRip != null)
                            {
                                return(new SubtitleResponse
                                {
                                    Format = "srt",
                                    Language = "PL",
                                    Stream = subRip
                                });
                            }
                        }
                    }
                }

                _logger.Info("No subtitles downloaded");
                return(new SubtitleResponse());
            }
            catch (HttpException ex)
            {
                if (!ex.StatusCode.HasValue || ex.StatusCode.Value != HttpStatusCode.NotFound)
                {
                    throw;
                }
                _logger.Debug("ERROR");
                return(new SubtitleResponse());
            }
        }
Exemple #3
0
        public override IEnumerable <SubtitlesDto> GetSubtitles(string subtitlesSourceUrl)
        {
            var doc = HttpRequester.GetHtmlDocumentAsync(subtitlesSourceUrl).Result;

            var subtitlesDownloadUrl = doc.DocumentNode.SelectSingleNode("//a[@class='btn-icon download-subtitle']")?.Attributes["href"]?.Value;

            if (string.IsNullOrEmpty(subtitlesDownloadUrl))
            {
                return(null);
            }

            DownloadSubtitlesZipFile(subtitlesDownloadUrl, null);
            var subtitlesFile = GetSubtitlesFile();

            return(SubtitlesConverter.GetSubtitles(subtitlesFile));
        }
Exemple #4
0
        public async Task <SubtitleResponse> GetSubtitles(string hash, CancellationToken cancellationToken)
        {
            var request = NapiCore.CreateRequest(hash, "PL");

            try
            {
                using (var response = await _httpClient.SendAsync(request).ConfigureAwait(false))
                {
                    var xml = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    var status = XmlParser.GetStatusFromXml(xml);

                    _logger.LogInformation($"Response status: {status}");

                    if (status != null && status == "success")
                    {
                        var subtitlesBase64 = XmlParser.GetSubtitlesBase64(xml);
                        var stream          = XmlParser.GetSubtitlesStream(subtitlesBase64);
                        var subRip          = SubtitlesConverter.ConvertToSubRipStream(stream);

                        if (subRip != null)
                        {
                            return(new SubtitleResponse
                            {
                                Format = "srt",
                                Language = "PL",
                                Stream = subRip
                            });
                        }
                    }
                }

                _logger.LogInformation("No subtitles downloaded");
                return(new SubtitleResponse());
            }
            catch (Exception)
            {
                return(new SubtitleResponse());
            }
        }