Example #1
0
        // GET: Manga
        public ActionResult Index(int id)
        {
            var dao = new MangaDao();

            var mangaId = id.ToString();

            if (String.IsNullOrEmpty((string)Session[mangaId]))
            {
                dao.AddView(id);
                Session[mangaId] = "Đã xem";
            }
            var manga = db.Mangas.Where(i => i.mId == id).FirstOrDefault();
            var item  = new MangaDetail();

            item.mId = manga.mId;
            var chapter = db.Chapters.OrderByDescending(i => i.cId)
                          .Where(i => i.mId == manga.mId).FirstOrDefault();

            item.displayName  = chapter == null ? manga.mName : chapter.cName;
            item.createdBy    = db.Users.Where(i => i.uId == manga.CreatedBy).FirstOrDefault().displayName;
            item.updatedAt    = manga.updatedAt;
            item.chapters     = manga.mChapter;
            item.totalComment = manga.totalComment;
            item.image        = manga.image;
            item.description  = manga.mDescription;
            item.author       = manga.mAuthor;
            item.totalView    = manga.totalView;
            var categories = db.Categories.Where(i => i.mId == item.mId).Join(db.CategoryDetails, d => d.categoryId, f => f.categoryId, (d, f) => new { Category = d, CategoryDetail = f });

            item.listCategories = categories.Select(i => new CategoryModel {
                id = i.Category.categoryId, displayName = i.CategoryDetail.categoryName
            }).ToList();
            return(View(item));
        }
Example #2
0
        public ActionResult Sort(int categoryId, int page = 1)
        {
            var listManga = new List <MangaDetail>();
            var ids       = db.Categories.Where(i => i.categoryId == categoryId).Select(i => i.mId).ToList();
            var mangas    = db.Mangas.Where(i => i.status == (int)Constants.STATUS.Published && ids.Contains(i.mId)).OrderByDescending(i => i.updatedAt).Skip((page - 1) * Constants.PAGE_SIZE).Take(Constants.PAGE_SIZE).ToList();

            foreach (var manga in mangas)
            {
                var item = new MangaDetail();
                item.mId = manga.mId;
                var chapter = db.Chapters.OrderByDescending(i => i.cId)
                              .Where(i => i.mId == manga.mId).FirstOrDefault();
                item.displayName  = chapter == null ? manga.mName : chapter.cName;
                item.image        = manga.image;
                item.createdBy    = db.Users.Where(i => i.uId == manga.CreatedBy).FirstOrDefault().displayName;
                item.updatedAt    = manga.updatedAt;
                item.chapters     = manga.mChapter;
                item.totalComment = manga.totalComment;
                item.image        = manga.image;
                item.description  = manga.mDescription;
                item.author       = manga.mAuthor;
                item.totalView    = manga.totalView;
                item.status       = manga.status;
                var categories = db.Categories.Where(i => i.mId == item.mId).Join(db.CategoryDetails, d => d.categoryId, f => f.categoryId, (d, f) => new { Category = d, CategoryDetail = f });
                item.listCategories = categories.Select(i => new CategoryModel {
                    id = i.Category.categoryId, displayName = i.CategoryDetail.categoryName
                }).ToList();
                listManga.Add(item);
            }
            return(View("Index", new PageListModel {
                listManga = listManga, page = page, total = db.Mangas.Count(), pageSize = Constants.PAGE_SIZE
            }));
        }
Example #3
0
        public MangaDetail GetFullInfoManga(MangaDetail manga)
        {
            var item = db.Mangas.Where(i => i.mId == manga.mId).FirstOrDefault();

            manga.displayName = item.mName;
            return(manga);
        }
