Пример #1
0
 public QueueItem(BookEntry Book, Manga manga)
 {
     this.Book = Book;
        this.Manga = manga;
        this.Name = this.Book.Name;
        this.Status = QueueStatus.Queued;
        this.Date = DateTime.Now;
 }
Пример #2
0
        internal void AddToQueue(BookEntry bookEntry, MangaEplision.Base.Manga manga)
        {
            if (DlQueue != null)
            {
                QueueItem qi = new QueueItem(bookEntry, manga);
                if (!DlQueue.Contains(qi) && !Global.GetBookExist(qi.Manga, qi.Book))
                {
                    DlQueue.Add(qi);
                    DlQueueList.ItemsSource = DlQueue;
                    DlQueueList.Items.Refresh();

                    if (isQueueRunning == false)
                        QueueStatuslbl.Content = string.Format("There are currently {0} items in your queue.", DlQueue.Count);
                }
            }
        }
Пример #3
0
        public Book GetBook(Manga mag, BookEntry chapter, Action<int,int> progressHandler = null)
        {
            Book b = new Book(mag);
            b.Name = chapter.Name;
            b.ReleaseDate = chapter.ReleaseDate;
            b.Pages = new System.Collections.ObjectModel.Collection<object>();
            b.PageOnlineUrls = new System.Collections.ObjectModel.Collection<Uri>();

            string url = chapter.Url; //first page.
            string firstpagehtml = GetHtml(url);

            int maxpages = 0;
            Match pgcount = Regex.Match(firstpagehtml, "<div id=\"selectpage\">.+?</div>", RegexOptions.Singleline | RegexOptions.Compiled);
            string pgcountstr = Regex.Replace(pgcount.Value, "<option.+?>.+?</option>", "");
            pgcountstr = Regex.Replace(pgcountstr, "<.+?>", "");
            pgcountstr = pgcountstr.Replace("of", "").Replace(" ", "").Replace("\n", "");
            maxpages = int.Parse(pgcountstr);

            Match firstimg = Regex.Match(firstpagehtml, "<img id=\"img\".+?>", RegexOptions.Singleline | RegexOptions.Compiled);
            string firstimgurl = Regex.Match(firstimg.Value, "src=\".+?\"", RegexOptions.Singleline | RegexOptions.Compiled).Value;
            firstimgurl = Regex.Replace(firstimgurl, "(src=\"|\")", "");
            System.Windows.Application.Current.Dispatcher.Invoke(new EmptyDelegate(delegate()
            {
                var uri = new Uri(firstimgurl);
                b.PageOnlineUrls.Add(uri);
                /*
                using (var ms = new MemoryStream())
                {

                    if (uri.LocalPath.EndsWith(".png"))
                    {
                        PngBitmapEncoder png = new PngBitmapEncoder();
                        png.Frames.Add(BitmapFrame.Create(uri));
                        png.Save(ms);
                    }
                    else if (uri.LocalPath.EndsWith(".jpg"))
                    {
                        JpegBitmapEncoder jpg = new JpegBitmapEncoder();
                        jpg.Frames.Add(BitmapFrame.Create(uri));
                        jpg.Save(ms);
                    }
                    else if (uri.LocalPath.EndsWith(".bmp"))
                    {
                        BmpBitmapEncoder bmp = new BmpBitmapEncoder();
                        bmp.Frames.Add(BitmapFrame.Create(uri));
                        bmp.Save(ms);
                    }
                    ms.Flush();
                    b.Pages.Add(ms.ToArray());
                } */
            }), null);

            string url_1 = null;
            string url_2 = null;
            if (url.EndsWith(".html"))
            {
                //old style urls.
                url_1 = url.Substring(0, url.NthIndexOf("-", 2) + 1);
                url_2 = url.Substring(url.NthIndexOf("/", 4));
            }
            else
            {
                url_1 = url + "/";
                url_2 = "";
            }
            for (int i = 2; i < maxpages + 1; i++)
            {
                if (progressHandler != null)
                    progressHandler(i, maxpages);

                string purl = url_1 + i + url_2;
                string html = GetHtml(purl);

                Match img = Regex.Match(html, "<img id=\"img\".+?>", RegexOptions.Singleline |  RegexOptions.Compiled);
                string imgurl = Regex.Match(img.Value, "src=\".+?\"", RegexOptions.Singleline | RegexOptions.Compiled).Value;
                imgurl = Regex.Replace(imgurl, "(src=\"|\")", "");
                System.Windows.Application.Current.Dispatcher.Invoke(new EmptyDelegate(delegate()
                {
                    var uri = new Uri(imgurl);
                    b.PageOnlineUrls.Add(uri);
                    /*
                    using (var ms = new MemoryStream())
                    {

                        if (uri.LocalPath.EndsWith(".png"))
                        {
                            PngBitmapEncoder png = new PngBitmapEncoder();
                            png.Frames.Add(BitmapFrame.Create(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default));
                            png.Save(ms);
                        }
                        else if (uri.LocalPath.EndsWith(".jpg"))
                        {
                            JpegBitmapEncoder jpg = new JpegBitmapEncoder();
                            jpg.Frames.Add(BitmapFrame.Create(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default));
                            jpg.Save(ms);
                        }
                        else if (uri.LocalPath.EndsWith(".bmp"))
                        {
                            BmpBitmapEncoder bmp = new BmpBitmapEncoder();
                            bmp.Frames.Add(BitmapFrame.Create(uri, BitmapCreateOptions.PreservePixelFormat,BitmapCacheOption.Default));
                            bmp.Save(ms);
                        }
                        ms.Flush();
                        b.Pages.Add(ms.ToArray());
                    }
                     * */
                }), null);

                System.Threading.Thread.Sleep(50); //Decreased from 100 to 50, better download time,   // //Prevent simulating a DDOS.
            }

            return b;
        }
