예제 #1
0
        public async Task Test1()
        {
            // load fake XML first.
            string feed = await NyaaRSSFeed.GetRSSFeed();

            var document = NyaaXMLConverter.ParseXML(feed);
            var torrents = NyaaXMLConverter.GetTorrents(document);

            var parsedTorrents = NyaaParser.ParseNyaaTorrents(torrents);
        }
        /// <summary>
        /// Performs the actual check for the anime
        /// </summary>
        /// <returns>true if something has been found</returns>
        public static async Task <bool> Check()
        {
            // get the XML, and parse it
            var xml = await NyaaRSSFeed.GetRSSFeed();

            var parsedXML = NyaaXMLConverter.ParseXML(xml);

            NyaaTorrentModel[] rawTorrents = NyaaXMLConverter.GetTorrents(parsedXML);

            string lastChecked = Database.Database.GetLastChecked();

            ParsedNyaaTorrentModel[] parsedTorrents = NyaaParser.ParseNyaaTorrents(rawTorrents)
                                                      .TakeWhile(x => x.NyaaTorrentModel.InfoHash != lastChecked).ToArray();

            // if the list is empty, return false.
            if (parsedTorrents.Length == 0)
            {
                return(false);
            }

            // set the lastChecked to the first occurence fiaojfoiasoi jdsfjsdoif doisf
            Database.Database.SetLastChecked(parsedTorrents[0].NyaaTorrentModel.InfoHash);


            // get ALL EPIC ANIME
            var(_, collection) = Database.Database.GetDatabaseAndSubscriptionCollection();

            var guildAnimes     = collection.FindAll().ToList();
            var animeToAnnounce = new List <AnnounceModel>();

            bool foundSomething = false;

            foreach (var parsedTorrent in parsedTorrents)
            {
                // if the title is correct, add it to the update list.
                var validAnime = guildAnimes.Where(x =>
                {
                    bool valid = true;

                    const double minSim = 0.55;

                    double confidence = Math.Max(
                        (x.AnimeTitle.EnglishTitle ?? "").ToLower().GetSimilarity((parsedTorrent.AnimeTitle ?? "").ToLower()),
                        x.AnimeTitle.RomajiTitle.ToLower().GetSimilarity((parsedTorrent.AnimeTitle ?? "").ToLower()));

                    valid = confidence >= minSim;

                    valid = valid && x.WantedSubgroupTitle.Contains(parsedTorrent.SubGroup.ToLower());

                    valid = valid && parsedTorrent.Episode >= x.LastAnnouncedEpisode;

                    return(valid);
                });

                foreach (var anime in validAnime)
                {
                    var m = new AnnounceModel()
                    {
                        AnimeGuildModel = anime,
                        Episode         = parsedTorrent.Episode
                    };

                    if (parsedTorrent.Quality != Quality.Unknown)
                    {
                        m.QualityLinks[parsedTorrent.Quality] = new SubgroupTorrentLink(parsedTorrent.NyaaTorrentModel.Link,
                                                                                        parsedTorrent.SubGroup);
                    }

                    if (!animeToAnnounce.Any(x => x.AnimeGuildModel.AnimeID == anime.AnimeID &&
                                             animeToAnnounce.Any(y => y.AnimeGuildModel.Guild == x.AnimeGuildModel.Guild)))
                    {
                        animeToAnnounce.Add(m);
                    }
                    AnimeReminderAnnouncer.UpdateAnime(m);

                    foundSomething = true;
                }
            }

            foreach (var anime in animeToAnnounce)
            {
                AnimeReminderAnnouncer.Announce(anime);
                anime.AnimeGuildModel.LastAnnouncedEpisode = anime.Episode;
                collection.Update(anime.AnimeGuildModel);
            }

            return(foundSomething);
        }