Skip to content

Commit

Permalink
fix(boylove): chapters not loading (#833)
Browse files Browse the repository at this point in the history
* chore: bump version

* chore: update dependencies

* fix: add query parameter `limit`

* fix: update api domain

* fix: update query parameters

* fix: update user agent for api

* fix: add header `Tokenparam` for api

* build: add crate `md5`

* fix: add header `Token` for api

* chore: update urls for deep linking
  • Loading branch information
aphronyx authored Dec 20, 2024
1 parent d7ebd08 commit 276adef
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 37 deletions.
53 changes: 30 additions & 23 deletions src/rust/zh.boylove/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/rust/zh.boylove/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ lto = true
[dependencies]
aidoku = { git = "https://github.com/Aidoku/aidoku-rs", features = ["helpers"] }
chinese-number = { version = "0.7.7", default-features = false, features = ["chinese-to-number"] }
md5 = { version = "0.7.0", default-features = false }
regex = { version = "1.10.2", default-features = false, features = ["unicode"] }
strum_macros = "0.26.4"
7 changes: 5 additions & 2 deletions src/rust/zh.boylove/res/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
"id": "zh.boylove",
"lang": "zh",
"name": "香香腐宅",
"version": 8,
"version": 9,
"urls": [
"https://boylove.cc",
"https://boylove3.cc",
"https://boylove.life",
"https://boylove.mobi",
"https://boylove1.mobi",
"https://boylove.today",
"https://boylove4.xyz",
Expand All @@ -17,15 +16,19 @@
"https://boyloves.space",
"https://boyslove.life",
"https://fufun.me",
"https://fufun.xyz",
"https://fufuzai.com",
"https://futaku.co",
"https://fuzai.cc",
"https://fuzai.fun",
"https://fuzai.life",
"https://fuzaifu.cc",
"https://fuzaii.cc",
"https://fuzhais.com",
"https://fuzone.org",
"https://fzai.club",
"https://ifuzai.life",
"https://yifuzai.net",
"https://zaifu.fun",
"https://zaifu.site"
],
Expand Down
53 changes: 44 additions & 9 deletions src/rust/zh.boylove/src/helper/url.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use aidoku::{
helpers::uri::{encode_uri_component, QueryParameters},
prelude::format,
std::{net::Request, String, Vec},
std::{current_date, net::Request, String, Vec},
Filter, FilterType,
};
use alloc::{borrow::ToOwned as _, string::ToString as _};
use alloc::string::ToString as _;
use core::fmt::{Display, Formatter, Result as FmtResult};
use strum_macros::{Display, FromRepr};

Expand Down Expand Up @@ -56,9 +56,6 @@ pub enum Url<'a> {

#[strum(to_string = "/home/book/capter/id/{id}")]
ChapterPage { id: &'a str },

#[strum(to_string = "/chapter_view_template?{query}")]
Chapter { query: ChapterQuery },
}

impl Url<'_> {
Expand Down Expand Up @@ -163,6 +160,40 @@ pub enum Charset {
Traditional,
}

#[derive(Display)]
#[strum(prefix = "https://xxblapingpong.cc")]
pub enum Api {
#[strum(to_string = "/chapter_view_template?{0}")]
Chapter(ChapterQuery),
}

impl Api {
pub fn chapter(id: &str) -> Self {
let query = ChapterQuery::new(id);

Self::Chapter(query)
}

pub fn get(&self) -> Request {
#[expect(clippy::cast_possible_truncation, clippy::as_conversions)]
let now = current_date() as i64;
let token_parameter = format!("{now},1.1.0");

let token = format!("{now}18comicAPPContent");
let token_digest = md5::compute(token);
let token_hash = format!("{token_digest:x}");

Request::get(self.to_string())
.header(
"User-Agent",
"Mozilla/5.0 (iPad; CPU OS 18_2 like Mac OS X) \
AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148",
)
.header("Tokenparam", &token_parameter)
.header("Token", &token_hash)
}
}

pub struct Index {
page: i32,
}
Expand Down Expand Up @@ -197,6 +228,8 @@ impl Display for LastUpdatedQuery {

query.push_encoded("widx", Some("11"));

query.push_encoded("limit", Some("18"));

let index = Index::from_page(self.page).to_string();
query.push_encoded("page", Some(&index));

Expand All @@ -209,17 +242,19 @@ pub struct ChapterQuery {
}

impl ChapterQuery {
pub fn new<S: AsRef<str>>(id: S) -> Self {
Self {
id: id.as_ref().to_owned(),
}
pub fn new(id: &str) -> Self {
Self { id: id.into() }
}
}

impl Display for ChapterQuery {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let mut query = QueryParameters::new();
query.push_encoded("id", Some(&self.id));
query.push_encoded("sw_page", Some("null"));
query.push_encoded("mode", Some("vertical"));
query.push_encoded("page", Some("0"));
query.push_encoded("app_img_shunt", Some("NaN"));

write!(f, "{query}")
}
Expand Down
6 changes: 3 additions & 3 deletions src/rust/zh.boylove/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use aidoku::{
use alloc::{borrow::ToOwned as _, string::ToString as _};
use helper::{
setting::change_charset,
url::{ChapterQuery, DefaultRequest as _, Index, LastUpdatedQuery, Url},
url::{Api, DefaultRequest as _, Index, LastUpdatedQuery, Url},
MangaList as _, MangaListRes as _, Part, Regex,
};

Expand Down Expand Up @@ -229,10 +229,10 @@ fn get_chapter_list(manga_id: String) -> Result<Vec<Chapter>> {
Ok(chapters)
}

#[expect(clippy::needless_pass_by_value)]
#[get_page_list]
fn get_page_list(_manga_id: String, chapter_id: String) -> Result<Vec<Page>> {
let query = ChapterQuery::new(chapter_id);
let pages = Url::Chapter { query }
let pages = Api::chapter(&chapter_id)
.get()
.html()?
.select("img.lazy")
Expand Down

0 comments on commit 276adef

Please sign in to comment.