Inheritance: IMangaRecord
Ejemplo n.º 1
0
        public IEnumerable<ChapterRecord> GetAvailableChapters(MangaRecord manga)
        {
            if (manga == null)
                throw new ArgumentNullException("manga");
            if (manga.Scraper != ScraperGuid)
                throw new ArgumentException("Manga record is not for " + Name, "manga");

            var cacheKey = ChapterCacheKey + manga.MangaName + manga.Url;

            var cached = _cache[cacheKey] as IEnumerable<ChapterRecord>;
            if (cached != null) // if chapters are already in cache return them
                return cached;

            var records = new List<ChapterRecord>();
            var document = WebHelper.GetHtmlDocument(DictionaryUrl);

            var columns = document.SelectNodes(@"//div[@id=""contentwrap-inner""]/table/tr/td");
            if (columns == null)
            {
                throw new ParserException("Could not find expected elements on website.", document.InnerHtml);
            }

            foreach (var column in columns)
            {
                string mangaName = "";

                if (column.ChildNodes == null) // not sure if they initialize child nodes with empty enumerable when there are no childs, so just to be sure
                    continue;

                foreach (var item in column.ChildNodes)
                {
                    switch (item.Name)
                    {
                        case "strong":
                            mangaName = CleanupText(item.InnerText);
                            break;
                        case "a":
                            if (mangaName == manga.MangaName)
                            {
                                records.Add(new ChapterRecord(ScraperGuid)
                                {
                                    MangaName = mangaName,
                                    ChapterName = CleanupText(item.InnerText),
                                    Url = GetFullUrl(item.Attributes.FirstOrDefault(a => a.Name == "href").Value),
                                    MangaRecord = manga
                                });
                            }
                            break;
                        default:
                            break;
                    }
                }
            }

            // save to cache
            _cache[cacheKey] = records;

            return records;
        }
Ejemplo n.º 2
0
        public IEnumerable<ChapterRecord> GetAvailableChapters(MangaRecord manga)
        {
            if (manga == null)
                throw new ArgumentNullException("manga");
            if (manga.Scraper != ScraperGuid)
                throw new ArgumentException("Manga record is not for " + Name, "manga");

            var cacheKey = ChapterCacheKey + manga.MangaName + manga.Url;

            var cached = _cache[cacheKey] as IEnumerable<ChapterRecord>;
            if (cached != null) // if chapters are already in cache return them
                return cached;

            var records = new List<ChapterRecord>();
            var document = WebHelper.GetHtmlDocument(manga.Url);

            var chapters = document.SelectNodes(@"//table[@id=""updates""]//th/a");
            if (chapters == null)
            {
                throw new ParserException("Could not find expected elements on website.", document.InnerHtml);
            }

            foreach (var chapter in chapters)
            {
                var sibling = chapter.ParentNode.NextSibling;
                if (sibling != null)
                {
                    // skip "in xx days" nodes
                    if (sibling.InnerText.IndexOf("ago", StringComparison.InvariantCultureIgnoreCase) == -1)
                        continue;
                }

                records.Add(new ChapterRecord(ScraperGuid)
                {
                    MangaName = manga.MangaName,
                    ChapterName = CleanupText(chapter.InnerText),
                    Url = GetFullUrl(chapter.Attributes["href"].Value),
                    MangaRecord = manga
                });
            }

            // save to cache
            _cache[cacheKey] = records;

            return records;
        }
Ejemplo n.º 3
0
        public IEnumerable<ChapterRecord> GetAvailableChapters(MangaRecord manga)
        {
            if (manga == null)
                throw new ArgumentNullException("manga");
            if (manga.Scraper != ScraperGuid)
                throw new ArgumentException("Manga record is not for " + Name, "manga");

            var cacheKey = ChapterCacheKey + manga.MangaName + manga.Url;

            var cached = _cache[cacheKey] as IEnumerable<ChapterRecord>;
            if (cached != null) // if chapters are already in cache return them
                return cached;

            var records = new List<ChapterRecord>();
            var document = WebHelper.GetHtmlDocument(manga.Url);

            var chapters = document.SelectNodes(@"//table[@id=""listing""]/tr/td[1]");
            if (chapters == null)
            {
                throw new ParserException("Could not find expected elements on website.", document.InnerHtml);
            }

            foreach (var chapter in chapters)
            {
                records.Add(new ChapterRecord(ScraperGuid)
                {
                    MangaName = manga.MangaName,
                    ChapterName = CleanupText(chapter.InnerText),
                    Url = GetFullUrl(chapter.ChildNodes.FirstOrDefault(n => n.Name == "a").Attributes["href"].Value),
                    MangaRecord = manga
                });
            }

            // save to cache
            _cache[cacheKey] = records;

            return records;
        }
Ejemplo n.º 4
0
        public IEnumerable<ChapterRecord> GetAvailableChapters(MangaRecord manga)
        {
            if (manga == null)
                throw new ArgumentNullException("manga");
            if (manga.Scraper != ScraperGuid)
                throw new ArgumentException("Manga record is not for " + Name, "manga");

            var cacheKey = ChapterCacheKey + manga.MangaName + manga.Url;

            var cached = _cache[cacheKey] as IEnumerable<ChapterRecord>;
            if (cached != null) // if chapters are already in cache return them
                return cached;

            var records = new List<ChapterRecord>();
            var document = WebHelper.GetHtmlDocument(manga.Url);

            var chapters = document.SelectNodes(@"//select[@name=""chapter""]/option");
            if (chapters == null)
            {
                throw new ParserException("Could not find expected elements on website.", document.InnerHtml);
            }

            foreach (var chapter in chapters)
            {
                records.Add(new ChapterRecord(ScraperGuid)
                {
                    MangaName = manga.MangaName,
                    ChapterName = CleanupText(chapter.InnerText),
                    Url = String.Format(EGScansChapterUrlFormat, manga.Url, chapter.Attributes["value"].Value),
                    MangaRecord = manga
                });
            }

            // save to cache
            _cache[cacheKey] = records;

            return records;
        }
Ejemplo n.º 5
0
        private void LoadChapters(MangaRecord manga)
        {
            if (manga == null)
                return;

            var scraper = CurrentScraper;

            ProgressIndeterminate = true;
            InvokePropertyChanged("ProgressIndeterminate");
            CurrentActionText = "Loading chapters ...";
            InvokePropertyChanged("CurrentActionText");

            _requestQueue.Add(
                () =>
                {
                    return scraper.GetAvailableChapters(manga);
                },
                (r, e) =>
                {
                    var results = r as IEnumerable<ChapterRecord>;
                    if (e == null && r != null)
                    {
                        lock (_syncRoot)
                        {
                            // just replace collection -> this is easier than removing and than adding records
                            Chapters = new AsyncObservableCollection<ChapterRecord>(results);
                            InvokePropertyChanged("Chapters");
                        }
                    }
                }
            );
        }