Ejemplo n.º 1
0
        public string GetRecentOutputFolder(IMangaRecord mangaRecord)
        {
            if (mangaRecord == null)
            {
                throw new ArgumentNullException("mangaRecord");
            }

            try
            {
                IDictionary <string, int> folders = _storage.GetRecentFolders(mangaRecord.Scraper, mangaRecord.MangaId);

                if (folders.Count == 0)
                {
                    return(null);
                }

                // return the folder name with most usages
                return(folders.Aggregate((l, r) => l.Value > r.Value ? l : r).Key);
            }
            catch (StorageException)
            {
                throw;
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        private void LoadChapters(IMangaRecord manga)
        {
            if (manga == null)
            {
                return;
            }

            var scraper = CurrentScraper;

            OperationInProgress = true;
            CurrentActionText   = "Loading chapters ...";

            _requestQueue.Add(
                () => scraper.GetAvailableChapters(manga),
                (r, e) =>
            {
                var results = r as IEnumerable <IChapterRecord>;
                if (e == null && results != null)
                {
                    lock (_syncRoot)
                    {
                        // just replace collection -> this is easier than removing and then adding records
                        Chapters =
                            new AsyncObservableCollection <ChapterViewModel>(
                                results.Select(ch => new ChapterViewModel(ch, ServiceLocator.Instance.GetService <Library.ILibraryManager>().GetDownloadInfo(ch, true))));
                        OnPropertyChanged(() => Chapters);
                    }
                }
            }
                );
        }
Ejemplo n.º 3
0
        public RecentMangaRecord(IMangaRecord mangaRecord)
        {
            if (mangaRecord == null)
                throw new ArgumentNullException("mangaRecord");

            _mangaRecord = mangaRecord;

            _scraper = ScraperLoader.Instance.AllScrapers.FirstOrDefault(s => s.ScraperGuid == _mangaRecord.Scraper);
        }
Ejemplo n.º 4
0
        public IEnumerable <IChapterRecord> GetAvailableChapters(IMangaRecord 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;
                    }
                }

                var url = GetFullUrl(chapter.Attributes["href"].Value);

                records.Add(new ChapterRecord(ScraperGuid, url)
                {
                    ChapterName = CleanupText(chapter.InnerText),
                    Url         = url,
                    MangaRecord = manga
                });
            }

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

            return(records);
        }
Ejemplo n.º 5
0
        public RecentMangaRecord(IMangaRecord mangaRecord)
        {
            if (mangaRecord == null)
            {
                throw new ArgumentNullException("mangaRecord");
            }

            _mangaRecord = mangaRecord;

            _scraper = ScraperLoader.Instance.AllScrapers.FirstOrDefault(s => s.ScraperGuid == _mangaRecord.Scraper);
        }
Ejemplo n.º 6
0
        public IEnumerable<DownloadedChapterInfo> GetChaptersInfo(IMangaRecord mangaRecord)
        {
            if (mangaRecord == null)
                throw new ArgumentNullException("mangaRecord");

            return GetChaptersInfo("ch.ScraperId = @ScraperId AND ch.MangaId = @MangaId", new Dictionary<string, object>()
                                                                                             {
                                                                                                 {"@ScraperId", mangaRecord.Scraper},
                                                                                                 {"@MangaId", mangaRecord.MangaId}
                                                                                             });
        }
Ejemplo n.º 7
0
        public IEnumerable<IChapterRecord> GetAvailableChapters(IMangaRecord manga)
        {
            if (manga == null)
                throw new ArgumentNullException("manga");

            var scraper = ScraperLoader.Instance.AllScrapers.FirstOrDefault(s => s.ScraperGuid == manga.Scraper);

            if (scraper == null)
                return Enumerable.Empty<IChapterRecord>();

            return scraper.GetAvailableChapters(manga);
        }
Ejemplo n.º 8
0
        public IEnumerable <DownloadedChapterInfo> GetChaptersInfo(IMangaRecord mangaRecord)
        {
            if (mangaRecord == null)
            {
                throw new ArgumentNullException("mangaRecord");
            }

            return(GetChaptersInfo("ch.ScraperId = @ScraperId AND ch.MangaId = @MangaId", new Dictionary <string, object>()
            {
                { "@ScraperId", mangaRecord.Scraper },
                { "@MangaId", mangaRecord.MangaId }
            }));
        }
Ejemplo n.º 9
0
        public IEnumerable <IChapterRecord> GetAvailableChapters(IMangaRecord manga)
        {
            if (manga == null)
            {
                throw new ArgumentNullException("manga");
            }

            var scraper = ScraperLoader.Instance.AllScrapers.FirstOrDefault(s => s.ScraperGuid == manga.Scraper);

            if (scraper == null)
            {
                return(Enumerable.Empty <IChapterRecord>());
            }

            return(scraper.GetAvailableChapters(manga));
        }
