diff --git a/SyncService/Models/AnimeMatching.cs b/SyncService/Models/AnimeMatching.cs index bfddc3d..2473e39 100644 --- a/SyncService/Models/AnimeMatching.cs +++ b/SyncService/Models/AnimeMatching.cs @@ -13,5 +13,7 @@ public class AnimeMatching public int Score { get; set; } public string Path { get; set; } public List Episodes { get; set; } = new List(); + public string SourceVariant { get; set; } + public AnimeMatching Linked { get; set; } } } diff --git a/SyncService/Models/IWebsiteScraper.cs b/SyncService/Models/IWebsiteScraper.cs index e8a779f..b928bea 100644 --- a/SyncService/Models/IWebsiteScraper.cs +++ b/SyncService/Models/IWebsiteScraper.cs @@ -32,6 +32,8 @@ public abstract class IWebsiteScraper protected Thread Thread { get; private set; } public bool Working { get; private set; } = false; + protected List EpisodeMatchings = new List(); + public IWebsiteScraper(WebsiteScraperService service) { this.Service = service; @@ -174,43 +176,16 @@ private async Task run() try { - for (int i = 1; i <= _anime.EpisodesCount; i++) + AnimeMatching linked = matching.Linked; + + await getEpisodes(browser, matching); + + while (linked != null) { - browser = await ProxyHelper.Instance.GetBrowser(); - try - { - using (Page webPage = await ProxyHelper.Instance.GetBestProxy(browser, this.Website.CanBlockRequests)) - { - EpisodeMatching episode = await this.GetEpisode(webPage, matching, i); - - if (episode != null) - { - Episode ep = new Episode() - { - AnimeID = _anime.Id, - Source = this.Website.Name, - Number = episode.Number, - Title = episode.Title, - Video = episode.Source, - Locale = this.Website.Localization - }; - - if (this._episodeCollection.Exists(ref ep)) - { - this._episodeCollection.Edit(ref ep); - } - else - { - this._episodeCollection.Add(ref ep); - } - } - } - } - catch { } - finally - { - await browser.CloseAsync(); - } + EpisodeMatchings.Clear(); + + await getEpisodes(browser, linked); + linked = linked.Linked; } } catch @@ -264,6 +239,48 @@ private async Task run() } } + private async Task getEpisodes(Browser browser, AnimeMatching matching) + { + for (int i = 1; i <= _anime.EpisodesCount; i++) + { + browser = await ProxyHelper.Instance.GetBrowser(); + try + { + using (Page webPage = await ProxyHelper.Instance.GetBestProxy(browser, this.Website.CanBlockRequests)) + { + EpisodeMatching episode = await this.GetEpisode(webPage, matching, i); + + if (episode != null) + { + Episode ep = new Episode() + { + AnimeID = _anime.Id, + Source = $"{this.Website.Name}{matching.SourceVariant}", + Number = episode.Number, + Title = episode.Title, + Video = episode.Source, + Locale = this.Website.Localization + }; + + if (this._episodeCollection.Exists(ref ep)) + { + this._episodeCollection.Edit(ref ep); + } + else + { + this._episodeCollection.Add(ref ep); + } + } + } + } + catch { } + finally + { + await browser.CloseAsync(); + } + } + } + private bool animeNeedWork(bool forceReload = false) { if (forceReload) diff --git a/SyncService/Models/WebsiteScrapers/AnimeworldScraper.cs b/SyncService/Models/WebsiteScrapers/AnimeworldScraper.cs index 64039a7..29883a9 100644 --- a/SyncService/Models/WebsiteScrapers/AnimeworldScraper.cs +++ b/SyncService/Models/WebsiteScrapers/AnimeworldScraper.cs @@ -21,8 +21,6 @@ public AnimeworldScraper(WebsiteScraperService service) : base(service) protected override Type WebsiteType => typeof(AnimeworldScraper); - private List episodesMatchings = new List(); - protected override async Task GetMatching(Page webPage, string animeTitle) { AnimeMatching matching = null; @@ -30,7 +28,7 @@ protected override async Task GetMatching(Page webPage, string an string url = $"{this.Website.SiteUrl}search?keyword={animeTitle}"; await ProxyHelper.NavigateAsync(webPage, url); - episodesMatchings.Clear(); + EpisodeMatchings.Clear(); await webPage.WaitForSelectorAsync(".film-list", new WaitForSelectorOptions() { @@ -62,7 +60,7 @@ protected override async Task GetEpisode(Page webPage, AnimeMat { string url; - if (episodesMatchings.Count == 0) + if (EpisodeMatchings.Count == 0) { url = this.Website.SiteUrl.Substring(0, this.Website.SiteUrl.Length - 1); url = $"{url}{matching.Path}"; @@ -94,7 +92,7 @@ protected override async Task GetEpisode(Page webPage, AnimeMat string path = await info.EvaluateFunctionAsync("e => e.getAttribute('href')"); string title = (await info.EvaluateFunctionAsync("e => e.innerText")).Trim(); - episodesMatchings.Add(new EpisodeMatching() + EpisodeMatchings.Add(new EpisodeMatching() { Path = path, Title = title @@ -105,7 +103,7 @@ protected override async Task GetEpisode(Page webPage, AnimeMat } } - EpisodeMatching episode = episodesMatchings[number - 1]; + EpisodeMatching episode = EpisodeMatchings[number - 1]; if (episode != null) { diff --git a/SyncService/Models/WebsiteScrapers/DreamsubScraper.cs b/SyncService/Models/WebsiteScrapers/DreamsubScraper.cs index 8b6f54b..fc0b05a 100644 --- a/SyncService/Models/WebsiteScrapers/DreamsubScraper.cs +++ b/SyncService/Models/WebsiteScrapers/DreamsubScraper.cs @@ -26,7 +26,7 @@ protected override async Task GetMatching(Page webPage, string an { AnimeMatching matching = null; - episodesMatchings.Clear(); + EpisodeMatchings.Clear(); string url = $"{this.Website.SiteUrl}/search/?q={animeTitle}"; await ProxyHelper.NavigateAsync(webPage, url); @@ -56,13 +56,11 @@ protected override async Task GetMatching(Page webPage, string an return null; } - private List episodesMatchings = new List(); - protected override async Task GetEpisode(Page webPage, AnimeMatching matching, int number) { string url; - if(episodesMatchings.Count == 0) + if(EpisodeMatchings.Count == 0) { url = $"{this.Website.SiteUrl}{matching.Path}"; await ProxyHelper.NavigateAsync(webPage, url); @@ -83,7 +81,7 @@ protected override async Task GetEpisode(Page webPage, AnimeMat string path = await info.EvaluateFunctionAsync("e => e.getAttribute('href')"); string title = (await info.EvaluateFunctionAsync("e => e.innerText")).Trim().Split(": ")[1]; - episodesMatchings.Add(new EpisodeMatching() + EpisodeMatchings.Add(new EpisodeMatching() { Path = path, Title = title @@ -91,7 +89,7 @@ protected override async Task GetEpisode(Page webPage, AnimeMat } } - EpisodeMatching episode = episodesMatchings[number - 1]; + EpisodeMatching episode = EpisodeMatchings[number - 1]; if(episode != null) { diff --git a/SyncService/Models/WebsiteScrapers/GogoanimeScraper.cs b/SyncService/Models/WebsiteScrapers/GogoanimeScraper.cs index 5ad3f04..7576c5d 100644 --- a/SyncService/Models/WebsiteScrapers/GogoanimeScraper.cs +++ b/SyncService/Models/WebsiteScrapers/GogoanimeScraper.cs @@ -24,8 +24,6 @@ public GogoanimeScraper(WebsiteScraperService service) : base(service) protected override Type WebsiteType => typeof(GogoanimeScraper); - private List episodesMatchings = new List(); - protected override async Task GetMatching(Page webPage, string animeTitle) { AnimeMatching matching = null; @@ -44,7 +42,7 @@ protected override async Task GetMatching(Page webPage, string an new WebsiteCollection().Edit(ref website); } - episodesMatchings.Clear(); + EpisodeMatchings.Clear(); await webPage.WaitForSelectorAsync(".last_episodes", new WaitForSelectorOptions() { @@ -65,6 +63,13 @@ protected override async Task GetMatching(Page webPage, string an ElementHandle path = await title.QuerySelectorAsync("a"); matching.Path = (await path.EvaluateFunctionAsync("e => e.getAttribute('href')")).Trim(); + matching.Linked = new AnimeMatching() + { + Title = matching.Title, + Path = $"{matching.Path}-dub", + SourceVariant = "_dub" + }; + return matching; } } @@ -76,7 +81,7 @@ protected override async Task GetEpisode(Page webPage, AnimeMat { string url; - if (episodesMatchings.Count == 0) + if (EpisodeMatchings.Count == 0) { url = this.Website.SiteUrl.Substring(0, this.Website.SiteUrl.Length - 1); url = $"{url}{matching.Path}"; @@ -114,16 +119,16 @@ protected override async Task GetEpisode(Page webPage, AnimeMat string path = await info.EvaluateFunctionAsync("e => e.getAttribute('href')"); string title = (await info.QuerySelectorAsync(".name").EvaluateFunctionAsync("e => e.innerText")).Trim(); - episodesMatchings.Add(new EpisodeMatching() + EpisodeMatchings.Add(new EpisodeMatching() { Path = path, Title = title }); } - episodesMatchings.Reverse(); + EpisodeMatchings.Reverse(); } - EpisodeMatching episode = episodesMatchings[number - 1]; + EpisodeMatching episode = EpisodeMatchings[number - 1]; if (episode != null) {