Example #4
0
        public async ValueTask <MangaDetail> GetManga(string url)
        {
            var page = await Client.GetStringAsync(url);

            var idMatch = MangaIdRe.Match(page);

            if (!idMatch.Success)
            {
                return(null);
            }
            var mangaId = idMatch.Groups[1].Value;

            List <string> aliases = null;
            var           htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(page);
            var aliasesNode = htmlDoc.DocumentNode.SelectSingleNode(
                "/html/body/div[4]/div[3]/div/div[1]/div[2]/div/div[4]/table/tbody/tr[1]/td");

            if (!string.IsNullOrEmpty(aliasesNode?.InnerText?.Trim()))
            {
                aliases = aliasesNode.InnerText.Trim().Split(',').ToList();
            }
            page = await Client.GetStringAsync(string.Format(MangaApiBase, mangaId));

            var mangaDetail = JsonConvert.DeserializeObject <MangaDetail_>(page);
            var result      = new MangaDetail()
            {
                Cover       = mangaDetail.cover,
                Id          = mangaId,
                Name        = mangaDetail.title,
                Description = mangaDetail.description,
                Tags        = new List <TagDetail>(),
                Aliases     = aliases,
                Url         = url,
                Chapters    = mangaDetail.chapters.SelectMany(chapters => chapters.data.Select(chapter =>
                                                                                               new ChapterDetail()
                {
                    Id   = chapter.chapter_id.ToString(),
                    Name = chapter.chapter_title,
                    Type = chapters.title,
                    Url  = string.Format(ChapterApiBase, mangaId, chapter.chapter_id)
                })).Reverse().ToList()
            };

            result.Tags.AddRange(mangaDetail.authors.Select(author => new TagDetail()
            {
                Name = author.tag_name, Type = TagTypeAuthorName
            }));
            result.Tags.AddRange(mangaDetail.types.Select(type => new TagDetail()
            {
                Name = type.tag_name, Type = TagTypeContentName
            }));
            result.Tags.AddRange(mangaDetail.status.Select(status => new TagDetail()
            {
                Name = status.tag_name, Type = TagTypeStatusName
            }));
            return(result);
        }
Example #5
0
        public ActionResult Create()
        {
            var manga          = new MangaDetail();
            var listCategories = db.CategoryDetails.Select(i => new CategoryModel {
                id = i.categoryId, displayName = i.categoryName
            }).ToList();

            manga.listCategories = listCategories;
            return(View(manga));
        }
