예제 #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
 public BookEntry(Manga m)
 {
     ParentManga = m;
 }
예제 #3
0
 public Book(Manga m)
 {
     ParentManga = m;
 }
예제 #4
0
        internal void InvokeReadManga(Manga m)
        {
            MetroTabItem mti = new MetroTabItem();
            mti.IsClosable = true;
            mti.Header = m.MangaName;
            mti.Content = new MangaInfoControl(m);

            metroTabControl1.Items.Add(mti);

            metroTabControl1.SelectedItem = mti;
        }
예제 #5
0
 private void ImportTile_Click(object sender, RoutedEventArgs e)
 {
     this.Move = (bool)cbMv.IsChecked;
     var task = Task.Factory.StartNew(() =>
                {
                    if (!System.IO.Directory.Exists(Global.CollectionDir + "Imports"))
                        System.IO.Directory.CreateDirectory(Global.CollectionDir + "Imports");
                    Dispatcher.Invoke(new EmptyDelegate(() =>
                    {
                        this.pbar.Value = 0;
                    }));
                    int i = 0;
                    int tot = ImportList.Items.Count;
                    while (ImportList.Items.Count > 0)
                    {
                        string name = string.Empty;
                        string path = ImportList.Items[i].ToString();
                        name = (new FileInfo(System.IO.Path.GetDirectoryName(path))).Directory.Name;
                        if (!System.IO.Directory.Exists(Global.CollectionDir + "Imports\\" + name))
                        {
                            System.IO.Directory.CreateDirectory(Global.CollectionDir + "Imports\\" + name);
                            Manga manga = new Manga();
                            manga.Author = "Unknown";
                            manga.Description = "Unknown";
                            manga.MangaName = name;
                            if (!Move)
                            {
                                Book b = new Book(manga);
                                b.Name = name;
                                b.Filename = name + ".bin";
                                foreach (var file in System.IO.Directory.EnumerateFiles(path))
                                {
                                    File.Copy(file, Global.CollectionDir + "Imports\\" + name + "\\" + System.IO.Path.GetFileName(file));
                                    b.PageLocalUrls.Add(Global.CollectionDir + "Imports\\" + name + "\\" + System.IO.Path.GetFileName(file));
                                }
                                using (var fs = new FileStream(Global.CollectionDir + "Imports\\" + name + "\\" + b.Filename, FileMode.Open))
                                {
                                    BinaryFormatter bf = new BinaryFormatter();
                                    bf.Serialize(fs, b);
                                    fs.Close();
                                }
                            }
                        }
                        Dispatcher.Invoke(new UpdateDelegate((Cur, Tot) =>
                        {
                            int pre = ((Cur * 100) / Tot);
                            this.pbar.Value = pre;
                        }), i, tot);
                    }
                    Dispatcher.Invoke(new EmptyDelegate(() =>
                    {
                        this.pbar.Value = 0;
                    }));
                });
 }
예제 #6
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;
        }
예제 #7
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;
        }
예제 #8
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();
                    });
        }
예제 #9
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;
        }