Skip to content

Commit

Permalink
Core refactor
Browse files Browse the repository at this point in the history
- Add polymorphism to Manga and Hentai to allow for easier addition of sources
- Several things have been renamed
- Beginnings of KissManga integration

Note: Need to make many more changes to fully polymorphize.  May require changes to manga.txt
  • Loading branch information
9vult committed Apr 8, 2020
1 parent 423499e commit 33021bc
Show file tree
Hide file tree
Showing 30 changed files with 749 additions and 91 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
81 changes: 81 additions & 0 deletions MikuReader-Core/Core/Download/KissMangaDownload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using HtmlAgilityPack;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;

namespace MikuReader.Core
{
public class KissMangaDownload : IDownload
{
private Chapter chapter;
private ArrayList clients;
private float total;

public event DownloadCompletedEventHandler DownloadCompleted;

public KissMangaDownload(Chapter chapter)
{
this.chapter = chapter;
clients = new ArrayList();
total = 0;
}

public void StartDownloading()
{
File.Create(Path.Combine(chapter.GetChapterRoot().Parent.FullName, "dl" + chapter.GetID())).Close();

string mName = chapter.GetChapterRoot().Parent.Name;
string cUrl = "https://kissmanga.org/chapter/" + mName + "/" + chapter.GetID();
string[] pageUrls = KissMangaHelper.GetPageUrls(cUrl);

foreach (string url in pageUrls)
{
string imgFile = Path.Combine(chapter.GetChapterRoot().FullName, KissMangaHelper.GetPageFileName(url));
DownloadAsync(new Uri(url), imgFile);
}
}

public void DownloadAsync(Uri imgUrl, string imgFile)
{
using (WebClient wc = new WebClient())
{
total++;
clients.Add(wc);
wc.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompletedCallback);
wc.DownloadFileAsync(imgUrl, imgFile);
}
}

public bool CheckStartNext()
{
if (clients.Count == 0)
{
DownloadCompleted.Invoke(this);
File.Delete(Path.Combine(chapter.GetChapterRoot().Parent.FullName, "dl" + chapter.GetID()));
return true;
}
return false;
}

public void DownloadCompletedCallback(object sender, AsyncCompletedEventArgs e)
{
clients.Remove((WebClient)sender);
CheckStartNext();
}

public int GetProgress()
{
return total != 0 ? (int)(((total - clients.Count) / total) * 100) : 0;
}

public string GetChapterName()
{
return chapter.GetChapterRoot().ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public MangaDexDownload(Chapter chapter)
public void StartDownloading()
{
File.Create(Path.Combine(chapter.GetChapterRoot().Parent.FullName, "dl" + chapter.GetID())).Close();
string jsonUrl = MangaDex.MANGADEX_URL + "/api/chapter/" + chapter.GetID();
string jsonUrl = MangaDexHelper.MANGADEX_URL + "/api/chapter/" + chapter.GetID();
string jsonString;

using (var wc = new WebClient())
Expand All @@ -62,7 +62,7 @@ public void StartDownloading()
foreach (string file in page_array)
{
if (server == "/data/")
server = MangaDex.MANGADEX_URL + "/data/";
server = MangaDexHelper.MANGADEX_URL + "/data/";

string imgUrl = server + hash + "/" + file;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ public void StartDownloading()
{
File.Create(Path.Combine(chapter.GetChapterRoot().Parent.FullName, "dl" + chapter.GetID())).Close();
List<HtmlDocument> docs = new List<HtmlDocument>();
int pageCount = Nhentai.GetPageCount("https://nhentai.net/g/" + chapter.GetID());
int pageCount = NhentaiHelper.GetPageCount("https://nhentai.net/g/" + chapter.GetID());

string hUrl = "https://nhentai.net/g/" + chapter.GetID() + "/";

string baseUrl = Nhentai.GetImageUrl(hUrl + "1");
string hash = Nhentai.GetHash(baseUrl);
string baseUrl = NhentaiHelper.GetImageUrl(hUrl + "1");
string hash = NhentaiHelper.GetHash(baseUrl);

for (int page = 1; page <= pageCount; page++)
{
string imgUrl = Nhentai.ImgBase() + hash + "/" + page + "." + Nhentai.GetExt(baseUrl);
string imgFile = Path.Combine(chapter.GetChapterRoot().FullName, page + "." + Nhentai.GetExt(baseUrl));
string imgUrl = NhentaiHelper.ImgBase() + hash + "/" + page + "." + NhentaiHelper.GetExt(baseUrl);
string imgFile = Path.Combine(chapter.GetChapterRoot().FullName, page + "." + NhentaiHelper.GetExt(baseUrl));
DownloadAsync(new Uri(imgUrl), imgFile);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ private void Populate()
switch (Title.GetType(dir))
{
case TitleType.MANGA:
mangaDB.Add(new Manga(dir));
mangaDB.Add(new MangaDex(dir, MangaType.MANGADEX));
break;

case TitleType.HENTAI:
hentaiDB.Add(new Hentai(dir));
hentaiDB.Add(new Nhentai(dir, HentaiType.NHENTAI));
break;
case TitleType.NULL:
default:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
55 changes: 55 additions & 0 deletions MikuReader-Core/Core/Model/Hentai.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace MikuReader.Core
{
/// <summary>
/// Representation of a Manga
/// </summary>
public abstract class Hentai : Title
{
/// <summary>
/// Loads Manga info from manga.txt
/// </summary>
public abstract void _Load();

/// <summary>
/// Creates manga.txt, then calls Load()
/// </summary>
/// <param name="mangaUrl"></param>
public abstract void _Create(string mangaUrl);

/// <summary>
/// Create a Chapter for each chapter and add it to the chapter list
/// </summary>
public abstract void _PopulateChapters();

public abstract override void UpdateLocation(string chapter, string page);

public abstract override void Save(string chapter, string page);

public abstract override void UpdateProperties(string title, string lang, string group);

public abstract override string GetTitle();

public abstract override string GetUserTitle();

public abstract override List<Chapter> GetChapters();

public abstract override string GetCurrentChapter();

public abstract override string GetCurrentPage();

public abstract override string GetID();

public abstract override bool IsDownloading();
}
}
84 changes: 84 additions & 0 deletions MikuReader-Core/Core/Model/Manga.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace MikuReader.Core
{
/// <summary>
/// Representation of a Manga
/// </summary>
public abstract class Manga : Title
{

/// <summary>
/// Loads Manga info from manga.txt
/// </summary>
public abstract void _Load(bool doChapters);

/// <summary>
/// Creates manga.txt, then calls Load()
/// </summary>
/// <param name="mangaUrl"></param>
public abstract void _Create(string mangaUrl);

public abstract Chapter[] GetSetPrunedChapters(bool overrideDlc);

public abstract Chapter[] GetUpdates();

/// <summary>
/// Get the groups associated with this manga
/// </summary>
/// <param name="langCode">Language to select group from</param>
/// <returns>List of groups associated with the language</returns>
public abstract string[] GetGroups(string langCode);

public abstract string[] GetLangs();

/// <summary>
/// Get the user's specified language
/// </summary>
public abstract string GetUserLang();

/// <summary>
/// Get the user's specified Group
/// </summary>
public abstract string GetUserGroup();

/// <summary>
/// Create a Chapter for each chapter and add it to the chapter list
/// </summary>
public abstract void _PopulateChapters();

public abstract override void UpdateLocation(string chapter, string page);

public abstract override void Save(string chapter, string page);

public abstract override void UpdateProperties(string title, string lang, string group);

public abstract override string GetTitle();

public abstract override string GetUserTitle();

public abstract override List<Chapter> GetChapters();

public abstract override string GetCurrentChapter();

public abstract override string GetCurrentPage();

public abstract override string GetID();

public abstract override bool IsDownloading();

public abstract void UpdateDLChapters(String[] chapterNums);

public abstract String[] GetDLChapters();

}
}
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions MikuReader-Core/Core/Title/HentaiType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MikuReader.Core
{
public enum HentaiType
{
NHENTAI
}
}
Loading

0 comments on commit 33021bc

Please sign in to comment.