Skip to content

Commit

Permalink
refactor(mangademon): use base_url as crate
Browse files Browse the repository at this point in the history
  • Loading branch information
KaBankz committed Apr 28, 2024
1 parent 803be90 commit 5e409e9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
10 changes: 6 additions & 4 deletions src/rust/en.mangademon/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use aidoku::{
std::{html::Node, String},
};

use crate::BASE_URL;

/// Converts `<br>` into newlines.
pub fn text_with_newlines(node: Node) -> String {
let html = node.html().read();
Expand Down Expand Up @@ -71,13 +73,13 @@ pub fn get_chapter_id(url: &str) -> String {
}

/// Returns full URL of a manga from a manga ID.
pub fn get_manga_url(manga_id: &String, base_url: &String) -> String {
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/{}-VA", 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, base_url: &String) -> String {
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)
format!("{}/manga/{}/chapter/{}-VA", BASE_URL, manga_id, chapter_id)
}
12 changes: 6 additions & 6 deletions src/rust/en.mangademon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn get_manga_list(filters: Vec<Filter>, page: i32) -> Result<MangaPageResult> {

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

Ok(parse_manga_list(html, String::from(BASE_URL), searching))
Ok(parse_manga_list(html, searching))
}

#[get_manga_listing]
Expand All @@ -78,12 +78,12 @@ fn get_manga_listing(_listing: Listing, page: i32) -> Result<MangaPageResult> {

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

Ok(parse_manga_list(html, String::from(BASE_URL), false))
Ok(parse_manga_list(html, false))
}

#[get_manga_details]
fn get_manga_details(manga_id: String) -> Result<Manga> {
let url = get_manga_url(&manga_id, &String::from(BASE_URL));
let url = get_manga_url(&manga_id);

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

Expand All @@ -92,16 +92,16 @@ fn get_manga_details(manga_id: String) -> Result<Manga> {

#[get_chapter_list]
fn get_chapter_list(manga_id: String) -> Result<Vec<Chapter>> {
let url = get_manga_url(&manga_id, &String::from(BASE_URL));
let url = get_manga_url(&manga_id);

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

Ok(parse_chapter_list(html, String::from(BASE_URL)))
Ok(parse_chapter_list(html))
}

#[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, &String::from(BASE_URL));
let url = get_chapter_url(&chapter_id, &manga_id);

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

Expand Down
13 changes: 7 additions & 6 deletions src/rust/en.mangademon/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use aidoku::{
};

use crate::helper::*;
use crate::BASE_URL;

pub fn parse_manga_list(html: Node, base_url: String, searching: bool) -> MangaPageResult {
pub fn parse_manga_list(html: Node, searching: bool) -> MangaPageResult {
let mut manga: Vec<Manga> = Vec::new();

if searching {
Expand All @@ -15,8 +16,8 @@ pub fn parse_manga_list(html: Node, base_url: String, searching: bool) -> MangaP

let raw_url = node.attr("href").read();
let id = get_manga_id(&raw_url);
let url = get_manga_url(&id, &base_url);
let cover = format!("{}/img/noimg.jpg", base_url);
let url = get_manga_url(&id);
let cover = format!("{}/img/noimg.jpg", BASE_URL);
let title = String::from(node.text().read().trim());

manga.push(Manga {
Expand All @@ -41,7 +42,7 @@ pub fn parse_manga_list(html: Node, base_url: String, searching: bool) -> MangaP

let title = node.attr("title").read();
let id = get_manga_id(&raw_url);
let url = get_manga_url(&id, &base_url);
let url = get_manga_url(&id);
let cover = node.select("img").attr("src").read();

manga.push(Manga {
Expand Down Expand Up @@ -140,7 +141,7 @@ pub fn parse_manga_details(html: Node, manga_url: String) -> Manga {
}
}

pub fn parse_chapter_list(html: Node, base_url: String) -> Vec<Chapter> {
pub fn parse_chapter_list(html: Node) -> Vec<Chapter> {
let mut chapters: Vec<Chapter> = Vec::new();

for node in html
Expand All @@ -153,7 +154,7 @@ pub fn parse_chapter_list(html: Node, base_url: String) -> Vec<Chapter> {
let id = node.attr("data-chapterno").read();

let manga_id = get_manga_id(&raw_url);
let url = get_chapter_url(&id, &manga_id, &base_url);
let url = get_chapter_url(&id, &manga_id);

let chapter = node
.attr("data-chapterno")
Expand Down

0 comments on commit 5e409e9

Please sign in to comment.