Example #1
0
        static void getIssues(List <string> pubids)
        {
            using (var client = new WebClient())
            {
                foreach (var pubid in pubids)
                {
                    string       pubinfojson = client.DownloadString("https://ingress.pressreader.com/services/IssueInfo/GetIssueInfo?accessToken=" + accesstoken + "&issue=" + pubid);
                    PubInfo.Root pubinfo     = JsonConvert.DeserializeObject <PubInfo.Root>(pubinfojson);

                    string        pagekeysjson = client.DownloadString("https://ingress.pressreader.com/services/IssueInfo/GetPageKeys?accessToken=" + accesstoken + "&issue=" + pubid + "&pageNumber=0");
                    PageKeys.Root pagekeys     = JsonConvert.DeserializeObject <PageKeys.Root>(pagekeysjson);

                    string title = MakeValidFileName(pubinfo.Newspaper.Name);
                    Directory.CreateDirectory(title);
                    string pubdate = pubinfo.Issue.IssueDate.ToString(@"yyyy-MM-dd");

                    int height = 0;
                    int size   = 0;
                    //int scale = 0;
                    bool usescale = true;
                    try
                    {
                        MemoryStream         stream = new MemoryStream(client.DownloadData("https://i.prcdn.co/img?file=" + pubid + "&page=1"));
                        System.Drawing.Image image  = System.Drawing.Image.FromStream(stream, false, false);
                        height   = image.Height;
                        size     = image.Width;
                        size     = (int)Math.Floor((double)Math.Min(100 * pubinfo.MagnifierPageSizes[pubinfo.MagnifierPageSizes.Count - 1].W / size, 100 * pubinfo.MagnifierPageSizes[pubinfo.MagnifierPageSizes.Count - 1].H / height));
                        usescale = true;
                    }
                    catch (Exception)
                    {
                        size     = pubinfo.MagnifierPageSizes[pubinfo.MagnifierPageSizes.Count - 1].W;
                        usescale = false;
                    }

                    if (type == "pdf")
                    {
                        getPdf(pubid, title, size, pubdate, pagekeys, usescale);
                    }
                    else if (type == "img")
                    {
                        getImg(pubid, title, size, pubdate, pagekeys, usescale);
                    }
                }
            }
        }
Example #2
0
        public static void getImg(string pubid, string title, int width, string pubdate, PageKeys.Root pagekeys, bool usescale)
        {
            foreach (var page in pagekeys.PageKeys)
            {
                using (var client = new WebClient())
                {
                    string filename = title + " - " + pubdate + " - " + page.PageNumber.ToString("000") + ".png";

                    if (!File.Exists(title + "\\" + filename))
                    {
                        Console.WriteLine("=============================================================================");
                        Console.WriteLine("Fetching: " + filename);
                        bool gotpage = false;

                        if (usescale == true)
                        {
                            while (gotpage == false)
                            {
                                try
                                {
                                    client.DownloadFile("https://i.prcdn.co/img?file=" + pubid + "&page=" + page.PageNumber + "&scale=" + width + "&ticket=" + HttpUtility.UrlEncode(page.Key), title + "\\" + filename);
                                    gotpage = true;
                                }
                                catch (Exception)
                                {
                                    gotpage = false;
                                }
                            }
                        }
                        else
                        {
                            while (gotpage == false)
                            {
                                try
                                {
                                    client.DownloadFile("https://i.prcdn.co/img?file=" + pubid + "&page=" + page.PageNumber + "&width=" + width + "&ticket=" + HttpUtility.UrlEncode(page.Key), title + "\\" + filename);
                                    gotpage = true;
                                }
                                catch (Exception)
                                {
                                    gotpage = false;
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine(filename + " Already Exists, Skipping.");
                    }
                }
            }
        }
Example #3
0
        public static void getPdf(string pubid, string title, int width, string pubdate, PageKeys.Root pagekeys, bool usescale)
        {
            string filename = title + " - " + pubdate + ".pdf";

            if (!File.Exists(title + "\\" + filename))
            {
                PdfDocument pdfDoc = new PdfDocument(new PdfWriter(title + "\\" + filename));

                Console.WriteLine("=============================================================================");
                Console.WriteLine("Fetching: " + filename);

                foreach (var page in pagekeys.PageKeys)
                {
                    using (var client = new WebClient())
                    {
                        bool gotpage = false;
                        Console.Write("\rPage: " + (page.PageNumber));
                        byte[] data = null;
                        if (usescale == true)
                        {
                            while (gotpage == false)
                            {
                                try
                                {
                                    data    = client.DownloadData("https://i.prcdn.co/img?file=" + pubid + "&page=" + page.PageNumber + "&scale=" + width + "&ticket=" + HttpUtility.UrlEncode(page.Key));
                                    gotpage = true;
                                }
                                catch (Exception)
                                {
                                    gotpage = false;
                                }
                            }
                        }
                        else
                        {
                            while (gotpage == false)
                            {
                                try
                                {
                                    data    = client.DownloadData("https://i.prcdn.co/img?file=" + pubid + "&page=" + page.PageNumber + "&width=" + width + "&ticket=" + HttpUtility.UrlEncode(page.Key));
                                    gotpage = true;
                                }
                                catch (Exception)
                                {
                                    gotpage = false;
                                }
                            }
                        }

                        Image    image = new Image(ImageDataFactory.Create(data));
                        Document doc   = new Document(pdfDoc, new PageSize(image.GetImageWidth(), image.GetImageHeight()));

                        image = new Image(ImageDataFactory.Create(data));
                        pdfDoc.AddNewPage(new PageSize(image.GetImageWidth(), image.GetImageHeight()));
                        image.SetFixedPosition(page.PageNumber, 0, 0);
                        doc.Add(image);
                    }
                }
                pdfDoc.Close();
            }
            else
            {
                Console.WriteLine(title + " - " + title + " Already Exists, Skipping.");
            }
        }