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); } }
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); } } } ); }
public RecentMangaRecord(IMangaRecord mangaRecord) { if (mangaRecord == null) throw new ArgumentNullException("mangaRecord"); _mangaRecord = mangaRecord; _scraper = ScraperLoader.Instance.AllScrapers.FirstOrDefault(s => s.ScraperGuid == _mangaRecord.Scraper); }
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); }
public RecentMangaRecord(IMangaRecord mangaRecord) { if (mangaRecord == null) { throw new ArgumentNullException("mangaRecord"); } _mangaRecord = mangaRecord; _scraper = ScraperLoader.Instance.AllScrapers.FirstOrDefault(s => s.ScraperGuid == _mangaRecord.Scraper); }
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} }); }
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); }
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 } })); }
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)); }
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); }
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; }
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); }
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; }
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; }
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; }
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); } } } ); }
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; } }
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; }