Phase 1 — Foundation
Mirror NPE's dependency-free spine in Rust:
* exceptions — NetworkError + ParsingError + ContentUnavailable
+ ExtractionError tree, with reqwest/serde_json conversions
* localization — Localization + ContentCountry, default (en, GB)
* downloader/ — Downloader trait, Request builder, Response,
reqwest blocking default impl
* page — continuation-token carrier
* image — Image + ImageSet + ResolutionLevel
(HEIGHT_UNKNOWN/WIDTH_UNKNOWN = -1)
* metainfo — title/content/url/url_text grab-bag
* service — StreamingService trait + LinkType + ServiceInfo
* newpipe — process-global Downloader / Localization /
ContentCountry singleton
Foundational invariants nailed down (per SPEC §3):
* HTTP non-2xx returns Ok(Response); only 429 throws NetworkError::Recaptcha
* Response header keys lowercase-normalized
* Request.add_header PARITY with NPE bug (silent overwrite);
append_header is our clean addition
* default Localization is en-GB
* No cookie jar in the default downloader
Tests: 7 unit + 7 live smoke against httpbin.org (gated on
'online-tests' feature). All green.
This commit is contained in:
parent
6340b54ad3
commit
2a2367a3d0
16 changed files with 2689 additions and 1 deletions
79
src/page.rs
Normal file
79
src/page.rs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
// Page — continuation token carrier. Mirrors NPE Page.java.
|
||||
//
|
||||
// Used everywhere "the next page" is paginated through an opaque token
|
||||
// (search results, channel videos, playlist videos, comments). The fields
|
||||
// are deliberately a grab-bag — NPE callers stuff whatever they need to
|
||||
// resume.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Page {
|
||||
url: Option<String>,
|
||||
id: Option<String>,
|
||||
ids: Vec<String>,
|
||||
body: Option<Vec<u8>>,
|
||||
cookies: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl Page {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn with_url(url: impl Into<String>) -> Self {
|
||||
Self { url: Some(url.into()), ..Self::default() }
|
||||
}
|
||||
|
||||
pub fn url(&self) -> Option<&str> {
|
||||
self.url.as_deref()
|
||||
}
|
||||
|
||||
pub fn set_url(&mut self, url: Option<String>) -> &mut Self {
|
||||
self.url = url;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn id(&self) -> Option<&str> {
|
||||
self.id.as_deref()
|
||||
}
|
||||
|
||||
pub fn set_id(&mut self, id: Option<String>) -> &mut Self {
|
||||
self.id = id;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn ids(&self) -> &[String] {
|
||||
&self.ids
|
||||
}
|
||||
|
||||
pub fn set_ids(&mut self, ids: Vec<String>) -> &mut Self {
|
||||
self.ids = ids;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn body(&self) -> Option<&[u8]> {
|
||||
self.body.as_deref()
|
||||
}
|
||||
|
||||
pub fn set_body(&mut self, body: Option<Vec<u8>>) -> &mut Self {
|
||||
self.body = body;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn cookies(&self) -> &BTreeMap<String, String> {
|
||||
&self.cookies
|
||||
}
|
||||
|
||||
pub fn set_cookies(&mut self, cookies: BTreeMap<String, String>) -> &mut Self {
|
||||
self.cookies = cookies;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn is_valid(&self) -> bool {
|
||||
self.url.as_deref().map(|s| !s.is_empty()).unwrap_or(false)
|
||||
|| self.id.as_deref().map(|s| !s.is_empty()).unwrap_or(false)
|
||||
|| !self.ids.is_empty()
|
||||
|| self.body.as_ref().map(|b| !b.is_empty()).unwrap_or(false)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue