Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mangademon): rewrite most of the source to account for a site remake #756

Merged
merged 22 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/rust/en.mangademon/res/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"id": "en.mangademon",
"lang": "en",
"name": "Manga Demon",
"version": 3,
"url": "https://mgdemon.org",
"version": 4,
"url": "https://ciorti.online",
"nsfw": 0
},
"listings": [
Expand Down
85 changes: 23 additions & 62 deletions src/rust/en.mangademon/src/helper.rs
Original file line number Diff line number Diff line change
@@ -1,85 +1,46 @@
use aidoku::{
prelude::format,
std::{html::Node, String},
};
use aidoku::{error::Result, prelude::format, std::String};

use crate::BASE_URL;

/// Converts `<br>` into newlines.
pub fn text_with_newlines(node: Node) -> String {
let html = node.html().read();
if !String::from(html.trim()).is_empty() {
Node::new_fragment(
node.html()
.read()
.replace("<br>", "{{ .LINEBREAK }}")
.as_bytes(),
)
.expect("Failed to create new fragment")
.text()
.read()
.replace("{{ .LINEBREAK }}", "\n")
} else {
String::new()
}
}

/// Returns the ID of a manga from a URL.
pub fn get_manga_id(url: &str) -> String {
// NOTE: From my limited testing every manga seems to have a suffix of `-VA54`
// But it looks like only `-VA` is required we can remove it for the id and
// add it back for the url
//
// Example Url: https://demonreader.org/manga/Skeleton-Soldier-VA54
// Example Url: https://demonreader.org/manga/Skeleton-Soldier/chapter/1-VA54
// parse "Skeleton-Soldier" from the url

let id_with_suffix = url.split("/manga/").last().unwrap_or("");

let id_without_suffix = if let Some(index) = id_with_suffix.rfind("-VA") {
// Two Formats
// https://demonicscans.org/title/Overgeared/chapter/1/2024090306
// https://demonicscans.org/manga/Overgeared
// For the chapter format it seems as if the ending part is <year><month><day><hour> where hour is 12hr time in UTC

let id_with_suffix = url
.split("/manga/")
.last()
.unwrap_or(url.split("/title/").last().unwrap_or(""));

// Handle chapter suffix
let id_without_chapter_suffix = if let Some(index) = id_with_suffix.rfind("/chapter/") {
&id_with_suffix[..index]
} else {
id_with_suffix
};

// Handle additional suffixes like "/chapter/1-VA54"
let id_without_chapter_suffix = if let Some(index) = id_without_suffix.rfind("/chapter/") {
&id_without_suffix[..index]
} else {
id_without_suffix
};

String::from(id_without_chapter_suffix)
}

/// Returns the ID of a chapter from a URL.
pub fn get_chapter_id(url: &str) -> String {
// NOTE: From my limited testing every chapter seems to have a suffix of `-VA54`
// But it looks like only `-VA` is required we can remove it for the id and
// add it back for the url
//
// Example Url: https://demonreader.org/manga/Skeleton-Soldier/chapter/1-VA54
// parse "1" from the url

let id_with_suffix = url.split("/chapter/").last().unwrap_or("");

let id_without_suffix = if let Some(index) = id_with_suffix.rfind("-VA") {
&id_with_suffix[..index]
} else {
id_with_suffix
};
// Example Url: https://demonicscans.org/chaptered.php?manga=4&chapter=1
// Example Url: /chaptered.php?manga=4&chapter=1
// parse "/chaptered.php?manga=4&chapter=1" from the url

String::from(id_without_suffix)
match url.find("/chaptered.php") {
Some(i) => url[i..].into(),
None => String::from(""),
}
}

/// Returns full URL of a manga from a manga ID.
pub fn get_manga_url(manga_id: &String) -> String {
// Append the `-VA` suffix to the manga id to get the proper url.
format!("{}/manga/{}-VA", BASE_URL, manga_id)
format!("{}/manga/{}", BASE_URL, manga_id)
}

/// Returns full URL of a chapter from a chapter ID.
pub fn get_chapter_url(chapter_id: &String, manga_id: &String) -> String {
// Append the `-VA` suffix to the chapter id to get the proper url.
format!("{}/manga/{}/chapter/{}-VA", BASE_URL, manga_id, chapter_id)
pub fn get_chapter_url(chapter_id: &String) -> Result<String> {
Ok(format!("{}{}", BASE_URL, chapter_id))
}
15 changes: 8 additions & 7 deletions src/rust/en.mangademon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use aidoku::{
use helper::*;
use parser::*;

const BASE_URL: &str = "https://mgdemon.org";
const BASE_URL: &str = "https://ciorti.online";

#[get_manga_list]
fn get_manga_list(filters: Vec<Filter>, page: i32) -> Result<MangaPageResult> {
let mut url = format!("{}/browse.php?list={}", BASE_URL, page);
let mut url = format!("{}/advanced.php?list={}", BASE_URL, page);

let mut searching = false;

Expand All @@ -32,6 +32,7 @@ fn get_manga_list(filters: Vec<Filter>, page: i32) -> Result<MangaPageResult> {
searching = true;
let query = encode_uri_component(value.read());
url = format!("{}/search.php?manga={}", BASE_URL, query);
break;
}
}
FilterType::Genre => {
Expand Down Expand Up @@ -74,11 +75,11 @@ fn get_manga_list(filters: Vec<Filter>, page: i32) -> Result<MangaPageResult> {

#[get_manga_listing]
fn get_manga_listing(_listing: Listing, page: i32) -> Result<MangaPageResult> {
let url = format!("{}/updates.php?list={}", BASE_URL, page);
let url = format!("{}/lastupdates.php?list={}", BASE_URL, page);

let html = Request::new(url, HttpMethod::Get).html()?;

Ok(parse_manga_list(html, false))
Ok(parse_latest_manga_list(html))
}

#[get_manga_details]
Expand All @@ -100,10 +101,10 @@ fn get_chapter_list(manga_id: String) -> Result<Vec<Chapter>> {
}

#[get_page_list]
fn get_page_list(manga_id: String, chapter_id: String) -> Result<Vec<Page>> {
let url = get_chapter_url(&chapter_id, &manga_id);
fn get_page_list(_manga_id: String, chapter_id: String) -> Result<Vec<Page>> {
let chap_url = get_chapter_url(&chapter_id)?;

let html = Request::new(url, HttpMethod::Get).html()?;
let html = Request::new(chap_url, HttpMethod::Get).html()?;

Ok(parse_page_list(html))
}
Expand Down
Loading
Loading