dynamic base url

This commit is contained in:
Simon
2026-03-10 18:45:32 +00:00
parent 2ad131f38f
commit 96926563b8
10 changed files with 118 additions and 43 deletions

View File

@@ -80,7 +80,8 @@ impl NoodlemagazineProvider {
.await
.unwrap_or_default();
let items = self.get_video_items_from_html(text);
let proxy_base_url = options.public_url_base.as_deref().unwrap_or_default();
let items = self.get_video_items_from_html(text, proxy_base_url);
if items.is_empty() {
Ok(old_items)
@@ -117,7 +118,8 @@ impl NoodlemagazineProvider {
.await
.unwrap_or_default();
let items = self.get_video_items_from_html(text);
let proxy_base_url = options.public_url_base.as_deref().unwrap_or_default();
let items = self.get_video_items_from_html(text, proxy_base_url);
if items.is_empty() {
Ok(old_items)
@@ -128,7 +130,7 @@ impl NoodlemagazineProvider {
}
}
fn get_video_items_from_html(&self, html: String) -> Vec<VideoItem> {
fn get_video_items_from_html(&self, html: String, proxy_base_url: &str) -> Vec<VideoItem> {
if html.is_empty() || html.contains("404 Not Found") {
return vec![];
}
@@ -148,21 +150,29 @@ impl NoodlemagazineProvider {
list.split("<div class=\"item\">")
.skip(1)
.filter_map(|segment| self.get_video_item(segment.to_string()).ok())
.filter_map(|segment| self.get_video_item(segment.to_string(), proxy_base_url).ok())
.collect()
}
fn proxy_url(&self, video_url: &str) -> String {
fn proxy_url(&self, proxy_base_url: &str, video_url: &str) -> String {
let target = video_url
.strip_prefix("https://")
.or_else(|| video_url.strip_prefix("http://"))
.unwrap_or(video_url)
.trim_start_matches('/');
format!("https://hottub.spacemoehre.de/proxy/noodlemagazine/{target}")
if proxy_base_url.is_empty() {
return format!("/proxy/noodlemagazine/{target}");
}
format!(
"{}/proxy/noodlemagazine/{}",
proxy_base_url.trim_end_matches('/'),
target
)
}
fn get_video_item(&self, video_segment: String) -> Result<VideoItem> {
fn get_video_item(&self, video_segment: String, proxy_base_url: &str) -> Result<VideoItem> {
let href = video_segment
.split("<a href=\"")
.nth(1)
@@ -212,7 +222,7 @@ impl NoodlemagazineProvider {
.and_then(|s| s.split('<').next())
.and_then(|v| parse_abbreviated_number(v.trim()))
.unwrap_or(0);
let proxy_url = self.proxy_url(&video_url);
let proxy_url = self.proxy_url(proxy_base_url, &video_url);
Ok(VideoItem::new(
id,
@@ -273,8 +283,11 @@ mod tests {
let provider = NoodlemagazineProvider::new();
assert_eq!(
provider.proxy_url("https://noodlemagazine.com/watch/-123_456"),
"https://hottub.spacemoehre.de/proxy/noodlemagazine/noodlemagazine.com/watch/-123_456"
provider.proxy_url(
"https://example.com",
"https://noodlemagazine.com/watch/-123_456"
),
"https://example.com/proxy/noodlemagazine/noodlemagazine.com/watch/-123_456"
);
}
@@ -294,12 +307,12 @@ mod tests {
>Show more</div>
"#;
let items = provider.get_video_items_from_html(html.to_string());
let items = provider.get_video_items_from_html(html.to_string(), "https://example.com");
assert_eq!(items.len(), 1);
assert_eq!(
items[0].url,
"https://hottub.spacemoehre.de/proxy/noodlemagazine/noodlemagazine.com/watch/-123_456"
"https://example.com/proxy/noodlemagazine/noodlemagazine.com/watch/-123_456"
);
assert_eq!(items[0].formats.as_ref().map(|f| f.len()), Some(1));
}