pimpbunny thumb
This commit is contained in:
@@ -15,6 +15,7 @@ use htmlentity::entity::{ICodedDataTrait, decode};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::{thread, vec};
|
||||
use titlecase::Titlecase;
|
||||
use url::Url;
|
||||
use wreq::Version;
|
||||
|
||||
error_chain! {
|
||||
@@ -167,6 +168,32 @@ impl PimpbunnyProvider {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_allowed_thumb_url(url: &str) -> bool {
|
||||
let Some(url) = Url::parse(url).ok() else {
|
||||
return false;
|
||||
};
|
||||
if url.scheme() != "https" {
|
||||
return false;
|
||||
}
|
||||
let Some(host) = url.host_str() else {
|
||||
return false;
|
||||
};
|
||||
matches!(host, "pimpbunny.com" | "www.pimpbunny.com")
|
||||
&& url.path().starts_with("/contents/videos_screenshots/")
|
||||
}
|
||||
|
||||
fn proxied_thumb(&self, options: &ServerOptions, thumb: &str) -> String {
|
||||
if thumb.is_empty() || !Self::is_allowed_thumb_url(thumb) {
|
||||
return thumb.to_string();
|
||||
}
|
||||
|
||||
crate::providers::build_proxy_url(
|
||||
options,
|
||||
"pimpbunny-thumb",
|
||||
&crate::providers::strip_url_scheme(thumb),
|
||||
)
|
||||
}
|
||||
|
||||
async fn load_stars(base: &str, stars: Arc<RwLock<Vec<FilterOption>>>) -> Result<()> {
|
||||
let mut requester = Requester::new();
|
||||
let text = requester
|
||||
@@ -558,6 +585,7 @@ impl Provider for PimpbunnyProvider {
|
||||
options: ServerOptions,
|
||||
) -> Vec<VideoItem> {
|
||||
let page = page.parse::<u8>().unwrap_or(1);
|
||||
let thumb_options = options.clone();
|
||||
|
||||
let res = match query {
|
||||
Some(q) => self.to_owned().query(cache, page, &q, options).await,
|
||||
@@ -568,9 +596,53 @@ impl Provider for PimpbunnyProvider {
|
||||
eprintln!("pimpbunny error: {e}");
|
||||
vec![]
|
||||
})
|
||||
.into_iter()
|
||||
.map(|mut item| {
|
||||
if !item.thumb.is_empty() {
|
||||
item.thumb = self.proxied_thumb(&thumb_options, &item.thumb);
|
||||
}
|
||||
item
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn get_channel(&self, v: ClientVersion) -> Option<Channel> {
|
||||
Some(self.build_channel(v))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::PimpbunnyProvider;
|
||||
use crate::videos::ServerOptions;
|
||||
|
||||
#[test]
|
||||
fn rewrites_allowed_thumbs_to_proxy_urls() {
|
||||
let provider = PimpbunnyProvider::new();
|
||||
let options = ServerOptions {
|
||||
featured: None,
|
||||
category: None,
|
||||
sites: None,
|
||||
filter: None,
|
||||
language: None,
|
||||
public_url_base: Some("https://example.com".to_string()),
|
||||
requester: None,
|
||||
network: None,
|
||||
stars: None,
|
||||
categories: None,
|
||||
duration: None,
|
||||
sort: None,
|
||||
sexuality: None,
|
||||
};
|
||||
|
||||
let proxied = provider.proxied_thumb(
|
||||
&options,
|
||||
"https://pimpbunny.com/contents/videos_screenshots/517000/517329/800x450/1.jpg",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
proxied,
|
||||
"https://example.com/proxy/pimpbunny-thumb/pimpbunny.com/contents/videos_screenshots/517000/517329/800x450/1.jpg"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user