Skip to content

Commit

Permalink
Bumping version
Browse files Browse the repository at this point in the history
  • Loading branch information
ForgQi committed Apr 22, 2024
1 parent 5b74de4 commit 8688dbe
Show file tree
Hide file tree
Showing 9 changed files with 411 additions and 465 deletions.
793 changes: 361 additions & 432 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions crates/biliup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9.17"
serde_urlencoded = "0.7"
reqwest_cookie_store = "0.6.0"
reqwest_cookie_store = "0.7.0"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "local-time"] }
Expand All @@ -34,8 +34,8 @@ cookie = "0.17.0"
bytes = "1.1.0"
futures = "0.3.17"
typed-builder = "0.18.0"
reqwest-middleware = "0.2.0"
reqwest-retry = "0.3.0"
reqwest-middleware = { version = "0.3.0", features = ["json"] }
reqwest-retry = "0.5.0"
clap = { version = "4", features = ["derive"] }
time = "0.3"
anyhow = "1.0"
Expand All @@ -54,12 +54,15 @@ async-trait = "0.1.57"
humantime = "2.1.0"
axum = { version = "0.7.3", optional = true }
tower-http = { version = "0.5.0", features = ["cors"], optional = true }
reqwest = { version = "0.11", default-features = false, features = ["json", "stream", "blocking", "deflate", "gzip", "rustls-tls"] }
reqwest = { version = "0.12", default-features = false, features = ["json", "stream", "blocking", "deflate", "gzip", "rustls-tls"] }
sqlx = { version = "0.7", features = [ "runtime-tokio-rustls", "sqlite" ], optional = true }

[build-dependencies]
native-tls = { version = "0.2.11", features = ["vendored"] }
openssl = { version = "0.10.42", features = ["vendored"] }

[target.'cfg(target_family = "unix")'.dependencies]
jemallocator = { version = "0.5", features = ["disable_initial_exec_tls"] }

[features]
server = ["indexmap", "axum", "tower-http", "sqlx"]
7 changes: 5 additions & 2 deletions crates/biliup/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use futures::Stream;

#[cfg(target_family = "unix")]
use jemallocator::Jemalloc;
use rand::distributions::uniform::{UniformFloat, UniformSampler};
use std::future::Future;
use std::time::Duration;
use tokio::time::sleep;
use tracing::info;

