Skip to content

Commit

Permalink
fix(mangalib): update url to manga & one more thing (#795)
Browse files Browse the repository at this point in the history
* fix(mangalib): update URL to manga

* fix(libgroup): display date of upload chapter

* fix(libgroup): determine MangaViewer

* fix(libgroup): add user-agent at every request & change api domain

* fix(libgroup): I forgot remove println
  • Loading branch information
vlapsk1y authored Nov 17, 2024
1 parent 7da7814 commit d95c61a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/rust/multi.libgroup/sources/mangalib/res/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "ru.mangalib",
"lang": "ru",
"name": "MangaLib",
"version": 1,
"version": 2,
"url": "https://mangalib.me",
"nsfw": 1
},
Expand Down
33 changes: 22 additions & 11 deletions src/rust/multi.libgroup/template/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,9 @@ pub fn parse_manga_details(
let description = detail.get("summary").as_string()?.read();

let url = format!(
"https://{}/{}",
"https://{}/ru/manga/{}",
domain,
detail
.get("slug_url")
.as_string()?
.read()
.split("--")
.collect::<Vec<&str>>()
.get(1)
.unwrap()
detail.get("slug_url").as_string()?.read()
);

let categories: Vec<String> = detail
Expand All @@ -144,7 +137,18 @@ pub fn parse_manga_details(

let nsfw = *is_nsfw;

let viewer = MangaViewer::Rtl;
let viewer = if detail
.get("type")
.as_object()?
.get("id")
.as_int()
.unwrap_or_default()
== 5
{
MangaViewer::Scroll
} else {
MangaViewer::Rtl
};

Ok(Manga {
id,
Expand Down Expand Up @@ -197,7 +201,14 @@ pub fn parse_chapter_list(js: ObjectRef, id: &str, domain: &str) -> Result<Vec<C
String::new(),
chapter_object.get("number").as_string()?.read(),
)[0],
date_updated: -1.0,
date_updated: chapter_object
.get("branches")
.as_array()?
.get(0)
.as_object()?
.get("created_at")
.as_string()?
.as_date("yyyy-MM-dd'T'HH:mm:ss.SSS'Z", Some("en_US"), None),
scanlator: chapter_object
.get("branches")
.as_array()?
Expand Down
23 changes: 17 additions & 6 deletions src/rust/multi.libgroup/template/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ pub struct CDN {
pub compress: &'static str,
}

static DOMAIN_API: &str = "https://api.lib.social/api/";
static USER_AGENT: &str = "Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1";
static DOMAIN_API: &str = "https://api.mangalib.me/api/";

impl SocialLibSource {
pub fn get_manga_list(&self, filters: Vec<Filter>, page: i32) -> Result<MangaPageResult> {
Expand All @@ -41,7 +42,9 @@ impl SocialLibSource {
}

let url = format!("{}manga?{}", DOMAIN_API, query);
let request = Request::new(url, HttpMethod::Get).header("Site-Id", self.site_id);
let request = Request::new(url, HttpMethod::Get)
.header("Site-Id", self.site_id)
.header("User-Agent", USER_AGENT);
let json = request.json()?.as_object()?;

parser::parse_manga_list(json, &self.domain.to_string(), self.nsfw)
Expand All @@ -56,7 +59,9 @@ impl SocialLibSource {
let query = qs.to_string();

let url = format!("{}media/top-views?{}", DOMAIN_API, query);
let request = Request::new(url, HttpMethod::Get).header("Site-Id", self.site_id);
let request = Request::new(url, HttpMethod::Get)
.header("Site-Id", self.site_id)
.header("User-Agent", USER_AGENT);
let json = request.json()?.as_object()?;

parser::parse_manga_list(json, &self.domain.to_string(), self.nsfw)
Expand All @@ -77,7 +82,9 @@ impl SocialLibSource {
query.push("fields[]", Some("status_id"));
query.push("fields[]", Some("artists"));
let url = format!("{}manga/{}?{}", DOMAIN_API, id, query.to_string());
let request = Request::new(url, HttpMethod::Get).header("Site-Id", self.site_id);
let request = Request::new(url, HttpMethod::Get)
.header("Site-Id", self.site_id)
.header("User-Agent", USER_AGENT);
let json = request.json()?.as_object()?;

parser::parse_manga_details(json, self.domain, self.nsfw)
Expand All @@ -86,7 +93,9 @@ impl SocialLibSource {
pub fn get_chapter_list(&self, id: String) -> Result<Vec<Chapter>> {
let url = format!("{}manga/{}/chapters", DOMAIN_API, id);

let request = Request::new(url, HttpMethod::Get).header("Site-Id", self.site_id);
let request = Request::new(url, HttpMethod::Get)
.header("Site-Id", self.site_id)
.header("User-Agent", USER_AGENT);
let json = request.json()?.as_object()?;

parser::parse_chapter_list(json, &id, self.domain)
Expand All @@ -102,7 +111,9 @@ impl SocialLibSource {
numbers.first().unwrap(),
numbers.get(1).unwrap()
);
let request = Request::new(url, HttpMethod::Get).header("Site-Id", self.site_id);
let request = Request::new(url, HttpMethod::Get)
.header("Site-Id", self.site_id)
.header("User-Agent", USER_AGENT);
let json = request.json()?.as_object()?;

parser::parse_page_list(json, self.cdn)
Expand Down

0 comments on commit d95c61a

Please sign in to comment.