Пример #4
0
        public BookEntry[] GetNewReleasesOfToday(int amount = 5)
        {
            var html = GetHtml("http://mangareader.net/");

            var manga_updates_area = Regex.Match(html, "<div id=\"latestchapters\">.+?<h3>Yesterday's Manga</h3>", RegexOptions.Singleline | RegexOptions.Compiled);
            var matchedmangas = Regex.Matches(manga_updates_area.Value, "<td>.+?</td>", RegexOptions.Singleline | RegexOptions.Compiled);

            List<BookEntry> entries = new List<BookEntry>();

            int i = 0;
            foreach (Match match in matchedmangas)
            {
                if (i == amount)
                    break;

                BookEntry be = null;

                var manganame = Regex.Match(match.Value,
                    "<a class=\"chapter\".+?>.+?</a>",
                    RegexOptions.Singleline | RegexOptions.Compiled);
                manganame = Regex.Matches(manganame.Value, "\".+?\"", RegexOptions.Compiled | RegexOptions.Singleline)[1];

                var manganamestr = manganame.Value;
                manganamestr = (manganamestr.StartsWith("\"") ? manganamestr.Substring(1) : manganamestr);
                manganamestr = (manganamestr.EndsWith("\"") ? manganamestr.Remove(manganamestr.Length -1) : manganamestr);

                var mangaurl = "http://mangareader.net" + manganamestr;
                be = new BookEntry(GetMangaInfoByUrl(mangaurl)); //Should implement a cached version for Global

                var chapter = Regex.Match(match.Value,
                    "<a class=\"chaptersrec\".+?>.+?</a>",
                    RegexOptions.Singleline | RegexOptions.Compiled);

                var chpname = Regex.Replace(
                    Regex.Match(chapter.Value, ">.+?<", RegexOptions.Singleline | RegexOptions.Compiled).Value,
                    "(>|<)",
                "");
                be.Name = chpname;

                var chpurl = Regex.Matches(match.Value, "\".+?\"", RegexOptions.Singleline | RegexOptions.Compiled)[1].Value;
                chpurl = (chpurl.StartsWith("\"") ? chpurl.Substring(1) : chpurl);
                chpurl = (chpurl.EndsWith("\"") ? chpurl.Remove(chpurl.Length - 1) : chpurl);
                be.Url = "http://mangareader.net" + chpurl;

                entries.Add(be);
                i++;
            }

            return entries.ToArray();
        }