Example #6
0
        public ActionResult Manga(int id = 0)
        {
            var manga = db.Mangas.Where(i => i.mId == id).FirstOrDefault();

            if (manga == null)
            {
                return(RedirectToAction("UploadedManga"));
            }
            var user = (UserLogin)Session[Constants.USER_SESSION];

            if (user != null)
            {
                if (user.UserName == "admin" || user.UserId == manga.CreatedBy)
                {
                    var item           = new MangaDetail();
                    var listCategories = db.CategoryDetails.Select(i => new CategoryModel {
                        id = i.categoryId, displayName = i.categoryName
                    }).ToList();
                    item.listCategories = listCategories;
                    item.mId            = manga.mId;
                    var chapter = db.Chapters.OrderByDescending(i => i.cId)
                                  .Where(i => i.mId == manga.mId).FirstOrDefault();
                    item.displayName = manga.mName;
                    item.createdBy   = db.Users.Where(i => i.uId == manga.CreatedBy).FirstOrDefault().displayName;
                    item.updatedAt   = manga.updatedAt;
                    item.chapters    = manga.mChapter;
                    var catIds = db.Categories.Where(i => i.mId == id).Select(i => i.categoryId).ToList();
                    item.categories   = catIds;
                    item.totalComment = manga.totalComment;
                    item.image        = manga.image;
                    item.description  = manga.mDescription;
                    item.author       = manga.mAuthor;
                    item.totalView    = manga.totalView;
                    return(View(item));
                }
                else
                {
                    return(View("Error"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
        }
Example #7
0
        public ActionResult Create(MangaDetail item)
        {
            var path     = "";
            var fileName = "";
            var user     = (UserLogin)Session[Constants.USER_SESSION];

            if (item.imgFile != null)
            {
                fileName = item.imgFile.FileName;
                if (item.imgFile.ContentLength > 0)
                {
                    var manga = new Manga();
                    manga.mName        = item.displayName;
                    manga.publishedAt  = DateTime.Now;
                    manga.updatedAt    = DateTime.Now;
                    manga.mAuthor      = item.author;
                    manga.CreatedBy    = user.UserId;
                    manga.mDescription = item.description;
                    MangaDao dao = new MangaDao();
                    int      id  = dao.AddManga(manga);
                    AddCategory(id, item.categories);

                    if (Path.GetExtension(fileName).ToLower() == ".jpg" ||
                        Path.GetExtension(fileName).ToLower() == ".png" ||
                        Path.GetExtension(fileName).ToLower() == ".gif" ||
                        Path.GetExtension(fileName).ToLower() == ".jpeg")
                    {
                        string currentDir = Path.Combine(HttpRuntime.AppDomainAppPath, "Image");
                        if (!Directory.Exists(Path.Combine(currentDir, id.ToString())))
                        {
                            Directory.CreateDirectory(Path.Combine(currentDir, id.ToString()));
                        }
                        string dir = Path.Combine(currentDir, id.ToString());
                        path = Path.Combine(dir, fileName);
                        item.imgFile.SaveAs(path);
                        var _manga = db.Mangas.Where(i => i.mId == id).FirstOrDefault();
                        _manga.image = "/Image/" + manga.mId.ToString() + "/" + item.imgFile.FileName;
                        db.SaveChanges();
                    }
                }
            }
            return(RedirectToAction("Index", "Manage"));
        }
Example #8
0
        public ActionResult Manga(MangaDetail mangaDetail)
        {
            var manga = db.Mangas.Where(i => i.mId == mangaDetail.mId).FirstOrDefault();

            if (manga != null)
            {
                var path     = "";
                var fileName = "";
                var user     = (UserLogin)Session[Constants.USER_SESSION];
                if (mangaDetail.imgFile != null)
                {
                    fileName = mangaDetail.imgFile.FileName;
                    if (mangaDetail.imgFile.ContentLength > 0)
                    {
                        if (Path.GetExtension(fileName).ToLower() == ".jpg" ||
                            Path.GetExtension(fileName).ToLower() == ".png" ||
                            Path.GetExtension(fileName).ToLower() == ".gif" ||
                            Path.GetExtension(fileName).ToLower() == ".jpeg")
                        {
                            string currentDir = Path.Combine(HttpRuntime.AppDomainAppPath, "Image");
                            if (!Directory.Exists(Path.Combine(currentDir, manga.mId.ToString())))
                            {
                                Directory.CreateDirectory(Path.Combine(currentDir, manga.mId.ToString()));
                            }
                            //var s = "/Images" + manga.mId.ToString();
                            string dir = Path.Combine(currentDir, manga.mId.ToString());
                            path = Path.Combine(dir, fileName);
                            mangaDetail.imgFile.SaveAs(path);
                        }
                        manga.image = "/Image/" + manga.mId.ToString() + "/" + mangaDetail.imgFile.FileName;
                    }
                }
                manga.mName        = mangaDetail.displayName;
                manga.updatedAt    = DateTime.Now;
                manga.mAuthor      = mangaDetail.author;
                manga.mDescription = mangaDetail.description;
                AddCategory(mangaDetail.mId, mangaDetail.categories);
                db.SaveChanges();
            }
            return(RedirectToAction("UploadedManga"));
        }
Example #9
0
        public async ValueTask ScrapeMetadata(MangaDetail context)
        {
            var html = await Client.GetStringAsync(string.Format(QueryBase, context.Name));

            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(html);
            var gallery = htmlDoc.DocumentNode.SelectSingleNode("//div[contains(@class, 'gallery')]");
            var href    = gallery?.FirstChild.GetAttributeValue("href", null);

            if (href == null)
            {
                return;
            }
            var mangaUrl = Host + href;

            html = await Client.GetStringAsync(mangaUrl);

            htmlDoc.LoadHtml(html);
            var titleNode   = htmlDoc.DocumentNode.SelectSingleNode("//h1[contains(@class, 'title')]");
            var jpTitleNode = htmlDoc.DocumentNode.SelectSingleNode("//h2[contains(@class, 'title')]");

            context.Aliases ??= new List <string>();
            if (jpTitleNode == null)
            {
                context.Name = titleNode.InnerText;
            }
            else
            {
                context.Name = jpTitleNode.InnerText;
                context.Aliases.Add(titleNode.InnerText);
            }
            context.Tags = new List <TagDetail>();
            foreach (var tagNode in htmlDoc.DocumentNode.SelectNodes("//div[contains(@class, 'tag-container field-name')]"))
            {
                string tagType;
                switch (tagNode.GetDirectInnerText().Trim())
                {
                case "Parodies:":
                    tagType = ParodiesTagTypeName;
                    break;

                case "Characters:":
                    tagType = CharactersTagTypeName;
                    break;

                case "Tags:":
                    tagType = TagsTagTypeName;
                    break;

                case "Artists:":
                    tagType = ArtistsTagTypeName;
                    break;

                case "Groups:":
                    tagType = GroupsTagTypeName;
                    break;

                case "Languages:":
                    tagType = LanguagesTagTypeName;
                    break;

                case "Categories:":
                    tagType = CategoriesTagTypeName;
                    break;

                default: continue;
                }

                context.Tags.AddRange(tagNode.Descendants("span").Where(it => it.GetAttributeValue("class", null) == "name")
                                      .Select(tag => new TagDetail()
                {
                    Name = tag.InnerText, Type = tagType
                }));
            }
        }
Example #10
0
        public async ValueTask Execute(ScanMangaTask scanMangaTask)
        {
            try
            {
                if (scanMangaTask.MangaPath.IsNewItem)
                {
                    scanMangaTask.Update(TaskStatus.Executing);
                    var manga = await FileTreeNodeToMangaConverter.CreateManga(scanMangaTask.MangaPath);

                    FileTreeNode coverPath = null;
                    if (manga.Cover == null)
                    {
                        coverPath =
                            LibraryManager.GenerateThumbnail(manga.Chapters.First().Images.First().Path);
                        manga.Cover   = FileTreeNodeToMangaConverter.CreateImage(coverPath);
                        manga.CoverId = manga.Cover.ObjectId;
                    }

                    if (scanMangaTask.Scraper != null)
                    {
                        var context = new MangaDetail()
                        {
                            Name = manga.Title
                        };
                        await scanMangaTask.Scraper.ScrapeMetadata(context);

                        manga = await FileTreeNodeToMangaConverter.UpdateManga(manga, context);
                    }

                    manga.Tags = await MangaManager.Insert(manga.Tags);

                    var success = await MangaManager.Insert(manga);

                    if (!success)
                    {
                        Logger.Info($"Update {manga.Title} fail");
                        if (coverPath != null)
                        {
                        }
                        scanMangaTask.Update(TaskStatus.Fail);
                    }
                    else
                    {
                        LibraryManager.StoreFileTree(scanMangaTask.MangaPath);
                        if (coverPath != null)
                        {
                            LibraryManager.StoreFileTree(coverPath);
                        }
                        scanMangaTask.Update(TaskStatus.Success);
                    }
                }
                else
                {
                    var manga = await FileTreeNodeToMangaConverter.UpdateManga(scanMangaTask.MangaPath);

                    manga.Tags = await MangaManager.Insert(manga.Tags);

                    var success = await MangaManager.Update(manga, true);

                    if (!success)
                    {
                        Logger.Info($"Update {manga.Title} fail");
                        scanMangaTask.Update(TaskStatus.Fail);
                    }
                    else
                    {
                        LibraryManager.StoreFileTree(scanMangaTask.MangaPath);
                        scanMangaTask.Update(TaskStatus.Success);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Warn(e);
                scanMangaTask.Update(TaskStatus.Fail);
            }
        }