Ejemplo n.º 10
0
        public IEnumerable <IChapterRecord> GetAvailableChapters(IMangaRecord 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(@"//ul[@class=""chlist""]/li//h3|//ul[@class=""chlist""]/li//h4");

            if (chapters == null)
            {
                throw new ParserException("Could not find expected elements on website.", document.InnerHtml);
            }

            foreach (var chapter in chapters)
            {
                var url = GetFullUrl(chapter.ChildNodes.FirstOrDefault(n => n.Name == "a").Attributes["href"].Value);

                records.Add(new ChapterRecord(ScraperGuid, url)
                {
                    ChapterName = CleanupText(chapter.InnerText),
                    Url         = url,
                    MangaRecord = manga
                });
            }

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

            return(records);
        }
Ejemplo n.º 11
0
        public IEnumerable<IChapterRecord> GetAvailableChapters(IMangaRecord 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;
                }

                var url = GetFullUrl(chapter.Attributes["href"].Value);

                records.Add(new ChapterRecord(ScraperGuid, url)
                {
                    ChapterName = CleanupText(chapter.InnerText),
                    Url = url,
                    MangaRecord = manga
                });
            }

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

            return records;
        }
Ejemplo n.º 12
0
        public IEnumerable <IChapterRecord> GetAvailableChapters(IMangaRecord 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)
            {
                var url = String.Format(EGScansChapterUrlFormat, manga.Url, chapter.Attributes["value"].Value);

                records.Add(new ChapterRecord(ScraperGuid, url)
                {
                    ChapterName = CleanupText(chapter.InnerText),
                    Url         = url,
                    MangaRecord = manga
                });
            }

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

            return(records);
        }
Ejemplo n.º 13
0
        private void PreSelectDownloadFolder(IMangaRecord mangaRecord)
        {
            if (mangaRecord == null)
            {
                throw new ArgumentNullException("mangaRecord");
            }

            if (!Properties.Settings.Default.PreselectOutputFolder)
            {
                return;
            }

            string folder = ServiceLocator.Instance.GetService <Library.ILibraryManager>().GetRecentOutputFolder(mangaRecord);

            if (String.IsNullOrEmpty(folder))
            {
                return;
            }

            OutputPath = folder;
        }
Ejemplo n.º 14
0
        public IEnumerable<IChapterRecord> GetAvailableChapters(IMangaRecord 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)
            {
                var url = String.Format(EGScansChapterUrlFormat, manga.Url, chapter.Attributes["value"].Value);

                records.Add(new ChapterRecord(ScraperGuid, url)
                {
                    ChapterName = CleanupText(chapter.InnerText),
                    Url = url,
                    MangaRecord = manga
                });
            }

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

            return records;
        }
Ejemplo n.º 15
0
        public IEnumerable<IChapterRecord> GetAvailableChapters(IMangaRecord 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[contains(@class, ""chapters_list"")]//tr[contains(@class, ""lang_English"")]/td[1]/a");
            if (chapters == null)
            {
                throw new ParserException("Could not find expected elements on website.", document.InnerHtml);
            }

            foreach (var chapter in chapters)
            {
                var url = GetFullUrl(chapter.Attributes["href"].Value);

                records.Add(new ChapterRecord(ScraperGuid, url)
                {
                    ChapterName = CleanupText(chapter.InnerText),
                    Url = url,
                    MangaRecord = manga
                });
            }

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

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

            var scraper = CurrentScraper;

            OperationInProgress = true;
            CurrentActionText = "Loading chapters ...";

            _requestQueue.Add(
                () => scraper.GetAvailableChapters(manga),
                (r, e) =>
                {
                    var results = r as IEnumerable<IChapterRecord>;
                    if (e == null && results != null)
                    {
                        lock (_syncRoot)
                        {
                            // just replace collection -> this is easier than removing and then adding records
                            Chapters =
                                new AsyncObservableCollection<ChapterViewModel>(
                                    results.Select(ch => new ChapterViewModel(ch, ServiceLocator.Instance.GetService<Library.ILibraryManager>().GetDownloadInfo(ch, true))));
                            OnPropertyChanged(() => Chapters);
                        }
                    }
                }
            );
        }
Ejemplo n.º 17
0
        public string GetRecentOutputFolder(IMangaRecord mangaRecord)
        {
            if (mangaRecord == null)
                throw new ArgumentNullException("mangaRecord");

            try
            {
                IDictionary<string, int> folders = _storage.GetRecentFolders(mangaRecord.Scraper, mangaRecord.MangaId);

                if (folders.Count == 0)
                    return null;

                // return the folder name with most usages
                return folders.Aggregate((l, r) => l.Value > r.Value ? l : r).Key;
            }
            catch (StorageException)
            {
                throw;
            }
            catch (Exception)
            {
                return null;
            }
        }
Ejemplo n.º 18
0
        private void PreSelectDownloadFolder(IMangaRecord mangaRecord)
        {
            if (mangaRecord == null)
                throw new ArgumentNullException("mangaRecord");

            if(!Properties.Settings.Default.PreselectOutputFolder)
                return;

            string folder = ServiceLocator.Instance.GetService<Library.ILibraryManager>().GetRecentOutputFolder(mangaRecord);

            if (String.IsNullOrEmpty(folder))
                return;

            OutputPath = folder;
        }