Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
syrflover committed Sep 8, 2024
1 parent 145c66d commit f740c35
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 12 deletions.
32 changes: 20 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@ name = "transmission-rss"
version = "0.1.0"
edition = "2021"

[features]
anissia = ["dep:tl", "dep:chrono", "dep:bytes"]

[dependencies]
# trname = { path = "../trname" }
trname = { git = "https://github.com/syrflover/trname", rev = "3eee979" }
trname = { git = "https://github.com/syrflover/trname", rev = "3becf44" }

chrono = { version = "0.4", features = ["serde"], optional = true }
bytes = { version = "1.7.1", optional = true }
tl = { version = "0.7.8", optional = true }

dotenv = "0.15.0"
futures = "0.3.30"
reqwest = "0.12.5"
rss = { version = "2.0.8", features = ["serde"] }
serde = "1.0.203"
serde_json = "1.0.120"
serde_yml = "0.0.11"
thiserror = "1.0.61"
tokio = { version = "1.38.0", features = ["rt-multi-thread", "macros"] }
transmission-rpc = "0.4.2"
url = "2.5.2"
dotenv = "0.15"
futures = "0.3"
reqwest = "0.12"
rss = { version = "2.0.9", features = ["serde"] }
serde = "1.0"
serde_json = "1.0"
serde_yml = "0.0.12"
thiserror = "1.0"
tokio = { version = "1.40", features = ["rt-multi-thread", "macros"] }
transmission-rpc = "0.4"
tap = "1.0.1"
url = "2.5"
119 changes: 119 additions & 0 deletions src/anissia.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use std::fmt::Debug;

use bytes::Bytes;
use chrono::{DateTime, Local};
use reqwest::StatusCode;
use serde::Deserialize;
use tap::Pipe;
use tl::ParserOptions;

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("reqwest: {0}")]
Reqwest(#[from] reqwest::Error),

#[error("tl: {0}")]
Tl(#[from] tl::ParseError),

#[error("status: {0} - {1}")]
Status(StatusCode, String),
}

mod sealed {
use std::fmt::Debug;

use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub(super) struct ResponseDataInner<T: Debug> {
pub content: T,
}
}

#[derive(Debug, Deserialize)]
struct ResponseData<T: Debug> {
pub data: sealed::ResponseDataInner<T>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CaptionInfo {
pub anime_no: u32,
pub subject: String,
pub episode: String,
#[serde(rename = "updDt")]
pub updated_at: DateTime<Local>,
pub website: String,
#[serde(rename = "name")]
pub translator: String,
}

impl CaptionInfo {
pub async fn download(&self, selector: &str) -> Result<Option<Bytes>, Error> {
let website_resp = reqwest::get(&self.website).await?;

if !website_resp.status().is_success() {
return Err(Error::Status(
website_resp.status(),
website_resp.text().await.unwrap_or_default(),
));
}

let website = website_resp.text().await?;

let dom = tl::parse(&website, ParserOptions::default())?;

let parser = dom.parser();

let element = match dom
.query_selector(selector)
.and_then(|r| r.next()?.get(&parser)?.as_tag()?.pipe(Some))
{
Some(r) => r,
None => return Ok(None),
};

let href = match element
.attributes()
.get("href")
.and_then(|r| String::from_utf8(r?.as_bytes().to_vec()).ok())
{
Some(r) => r,
None => return Ok(None),
};

let resp = reqwest::get(&href).await?;

Ok()
}
}

// TODO: https://github.com/dhku/SMI-Auto-Downloader/blob/main/subs.py

struct GoogleDrive {}

impl GoogleDrive {
pub async fn download(url: &str) -> Result<Bytes, Error> {}
}

const ANISSIA_URL: &str = "https://api.anissia.net";

// https://api.anissia.net/anime/caption/recent/0
// res_json.data.content

pub async fn get_recent_captions(page: usize) -> Result<Vec<CaptionInfo>, Error> {
let url = format!("{}/anime/caption/recent/{}", ANISSIA_URL, page);

let resp = reqwest::get(url).await?;

if !resp.status().is_success() {
return Err(Error::Status(
resp.status(),
resp.text().await.unwrap_or_default(),
));
}

let res = resp.json::<ResponseData<Vec<CaptionInfo>>>().await?;

Ok(res.data.content)
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#[cfg(feature = "anissia")]
pub mod anissia;
pub mod config;
pub mod rule;

0 comments on commit f740c35

Please sign in to comment.