コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: DM5Provider.cs プロジェクト: leotse/ComicService
        public IList<Page> GetPages(Volume volume)
        {
            IList<Page> result = new List<Page>();

            // get the server comic id from the volume url
            string[] urlParts = volume.Url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            string comicId = urlParts[urlParts.Length - 1];
            comicId = comicId.Substring(1);

            // download the first page of the volume to check how many pages there are in total in this volume
            string firstPageHtml = WebClientFactory.Create(volume.Url).DownloadString(volume.Url);
            HtmlDocument firstPageDocument = new HtmlDocument();
            firstPageDocument.LoadHtml(firstPageHtml);
            int numPages = firstPageDocument.DocumentNode.SelectNodes("//select[@id='pagelist']/option").Count;

            // download the pages
            int currentPage = 1;
            while (currentPage <= numPages)
            {
                // call the web service (showimage.ashx) to get the actual comic image link
                // it is not known how many items this service returns hence this weird while loop...
                WebClient client = WebClientFactory.Create(volume.Url, Encoding.UTF8);
                string imageLinksString = client.DownloadString(volume.Url + string.Format(SHOWIMAGE_TEMPLATE, comicId, currentPage));

                // parse the result of the service call and store the pages
                string[] imageLinks = imageLinksString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < imageLinks.Length; i++)
                {
                    try
                    {
                        byte[] image = client.DownloadData(imageLinks[i]);
                        result.Add(new Page
                        {
                            Number = currentPage + i,
                            ImageUrl = imageLinks[i],
                            ImageType = IMAGE_TYPE,
                            Image = image
                        });
                    }
                    catch { }
                }

                // since we don't know how many items get returned before hand... update the current page accordingly
                currentPage += imageLinks.Length;
            }

            // finally return the results!
            return result;
        }
コード例 #3
0
 private void CreateFolder(Comic comic, Volume volume)
 {
     string path = string.Format(FOLDER_TEMPLATE, _rootPath, comic.Title, volume.Title);
     Directory.CreateDirectory(path);
 }
コード例 #4
0
 private string BuildPath(Comic comic, Volume volume, Page page)
 {
     return string.Format(PATH_TEMPLATE, _rootPath, comic.Title, volume.Title, page.Number, page.ImageType);
 }