Refactor segment handling and SubmitOption parsing

Replaces the custom Segment class in Python with the PySegment class from Rust, and exposes PySegment to Python via PyO3. Refactors SubmitOption to implement FromStr for string parsing, updating usage accordingly. These changes improve interoperability between Python and Rust components and standardize enum parsing.

Bump stream-gears version to 1.0.5

Updated the stream-gears crate version from 1.0.4 to 1.0.5 in Cargo.toml and Cargo.lock to prepare for a new release.
This commit is contained in:
ForgQi committed 2025-08-08 02:02:01 +08:00
1 parent 4d992c3486
commit 35024feaa7
6 files changed
+26 -11

No files matched your search

Generated
+1 -1
View File
@@ -5289,7 +5289,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "stream-gears"
version = "1.0.4"
version = "1.0.5"
dependencies = [
"anyhow",
"biliup",
+1 -3
View File
@@ -542,10 +542,8 @@ class DownloadBase(ABC):
def stream_gears_download(url, headers, file_name, segment_time=None, file_size=None,
file_name_callback: Callable[[str], None] = None):
class Segment:
pass
segment = Segment()
segment = stream_gears.PySegment()
if segment_time:
seg_time = segment_time.split(':')
# print(int(seg_time[0]) * 60 * 60 + int(seg_time[1]) * 60 + int(seg_time[2]))
+5 -2
View File
@@ -1,3 +1,4 @@
use std::str::FromStr;
#[cfg(feature = "cli")]
use clap::ValueEnum;
@@ -10,9 +11,11 @@ pub enum SubmitOption {
BCutAndroid,
}
impl SubmitOption {
impl FromStr for SubmitOption {
type Err = String;
/// Parse a string into SubmitOption, compatible with both clap and manual parsing
pub fn parse_str(s: &str) -> Result<Self, String> {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"app" => Ok(SubmitOption::App),
"bcutandroid" | "b-cut-android" | "bcut_android" => Ok(SubmitOption::BCutAndroid),
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "stream-gears"
version = "1.0.4"
version = "1.0.5"
edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+16 -3
View File
@@ -17,14 +17,26 @@ use biliup::downloader::util::Segmentable;
use tracing_subscriber::layer::SubscriberExt;
#[derive(FromPyObject, Debug)]
#[derive(Debug, Clone)]
#[pyclass(set_all)]
pub struct PySegment {
#[pyo3(attribute("time"))]
// #[pyo3(attribute("time"))]
time: Option<u64>,
#[pyo3(attribute("size"))]
// #[pyo3(attribute("size"))]
size: Option<u64>,
}
#[pymethods]
impl PySegment {
#[new]
fn new() -> Self {
PySegment{
time: None,
size: None,
}
}
}
#[pyfunction]
#[pyo3(signature = (url,header_map,file_name,segment,proxy = None))]
fn download(
@@ -347,6 +359,7 @@ fn stream_gears(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(login_by_web_cookies, m)?)?;
m.add_function(wrap_pyfunction!(login_by_web_qrcode, m)?)?;
m.add_class::<UploadLine>()?;
m.add_class::<PySegment>()?;
Ok(())
}
+2 -1
View File
@@ -12,6 +12,7 @@ use pyo3::pyclass;
use std::collections::HashMap;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Instant;
use tracing::info;
@@ -190,7 +191,7 @@ pub async fn upload(studio_pre: StudioPre, submit: Option<&str>, proxy: Option<&
}
let submit = match submit {
Some(submit) => SubmitOption::parse_str(submit).unwrap_or(SubmitOption::App),
Some(submit) => SubmitOption::from_str(submit).unwrap_or(SubmitOption::App),
_ => SubmitOption::App,
};