protected override async Task <Uri> GetEpisodeDownloadUrl(Episode episode) { var episodeSrcUrls = new List <string>(); Driver.Url = episode.EpisodeUri.AbsoluteUri; var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30)); AcceptCookies(wait); var table = GetTable(wait); var rows = table.FindElements(By.TagName("tr")); var episodeSources = new List <EpisodeSource>(); foreach (var row in rows) { var columns = row.FindElements(By.TagName("td")); var providerName = columns[0].Text; if (providerName.ToLower().Contains("cda".ToLower())) { var spans = columns[2].FindElements(By.TagName("span")); var soundsLanguage = spans[1].GetAttribute("textContent"); if (!soundsLanguage.Equals("japoński", StringComparison.InvariantCultureIgnoreCase)) { continue; } var quality = columns[1].Text; var button = columns[5].FindElement(By.TagName("a")); var episodeSource = new EpisodeSource { ProviderType = ProviderType.Cda, Quality = QualityParser.FromString(quality), Language = Language.PL, Button = button }; episodeSources.Add(episodeSource); } } if (episodeSources.Count == 0) { throw new NullReferenceException("Episodes with chosen criteria not found"); } episodeSources = episodeSources .OrderByDescending(a => a.Language) .ThenByDescending(a => a.Quality) .ToList(); foreach (var episodeSource in episodeSources) { try { TryClickButton(episodeSource); IWebElement iframe; try { iframe = wait.Until(a => a.FindElement(By.XPath("/html/body/div[4]/div/article/div[2]/div/iframe"))); } catch (WebDriverTimeoutException) { continue; } var src = iframe.GetAttribute("src"); var fullSrc = $"{src}?wersja={episodeSource.Quality.GetDescription()}"; episodeSource.SourceUrl = fullSrc; } catch (InvalidOperationException) { } } Uri episodeUri = null; foreach (var episodeSource in episodeSources) { try { episodeUri = await new ProviderFactory(Driver).GetProvider(episodeSource.ProviderType) .GetVideoSourceAsync(episodeSource.SourceUrl); break; } catch (WebDriverTimeoutException) { } } if (episodeUri == null) { throw new InvalidOperationException("Could not find any episode source to download"); } return(episodeUri); }