public override async Task <IEnumerable <RemoteMedia> > FindAllMedia(Anime anime, string name, int episode) { if (_nodes == null || (DateTime.Now - _lastUpdatedNodes).Minutes > 10) { await RetrieveNodes(); } return(_nodes .Where(item => // Episode is this season { if (item.Date.HasValue) { return (item.Date.Value - DateTime.Now).Days <= AnimeSeason.MaxAgeFor(anime, episode); } return true; }) .Where(item => item.StrippedName.Contains(episode.ToString()) && !item.StrippedName.Contains(episode.ToString() + ".5")) .Where(item => // Name contains everything { var title = Regex.Replace(item.StrippedWithNoEpisode.ToLower(), @"-|:|'", " "); var filtered = Regex.Replace( Regex.Replace(name, @"\s?(\d|\dnd season)$", "", RegexOptions.IgnoreCase), @"-|:|'", " "); var words = filtered.ToLower().Split(' ').ToList(); return words.Count(word => title.Contains(word)) > (words.Count / 2); }) .OrderByDescending(n => n.Name.Contains(anime.Resolution))); }
public override async Task <IEnumerable <RemoteMedia> > FindAllMedia(Anime anime, string name, int episode) { var document = new XmlDocument(); var url = new Uri("https://nyaa.pantsu.cat/feed" + $"?c={EnglishTranslated}" + "&s=" + $"&sort={BySeeders}" + "&order=desc" + "&max=20" + $"&q={TransformEpisodeSearch(name, episode)}"); // https://nyaa.pantsu.cat/feed // ?c=3_5&limit=50&order=false&q=new+game%21%21&s=0&sort=5&userID=0 using (var client = new WebClient()) { var html = await client.DownloadStringTaskAsync(url); document.LoadXml(html); } Console.WriteLine(document); var result = document.SelectNodes("//item") ?.Cast <XmlNode>() .Select(ToTorrent) .Where(item => // Episode is this season { if (item.Date.HasValue) { return((item.Date.Value - DateTime.Now).Days <= AnimeSeason.MaxAgeFor(anime, episode)); } return(true); }) .Where(item => Regex .Split(item.StrippedName, " ") .Any(s => s.Contains(episode.ToString("D2")) && !s.Contains(episode.ToString("D2") + ".5"))); if (anime.NameCollection.Any(c => Regex.Replace(c, YearPattern, "").Contains(episode.ToString("D2")))) { result = result? .Where(nyaa => nyaa.StrippedName.Split() .Select(c => Regex.Replace(c, YearPattern, "")) .Count(c => c.Contains(episode.ToString("D2"))) >= 2); } return(result?.OrderByDescending(n => n.Name.Contains(anime.Resolution))); }
public override async Task <IEnumerable <RemoteMedia> > FindAllMedia(Anime anime, string name, int episode) { var document = new XmlDocument(); var url = new Uri("https://nyaa.si/?page=rss" + $"&q={TransformEpisodeSearch(name, episode)}" + "&c=1_2" + "&f=0"); using (var client = new WebClient()) { var html = await client.DownloadStringTaskAsync(url); document.LoadXml(html); } var manager = new XmlNamespaceManager(document.NameTable); manager.AddNamespace("nyaa", "https://nyaa.si/xmlns/nyaa"); var result = document.SelectNodes("//item")? .Cast <XmlNode>() .Select(node => ToMedia(node, manager)) .Where(item => !item.Name.Contains("OAD")) // Shokugeki specific rule (bad...) .Where(item => // Episode is this season { if (item.Date.HasValue) { return((DateTime.Now - item.Date.Value).Days <= AnimeSeason.MaxAgeFor(anime, episode)); } return(true); }) .Where(item => Regex.Split(item.StrippedName, " ") .Any(s => s.Contains(episode.ToString("D2")) && !s.Contains(episode.ToString("D2") + ".5"))); return(result?.OrderByDescending(n => n.Name.Contains(anime.Resolution)).ThenByDescending(n => n.Health)); }