Пример #5
0
        public Manga GetMangaInfoByUrl(string url)
        {
            Manga m = new Manga();
            HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(url);
            string html = "";
            using (var sr = new StreamReader(hwr.GetResponse().GetResponseStream()))
            {
                html = sr.ReadToEnd();
                sr.Close();
            }

            string summuaryarea = Regex.Match(html, "<div id=\"readmangasum\">.+?</div>", RegexOptions.Singleline | RegexOptions.Compiled).Value;
            summuaryarea = Regex.Match(summuaryarea, "<p>.+?</p>", RegexOptions.Singleline | RegexOptions.Compiled).Value;
            string sum = Regex.Replace(summuaryarea, "<(/p|p)>", "");

            m.Description = sum;

            string imagearea = Regex.Match(html, "<div id=\"mangaimg\">.+?</div>", RegexOptions.Singleline | RegexOptions.Compiled).Value;
            imagearea = Regex.Match(imagearea, "src=\".+?\"", RegexOptions.Singleline | RegexOptions.Compiled).Value;
            string img = Regex.Replace(imagearea, "(src=\"|\")", "");

            m.IsBookImageCached = false;
            m.BookImageUrl = img;

            var name = Regex.Match(html, "<h2 class=\"aname\">.+?</h2>", RegexOptions.Singleline | RegexOptions.Compiled).Value;
            name = Regex.Replace(name,"<.+?>","");
            m.MangaName = name;

            string chaptersarea = Regex.Match(html, "<div id=\"chapterlist\">.+?</div>.+?</table>", RegexOptions.Singleline | RegexOptions.Compiled).Value;

            foreach (Match chp in Regex.Matches(chaptersarea, "<tr>.+?</tr>", RegexOptions.Singleline | RegexOptions.Compiled))
            {
                MatchCollection split = Regex.Matches(chp.Value, "<td>.+?</td>", RegexOptions.Singleline | RegexOptions.Compiled);
                BookEntry be = new BookEntry(m);
                string datestr = split[1].Value.Replace("</td>", "").Replace("<td>", "");
                DateTime tmp;
                be.ReleaseDate = (DateTime.TryParse(datestr, out tmp)) ? DateTime.Parse(datestr) : DateTime.Now;
                string chpurl = "";
                chpurl = Regex.Match(split[0].Value, "href=\".+?\"", RegexOptions.Singleline | RegexOptions.Compiled).Value;
                chpurl = Regex.Replace(chpurl, "(href=\"|\")", "");
                chpurl = "http://www.mangareader.net" + chpurl;
                be.Url = chpurl;

                string nm = Regex.Replace(split[0].Value.Replace("</td>", "").Replace("<td>", ""), "<.+?>", "");
                //nm = nm.Substring(3);
                be.Name = nm.Replace("\n", "");
                be.ID = m.Books.Count + 1;
                m.Books.Add(be);
            }

            string authorarea = Regex.Match(html, "<td class=\"propertytitle\">Author:.+?</tr>", RegexOptions.Singleline | RegexOptions.Compiled).Value;
            MatchCollection authorsplt = Regex.Matches(authorarea, "<td>.+?</td>", RegexOptions.Singleline | RegexOptions.Compiled);
            try
            {
                m.Author = Regex.Replace(authorsplt[0].Value, "<.+?>", "");
            }
            catch (Exception) { m.Author = "Unknown"; }

            m.FetchImage();

            return m;
        }
Пример #6
0
        public static void DownloadMangaBook(Manga manga, BookEntry book, Action<Book> act = null, Action<int,int> Pcount = null)
        {
            Task.Factory.StartNew<Book>(() =>
                {
                    try
                    {
                        Book bk = Global.MangaSource.GetBook(manga, book, Pcount);
                        bk.PageLocalUrls = new System.Collections.ObjectModel.Collection<string>();

                        BinaryFormatter bf = new BinaryFormatter();
                        string mangadir = CollectionDir + bk.ParentManga.MangaName;
                        string bookdir = mangadir + "\\" + bk.Name.CommonReplace() + "\\";

                        if (!Directory.Exists(mangadir))
                            Directory.CreateDirectory(mangadir);
                        if (!Directory.Exists(bookdir))
                            Directory.CreateDirectory(bookdir);

                        using (var fs = new FileStream(bookdir + bk.Name.CommonReplace() + ".bin", FileMode.Create))
                        {
                            int i = 1;
                            using (var wc = new WebClient())
                            {
                                foreach (Uri url in bk.PageOnlineUrls)
                                {
                                    var file = bookdir + "page" + i + url.LocalPath.Substring(url.LocalPath.LastIndexOf("."));
                                    wc.DownloadFile(url, file);
                                    bk.PageLocalUrls.Add(file);
                                    i++;
                                }
                            }

                            bf.Serialize(fs, bk);

                            fs.Close();
                        }
                        new DirectoryInfo(mangadir).Attributes = FileAttributes.ReadOnly;

                        return bk;
                    }
                    catch (Exception ex)
                    {
            #if DEBUG
                        System.Diagnostics.Debug.Write(ex);
            #endif
                    }
                    return null;
                }).ContinueWith((tsk) =>
                    {
                        if (act != null)
                            act(tsk.Result);
                        tsk.Dispose();
                    });
        }
Пример #7
0
        public static bool GetBookExist(Manga manga, BookEntry book)
        {
            var firstcheck = File.Exists(CollectionDir + "\\" + manga.MangaName + "\\" + book.Name.CommonReplace() + "\\" + book.Name.CommonReplace() + ".bin");

            if (firstcheck)
                return true;
            else
            {
                foreach (var b in CollectionBooks)
                    if (b.Name == book.Name)
                        return true;
            }

            return false;
        }