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.
53 lines
1.1 KiB
Rust
53 lines
1.1 KiB
Rust
// MetaInfo — mirrors NPE MetaInfo.java.
|
|
//
|
|
// Carries "info card" style data (knowledge-panel boxes, COVID/election
|
|
// warning banners, etc.) attached to a stream or search result. Paired URLs
|
|
// + URL texts — same indices.
|
|
|
|
use url::Url;
|
|
|
|
#[derive(Clone, Debug, Default)]
|
|
pub struct MetaInfo {
|
|
title: String,
|
|
content: String,
|
|
urls: Vec<Url>,
|
|
url_texts: Vec<String>,
|
|
}
|
|
|
|
impl MetaInfo {
|
|
pub fn new() -> Self {
|
|
Self::default()
|
|
}
|
|
|
|
pub fn title(&self) -> &str {
|
|
&self.title
|
|
}
|
|
|
|
pub fn set_title(&mut self, title: impl Into<String>) -> &mut Self {
|
|
self.title = title.into();
|
|
self
|
|
}
|
|
|
|
pub fn content(&self) -> &str {
|
|
&self.content
|
|
}
|
|
|
|
pub fn set_content(&mut self, content: impl Into<String>) -> &mut Self {
|
|
self.content = content.into();
|
|
self
|
|
}
|
|
|
|
pub fn urls(&self) -> &[Url] {
|
|
&self.urls
|
|
}
|
|
|
|
pub fn url_texts(&self) -> &[String] {
|
|
&self.url_texts
|
|
}
|
|
|
|
pub fn add_url(&mut self, url: Url, text: impl Into<String>) -> &mut Self {
|
|
self.urls.push(url);
|
|
self.url_texts.push(text.into());
|
|
self
|
|
}
|
|
}
|