public void LoadChaptersFromADL(ref ZipArchive zip) { List <MangaChapter> chapterlist = new List <MangaChapter>(); string[] chapters = zip.GetEntriesUnderDirectoryToStandardString("Chapters/"); int id = 0; foreach (string chp in chapters) { MangaChapter chap = new MangaChapter(); chap.ChapterName = chp; /* using (StreamReader sr = new StreamReader(zip.GetEntry("Chapters/" + chp).Open())) * { * string b; * List<Epub.Image> images = new List<Epub.Image>(); * while((b = sr.ReadLine()) != null) * images.Add(Epub.Image.GenerateImageFromByte(Convert.FromBase64String(b), id++.ToString())); * * chap.Images = images.ToArray(); * }*/ chap.existing = true; chapterlist.Add(chap); } Chapters = chapterlist.ToArray(); }
public IActionResult Chapter(int id) { MangaChapter chapter = _mangaRepository.GetChapter(id); if (chapter == null) { return(View("404Error")); } var orderedChList = _mangaRepository.GetAllChapters(chapter.MangaId).OrderBy(s => s.ChapterNo); var current = orderedChList.IndexOf(chapter); Manga manga = _mangaRepository.GetManga(chapter.MangaId); var model = new ChapterViewModel() { Manga = manga, Id = chapter.Id, ChNo = chapter.ChapterNo, Title = chapter.Title, PrevCh = orderedChList.ElementAtOrDefault(current - 1), NextCh = orderedChList.ElementAtOrDefault(current + 1), Contents = _hostingEnvironment.WebRootFileProvider.GetDirectoryContents("/Mangas/" + manga.Id + "/" + chapter.ChapterNo) }; return(View(model)); }
public override Image[] GetImages(ref MangaChapter aski, ref Models.Manga manga, ref ArchiveManager arc) { MovePage(aski.linkTo); pageEnumerator.Reset(); Dictionary <string, LinkedList <HtmlNode> > baseInfo = pageEnumerator.GetElementsByClassNames(new string[] { "container-chapter-reader" }); IEnumerator <HtmlNode> a = baseInfo["container-chapter-reader"].GetEnumerator(); a.MoveNext(); // Set to 1; List <HtmlNode> collection = a.Current.ChildNodes.Where(x => x.Name == "img").ToList(); List <Image> images = new List <Image>(); for (int idx = 0; idx < collection.Count; idx++) { a :; GenerateHeaders(); try { images.Add(Epub.Image.GenerateImageFromByte(webClient.DownloadData(collection[idx].Attributes[0].Value), collection[idx].Attributes[0].Value.RemoveSpecialCharacters())); } catch { Alert.ADLUpdates.CallLogUpdate($"Timeout on Img. {idx} from {aski.ChapterName}, retrying after 30 seconds.", Alert.ADLUpdates.LogLevel.Middle); Thread.Sleep(30000); goto a; } ADLCore.Alert.ADLUpdates.CallLogUpdate($"Got Image {idx} out of {collection.Count - 1} for {aski.ChapterName}"); } return(images.ToArray()); }
/// <summary> /// Returns a path for a provided <see cref="MangaChapter" /> /// </summary> /// <param name="Chapter"> /// <see cref="MangaChapter" /> to return path for /// </param> /// <returns></returns> public String PathForChapter(MangaChapter Chapter) { return(Path.Combine( PathForManga(Chapter.Manga.ToString( )), SafeFolderName(Chapter.ToString( )) )); }
public void Add(MangaChapter Item) { var lvi = this.Items.Add(Item.ToString( )); lvi.ForeColor = Item.IsDownloaded ? System.Drawing.Color.LightBlue : System.Drawing.Color.Black; this.ChapterList.Add(Item, lvi); }
//Output format(Per face Single - 3 items, Double 2 items) // * MUST have faces for both sides (full pages) // * Front side first, Left face first -> LTR (a->b) a,b while RTL (a->b) b,a // S,M,B / D,M / S,M,M / S,M,E / .... public static void TestResult(string inputMangaChapters, string outputPrintFaces, bool startPage, bool endPage, int antiSpoiler = 0) { // ------------ MOCK INPUT -------------- List <MangaChapter> allChapters = new List <MangaChapter>(); string [] iCs = inputMangaChapters.Replace(" ", "").Split('/'); foreach (string iC in iCs) { MangaChapter mc = new MangaChapter(); mc.Pages = new System.Collections.ObjectModel.ObservableCollection <MangaPage>(); mc.IsRTL = (iC[0] == 'R'); string[] pages = iC.Substring(1).Split(','); foreach (string stringpage in pages) { MangaPage mp = new MangaPage(); mp.IsDouble = (stringpage == "1") ? false : true; mc.Pages.Add(mp); } allChapters.Add(mc); } // ------------ REAL OUTPUT -------------- List <PrintPage> resultPages = (new Core.ChapterBuilders.DuplexBuilder()).Build(allChapters, startPage, endPage, antiSpoiler); List <PrintFace> resultFaces = resultPages.SelectMany <PrintPage, PrintFace>((p) => new[] { p.Front, p.Back }).ToList(); List <string> quickLookArr = new List <string>(); foreach (PrintFace face in resultFaces) { string isRTL = (face.IsRTL ? "R" : "L") + ">"; if (face.PrintFaceType == FaceType.SINGLES) { quickLookArr.Add(isRTL + "S," + reverseSide(face.Left.SideType) + "," + reverseSide(face.Right.SideType)); } else { quickLookArr.Add(isRTL + "D," + reverseSide(face.Left.SideType)); } } // ------------ COMPARE -------------- string resultOutputString = string.Join("/", quickLookArr).ToUpper(); string testOutputString = outputPrintFaces.Replace(" ", "").ToUpper(); Console.WriteLine(resultOutputString); Assert.AreEqual(testOutputString, resultOutputString); }
private List <string> getBindedRange() { List <string> chaptersInfo = new List <string>(); MangaChapter lastChapter = null; int lastChapterStart = -1; foreach (var _p in lstPrintPages.Items) { var page = (PrintPage)_p; var Faces = new[] { page?.Front, page?.Back }; foreach (var Face in Faces) { var Sides = new[] { Face.Left, Face.Right }; if (Face.IsRTL) { Sides = new[] { Face.Right, Face.Left } } ; foreach (var Side in Sides) { if (Side.MangaPageSource?.Chapter != null) { var ch = Side.MangaPageSource.Chapter; if ((ch == null && lastChapter != null) || !ch.isEqual(lastChapter)) { chaptersInfo.Add( string.Format(HTMLItem, lastChapter?.Name + string.Format(" [{0}-{1}]", lastChapterStart, Face.FaceNumber - 1), lastChapter?.ParentName) ); lastChapter = ch; lastChapterStart = Face.FaceNumber; } } } } } // Add unclosed chapter: if (lastChapter != null) { chaptersInfo.Add( string.Format(HTMLItem, lastChapter?.Name + string.Format(" [{0}-{1}]", lastChapterStart, lstPrintPages.Items.Count * 2), lastChapter?.ParentName) ); } if (chaptersInfo.Count > 0) { chaptersInfo.RemoveAt(0); // The first element is null chapter } return(chaptersInfo); } const string HTMLItem = "<li><span>{0}</span><br><span style='color: dimgray;'>{1}</span></li>";
public IActionResult DeleteChapter(int id) { MangaChapter chapter = _mangaRepository.GetChapter(id); if (chapter == null) { return(View("404Error")); } _mangaRepository.DeleteChapter(id); return(RedirectToAction("Chapters", new { id = chapter.MangaId })); }
private MangaChapter[] GetChaptersA(HtmlNode col) { List <HtmlNode> collection = col.ChildNodes.Where(x => x.Name == "div").ToList(); List <MangaChapter> chapters = new List <MangaChapter>(); for (int idx = collection.Count - 1; idx > 0; idx--) { MangaChapter mngChp = new MangaChapter(); HtmlNode chpData = collection[idx].ChildNodes.First(x => x.Name == "span"); mngChp.ChapterName = chpData.InnerText + ".imc"; mngChp.linkTo = chpData.ChildNodes[0].Attributes[0].Value; chapters.Add(mngChp); } return(chapters.ToArray()); }
private void menuImprtFolders_Click(object sender, RoutedEventArgs e) { dlgSaveFile.Filter = "Folder|_Choose.Here_"; dlgSaveFile.FileName = "_Choose.Here_"; dlgSaveFile.CheckFileExists = false; dlgSaveFile.Multiselect = false; dlgSaveFile.ValidateNames = false; dlgSaveFile.Title = "Choose folder to import from:"; if (dlgSaveFile.ShowDialog() == true) { Core.FileImporter fileImporter = new Core.FileImporter(); var DirPath = new System.IO.FileInfo(dlgSaveFile.FileName).Directory.FullName; var subFolders = cbSubfolders.IsChecked ?? false; float cutoff = float.Parse(txtPageMaxWidth.Text); var rtl = rbRTL.IsChecked ?? false; var numFix = cbNumberFix.IsChecked ?? false; Func <System.IO.FileSystemInfo, object> orderFunc = (si) => si.CreationTime; if (rbByName.IsChecked ?? false) { orderFunc = (si) => numFix?FileImporter.pad0AllNumbers(si.Name) : si.Name; } List <FileImporterError> importErrors = new List <FileImporterError>(); winWorking.waitForTask(this, (updateFunc) => { return(fileImporter.getChapters(DirPath, subFolders, cutoff, rtl, orderFunc, importErrors, updateFunc)); }, isProgressKnwon: false) .ForEach(ch => mangaChapters.Add(MangaChapter.Extend <SelectableMangaChapter>(ch))); if (importErrors.Count > 0) { (new dlgImportErrors() { DataErrors = importErrors }).ShowDialog(); } else { StartWhiteRatioScan(); } } }
private void mnuAddEmptyChapter_Click(object sender, RoutedEventArgs e) { Dialogs.dlgString dlgName = new Dialogs.dlgString() { Title = "Enter name", Caption = "Enter empty chapter title:", StringData = "Chapter Name" }; if (dlgName.ShowDialog() ?? false) { mangaChapters.Add(MangaChapter.Extend <SelectableMangaChapter>(new Core.MangaChapter() { IsRTL = rbRTL.IsChecked ?? false, Pages = new ObservableCollection <Core.MangaPage>(), Name = dlgName.StringData })); } }
public IActionResult CreateChapter(int id, MangaChapterCreateViewModel model) { if (ModelState.IsValid) { if (model.Files != null && model.Files.Count > 0) { foreach (IFormFile file in model.Files) { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "Mangas"); string filePath = Path.Combine(uploadsFolder, id.ToString(), model.ChapterNo.ToString()); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string fullPath = Path.Combine(filePath, file.FileName); file.CopyTo(new FileStream(fullPath, FileMode.Create)); } } MangaChapter newChapter = new MangaChapter() { ChapterNo = model.ChapterNo, MangaId = id, Title = model.Title, ChFolder = Path.Combine(_hostingEnvironment.WebRootPath, "Mangas", id.ToString(), model.ChapterNo.ToString()) }; _mangaRepository.AddChapter(newChapter); return(RedirectToAction("Chapters", new { id = id })); } return(View(model)); }
// Shamefully copied from hakuneko (barely modified) /// <summary> /// Returns the url from all pages of the provided <see /// cref="MangaChapter" /> /// </summary> /// <param name="Chapter">The <see cref="MangaChapter" /> to scrap</param> /// <returns></returns> public async override Task <String[]> GetPageLinksAsync(MangaChapter Chapter) { var pageLinks = new List <String> ( ); try { var HTML = await HTTP.GetStringAsync(Chapter.Link); var indexStart = HTML.IndexOf("<select onchange=\"change_page(this)\" class=\"m\">") + 48; // ignore last option (comments -> value="0") var indexEnd = HTML.IndexOf("<option value=\"0\"", indexStart); if (indexStart > 47 && indexEnd >= -1) { HTML = HTML.Substring(indexStart, indexEnd - indexStart); indexEnd = 0; // Example Entry: // <option value="1" selected="selected">1</option> while ((indexStart = HTML.IndexOf("<option value=\"", indexEnd)) > -1) { indexStart += 15; indexEnd = HTML.IndexOf('"', indexStart); pageLinks.Add( await GetImageLinkAsync( Chapter.Link.BeforeLast('/') + '/' + HTML.Substring(indexStart, indexEnd - indexStart) + ".html" ) ); } } } catch (Exception e) { Logger.Log("Couldn't retrieve page links:"); Logger.Log(e); } return(pageLinks.ToArray( )); }
public override Task <String[]> GetPageLinksAsync(MangaChapter Chapter) { return(GT(Enumerable.Range(1, 10) .Select(num => $"https://example.com/{Chapter.Manga.Name}/{Chapter.Chapter}") .ToArray( ))); }
private static void HandleFace(ref bool isFirst, List <PrintFace> Faces, MangaChapter ch, MangaPage p, SingleSideType sideType = SingleSideType.MANGA) { if (isFirst && !p.IsDouble) { PrintFace face = new PrintFace() { PrintFaceType = FaceType.SINGLES, IsRTL = ch.IsRTL }; Faces.Add(face); PrintSide side = null; if (sideType == SingleSideType.MANGA) { side = new PrintSide() { SideType = SingleSideType.MANGA, MangaPageSource = p, MangaPageSourceType = SideMangaPageType.ALL }; } else { side = new PrintSide() { MangaPageSource = p, SideType = sideType, }; } if (ch.IsRTL) { face.Right = side; } else { face.Left = side; } isFirst = false; } else if (isFirst && p.IsDouble) { PrintFace face = new PrintFace() { PrintFaceType = FaceType.DOUBLE, IsRTL = ch.IsRTL }; Faces.Add(face); PrintSide side = new PrintSide() { SideType = SingleSideType.MANGA, MangaPageSource = p, MangaPageSourceType = SideMangaPageType.ALL // only in booklet we need to know right\left }; face.Left = face.Right = side; isFirst = true; } else if (!isFirst && !p.IsDouble) { PrintFace face = Faces.Last(); PrintSide side = null; if (sideType == SingleSideType.MANGA) { side = new PrintSide() { SideType = SingleSideType.MANGA, MangaPageSource = p, MangaPageSourceType = SideMangaPageType.ALL }; } else { side = new PrintSide() { SideType = sideType, MangaPageSource = p, }; } if (ch.IsRTL) { face.Left = side; } else { face.Right = side; } isFirst = true; } else if (!isFirst && p.IsDouble) { // Add FILLER PrintFace face = Faces.Last(); PrintSide side = new PrintSide() { SideType = SingleSideType.BEFORE_DOUBLE, }; if (ch.IsRTL) { face.Left = side; } else { face.Right = side; } // Add Double face = new PrintFace() { PrintFaceType = FaceType.DOUBLE, IsRTL = ch.IsRTL }; Faces.Add(face); side = new PrintSide() { SideType = SingleSideType.MANGA, MangaPageSource = p, MangaPageSourceType = SideMangaPageType.ALL // only in booklet we need to know right\left }; face.Left = face.Right = side; isFirst = true; } }
public void Remove(MangaChapter Item) { this.Items.Remove(this.ChapterList[Item]); this.ChapterList.Remove(Item); }
public Boolean Contains(MangaChapter Item) { return(this.ChapterList.ContainsKey(Item)); }
public void BeginExecution() { Manga.Models.Manga manga = new Manga.Models.Manga(); string ex; if (args.d) { if (args.term.IsValidUri()) { manga.metaData = GetMetaData(); ex = args.l ? args.export + Path.DirectorySeparatorChar + manga.metaData.name + ".adl" : Directory.GetCurrentDirectory() + $"{Path.DirectorySeparatorChar}Epubs{Path.DirectorySeparatorChar}" + manga.metaData.name + ".adl"; archive.InitializeZipper(ex); } else { archive.InitializeZipper(args.term, true); manga.LoadMangaFromADL(ref archive.zapive); ex = args.l ? args.export + Path.DirectorySeparatorChar + manga.metaData.name + ".adl" : Directory.GetCurrentDirectory() + $"{Path.DirectorySeparatorChar}Epubs{Path.DirectorySeparatorChar}" + manga.metaData.name + ".adl"; args.term = manga.metaData.url; } this.mdata = manga.metaData; manga.ExportMetaData(ref archive.zapive); MovePage(args.term); MangaChapter[] b = GetMangaLinks(); if (manga.Chapters != null) { ArraySegment <MangaChapter> mg = new ArraySegment <MangaChapter>(b, manga.Chapters.Length, b.Length - manga.Chapters.Length); MangaChapter[] c = new MangaChapter[b.Length]; manga.Chapters.CopyTo(c, 0); mg.CopyTo(c, manga.Chapters.Length); manga.Chapters = c; } else { manga.Chapters = b; } } else { //manga.Chapters = GetMangaLinks(); unable for now. ex = args.l ? args.export : args.term; archive.InitializeZipper(ex, true); manga.LoadMangaFromADL(ref archive.zapive); manga.LoadChaptersFromADL(ref archive.zapive); } for (int idx = (args.vRange ? args.VideoRange[0] : args.d ? 0 : manga.Chapters.Length); idx < (args.vRange ? args.VideoRange[1] : manga.Chapters.Length); idx++) { if (manga.Chapters[idx].existing == true) { continue; } manga.Chapters[idx].Images = GetImages(ref manga.Chapters[idx], ref manga, ref archive); List <Byte[]> bytes = new List <byte[]>(); foreach (Epub.Image img in manga.Chapters[idx].Images) { bytes.Add(img.bytes); } archive.AddContentToArchive(manga.Chapters[idx].ChapterName, bytes); manga.Chapters[idx].Images = null; // free up memory. GC.Collect(); } manga.ExportToEpub(Directory.GetCurrentDirectory() + $"{Path.DirectorySeparatorChar}Epubs{Path.DirectorySeparatorChar}" + manga.metaData.name, ref archive.zapive); }
public abstract Epub.Image[] GetImages(ref MangaChapter aski, ref Models.Manga manga, ref ArchiveManager arc);
public void Process() { loadFromSourceConfig(); // make sure web source is available WebValidator webVal = new WebValidator(); // ensure link is valid if (!webVal.isValidURL(inputLink)) { throw new Exception(ErrorMsg.INVALID_WEB_LINK); } // create process tree string link = inputLink; int currChapterCount = 1; int currPageNum = 1; MangaHolder currManga = new MangaHolder(); MangaChapter currChapter = new MangaChapter(); while (!String.IsNullOrEmpty(link)) { HtmlDocument currentDoc = getPageSource(link); string lastPageURL = link; string nextPageElement = getElementFromKey(currentDoc.DocumentNode, new Queue <KeyValuePair <string, int> >(nextPageKey), "href"); string nextPageURL = getURL(getElementFromKey(currentDoc.DocumentNode, new Queue <KeyValuePair <string, int> >(nextPageKey), "href"), link); string chapterPageURL = getURL(getElementFromKey(currentDoc.DocumentNode, new Queue <KeyValuePair <string, int> >(chapterPageKey), "href"), link); string imageSrcURL = getURL(getElementFromKey(currentDoc.DocumentNode, new Queue <KeyValuePair <string, int> >(imgPageKey), "content"), link); // If theres a chapter configuration make there we didnt miss any chapters if (nextChapterPageKey.Count > 0 && nextPageElement != null && nextPageElement.Equals("javascript:void(0);")) { nextPageURL = getURL(getElementFromKey(currentDoc.DocumentNode, new Queue <KeyValuePair <string, int> >(nextChapterPageKey), "href"), link); } if ( !String.IsNullOrEmpty(lastPageURL) && !String.IsNullOrEmpty(nextPageURL) && !String.IsNullOrEmpty(imageSrcURL) && !String.IsNullOrEmpty(chapterPageURL) ) { // Base Case if (!currManga.ContainsChapter(chapterPageURL)) { currPageNum = 1; MangaChapter chapter = new MangaChapter(chapterPageURL); chapter.TryAddPage(new MangaPage(imageSrcURL, lastPageURL, nextPageURL, chapterPageURL, currPageNum)); chapter.relativeChapterNum = currChapterCount; currChapterCount++; //chapter.AddPage(new MangaPage(imageSrcURL, lastPageURL, nextPageURL, chapterPageURL, currPageNum)); currManga.TryAddChapter(chapter); } else { currManga.AddToExistingChapter(chapterPageURL, new MangaPage(imageSrcURL, lastPageURL, nextPageURL, chapterPageURL, currPageNum)); } currPageNum++; } link = nextPageURL; } //Create folder in temp string tempPath = Path.GetTempPath(); if (String.IsNullOrEmpty(tempPath)) { throw new Exception(ErrorMsg.INVALID_TEMP_FOLDER_PATH); } tempPath = tempPath + DateTime.Now.Ticks; // DateTime.Now.Ticks will make the folder path unique af Directory.CreateDirectory(tempPath); // Console.WriteLine("Temp Path: " + tempPath); string mangaPath = tempPath; string chapterFolderPath; string fileName; foreach (KeyValuePair <String, MangaChapter> chapter in currManga.chapters) { chapterFolderPath = tempPath + "\\" + chapter.Value.relativeChapterNum.ToString(); Directory.CreateDirectory(chapterFolderPath); foreach (List <MangaPage> pages in chapter.Value.pages.Values) { foreach (MangaPage page in pages) { fileName = chapterFolderPath + "\\" + page.relativePageNum + ".jpg"; Console.WriteLine("Downloading src: " + page.imgSrc); using (WebClient client = new WebClient()) { client.DownloadFile(page.imgSrc, fileName); } } } } string zipName = folderPath + "\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip"; using (ZipFile zip = new ZipFile()) { zip.AddDirectory(tempPath); zip.Save(zipName); } System.IO.DirectoryInfo di = new DirectoryInfo(tempPath); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } foreach (DirectoryInfo dir in di.GetDirectories()) { dir.Delete(true); } //test(getPageSource(inputLink), inputLink); System.Windows.Forms.MessageBox.Show("Finished downloading images. Please locate to " + folderPath + " for the manga ripped."); return; }