public IList<Volume> GetVolumes(Comic comic) { IList<Volume> result = new List<Volume>(); // download volumes list Stream stream = WebClientFactory.Create(DOMAIN).OpenRead(comic.Url); HtmlDocument document = new HtmlDocument(); document.Load(stream, Encoding.UTF8); // parse volumes var volumeNodes = document.DocumentNode.SelectNodes("//ul[contains(@class, 'nr6')]/li/a"); foreach (var volumeNode in volumeNodes) { string href = volumeNode.GetAttributeValue("href", ""); if (!href.ToLowerInvariant().Contains("javascript")) { result.Insert(0, new Volume { Title = volumeNode.InnerText, Url = DOMAIN + href }); } } return result; }
public void Download(Comic comic) { var volumes = ComicProvider.GetVolumes(comic); foreach (var volume in volumes) { var pages = ComicProvider.GetPages(volume); foreach (var page in pages) { StorageProvider.Save(comic, volume, page); } } }
public void Save(Comic comic, Volume volume, Page page) { // setup the folder CreateFolder(comic, volume); // save the image string path = BuildPath(comic, volume, page); using (FileStream fileStream = File.Create(path)) { fileStream.Write(page.Image, 0, page.Image.Length); } }
private void CreateFolder(Comic comic, Volume volume) { string path = string.Format(FOLDER_TEMPLATE, _rootPath, comic.Title, volume.Title); Directory.CreateDirectory(path); }
private string BuildPath(Comic comic, Volume volume, Page page) { return string.Format(PATH_TEMPLATE, _rootPath, comic.Title, volume.Title, page.Number, page.ImageType); }