#[global_allocator]
#[cfg(target_family = "unix")]
static ALLOC: Jemalloc = Jemalloc;
pub mod client;
pub mod downloader;
pub mod error;
Expand Down
8 changes: 5 additions & 3 deletions crates/biliup/src/uploader/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,17 @@ impl Credential {
form["sign"] = Value::from(sign);
loop {
tokio::time::sleep(Duration::from_secs(1)).await;
let res: ResponseData<ResponseValue> = self
let raw = self
.0
.client
.post("http://passport.bilibili.com/x/passport-tv-login/qrcode/poll")
.form(&form)
.send()
.await?
.json()
.await?;
.error_for_status()?;
let full = raw.bytes().await?;

let res: ResponseData<ResponseValue> = serde_json::from_slice(&full).map_err(|e| Kind::Custom(format!("error decoding response body, content: {:#?}", String::from_utf8_lossy(&full))))?;

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (x86_64-linux)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (x86_64-linux)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (arm-linux)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (arm-linux)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (x86_64-linux-musl)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (x86_64-linux-musl)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (aarch64-linux)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (aarch64-linux)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (x86_64-windows)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (x86_64-windows)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (aarch64-macos)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (x86_64-macos)

unused variable: `e`

Check warning on line 427 in crates/biliup/src/uploader/credential.rs

View workflow job for this annotation

GitHub Actions / Dist (x86_64-macos)

unused variable: `e`
match res {
ResponseData {
code: 0,
Expand Down
4 changes: 2 additions & 2 deletions crates/stream-gears/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stream-gears"
version = "0.1.21"
version = "0.1.22"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -9,7 +9,7 @@ name = "stream_gears"
crate-type = ["cdylib", "lib"]

[dependencies]
pyo3 = { version = "0.20.0", features = ["abi3-py38"] }
pyo3 = { version = "0.21.0", features = ["abi3-py38"] }
serde = "1"
serde_json = "1.0"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
26 changes: 13 additions & 13 deletions crates/stream-gears/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::uploader::UploadLine;
use biliup::downloader::construct_headers;
use biliup::downloader::util::Segmentable;
use tracing_subscriber::layer::SubscriberExt;
use biliup::credential::Credential;

#[derive(FromPyObject)]
pub enum PySegment {
Expand Down Expand Up @@ -73,9 +74,9 @@ fn download(
})
}
#[pyfunction]
fn login_by_cookies() -> PyResult<bool> {
fn login_by_cookies(file: String) -> PyResult<bool> {
let rt = tokio::runtime::Runtime::new().unwrap();
let result = rt.block_on(async { login::login_by_cookies().await });
let result = rt.block_on(async { login::login_by_cookies(&file).await });
match result {
Ok(_) => Ok(true),
Err(err) => Err(pyo3::exceptions::PyRuntimeError::new_err(format!(
Expand Down Expand Up @@ -120,17 +121,16 @@ fn get_qrcode() -> PyResult<String> {
}
}
#[pyfunction]
fn login_by_qrcode(ret: String) -> PyResult<bool> {
fn login_by_qrcode(ret: String) -> PyResult<String> {
let rt = tokio::runtime::Runtime::new().unwrap();
let result =
rt.block_on(async { login::login_by_qrcode(serde_json::from_str(&ret).unwrap()).await });
match result {
Ok(_) => Ok(true),
Err(err) => Err(pyo3::exceptions::PyRuntimeError::new_err(format!(
"{}",
err
))),
}
rt.block_on(async {
let info = Credential::new().login_by_qrcode(serde_json::from_str(&ret).unwrap()).await?;
let res = serde_json::to_string_pretty(&info)?;
Ok::<_, anyhow::Error>(res)
}).map_err(|err| pyo3::exceptions::PyRuntimeError::new_err(format!(
"{:#?}",
err
)))
}
#[pyfunction]
fn login_by_web_cookies(sess_data: String, bili_jct: String) -> PyResult<bool> {
Expand Down Expand Up @@ -242,7 +242,7 @@ fn upload(

/// A Python module implemented in Rust.
#[pymodule]
fn stream_gears(py: Python, m: &PyModule) -> PyResult<()> {
fn stream_gears(m: &Bound<'_, PyModule>) -> PyResult<()> {
// let file_appender = tracing_appender::rolling::daily("", "upload.log");
// let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
// tracing_subscriber::fmt()
Expand Down
10 changes: 2 additions & 8 deletions crates/stream-gears/src/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use anyhow::Result;
use biliup::uploader::bilibili::BiliBili;
use biliup::uploader::credential::Credential;

pub async fn login_by_cookies() -> Result<BiliBili> {
let login_info = biliup::uploader::credential::login_by_cookies("cookies.json").await?;
pub async fn login_by_cookies(file: &str) -> Result<BiliBili> {
let login_info = biliup::uploader::credential::login_by_cookies(file).await?;
Ok(login_info)
}

Expand All @@ -23,12 +23,6 @@ pub async fn get_qrcode() -> Result<serde_json::Value> {
let qrcode = Credential::new().get_qrcode().await?;
Ok(qrcode)
}
pub async fn login_by_qrcode(res: serde_json::Value) -> Result<bool> {
let info = Credential::new().login_by_qrcode(res).await?;
let file = std::fs::File::create("cookies.json")?;
serde_json::to_writer_pretty(&file, &info)?;
Ok(true)
}

pub async fn login_by_web_cookies(sess_data: &str, bili_jct: &str) -> Result<bool> {
let info = Credential::new()
Expand Down
10 changes: 10 additions & 0 deletions crates/stream-gears/tests/login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import json

import stream_gears
if __name__ == '__main__':
res = stream_gears.get_qrcode()
print(res)
res = stream_gears.login_by_qrcode(res)
with open(f'{json.loads(res)["token_info"]["mid"]}.json', 'w', encoding='utf-8') as file:
file.write(res)
print(res)
7 changes: 6 additions & 1 deletion crates/stream-gears/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
"desc",
"dynamic",
"",
0,
0,
0,
0,
3,
[],
None,
stream_gears.UploadLine.Bda2,
3,
)

0 comments on commit 8688dbe

Please sign in to comment.