xgroovy: resolve pornstar/channel names without prefix
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use crate::DbPool;
|
||||
use crate::api::ClientVersion;
|
||||
use crate::providers::{Provider, report_provider_error, requester_or_default};
|
||||
use crate::providers::{
|
||||
Provider, probe_first_archive, report_provider_error, requester_or_default, slug_dashed,
|
||||
};
|
||||
use crate::status::*;
|
||||
use crate::util::cache::VideoCache;
|
||||
use crate::videos::{ServerOptions, VideoItem};
|
||||
@@ -426,6 +428,23 @@ impl XgroovyProvider {
|
||||
Target::Search(trimmed.to_string())
|
||||
}
|
||||
|
||||
/// A free-form query that names a pornstar or a channel goes to that
|
||||
/// archive (probed on the site; unknown names 404), else keyword search.
|
||||
async fn resolve_keyword(query: &str, options: &ServerOptions) -> Option<Target> {
|
||||
let slug = slug_dashed(query);
|
||||
if slug.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let candidates = [Target::Pornstar(slug.clone()), Target::Channel(slug)];
|
||||
let urls: Vec<String> = candidates.iter().map(|t| Self::target_url(t, 1)).collect();
|
||||
let mut requester = requester_or_default(options, CHANNEL_ID, "resolve_keyword");
|
||||
let (index, _) = probe_first_archive(&mut requester, &urls, &format!("{BASE_URL}/"), |body| {
|
||||
body.contains("data-video-id")
|
||||
})
|
||||
.await?;
|
||||
candidates.into_iter().nth(index)
|
||||
}
|
||||
|
||||
fn resolve_option_target(&self, options: &ServerOptions) -> Target {
|
||||
if let Some(cat) = options.categories.as_deref() {
|
||||
if cat != "all" && !cat.is_empty() {
|
||||
@@ -488,10 +507,15 @@ impl Provider for XgroovyProvider {
|
||||
let page = page.parse::<u16>().unwrap_or(1).max(1);
|
||||
let per_page = per_page.parse::<usize>().unwrap_or(10).clamp(1, 60);
|
||||
|
||||
let target = match query {
|
||||
let mut target = match query {
|
||||
Some(q) if !q.trim().is_empty() => self.resolve_query_target(q.trim()),
|
||||
_ => self.resolve_option_target(&options),
|
||||
};
|
||||
if let Target::Search(query) = &target {
|
||||
if let Some(found) = Self::resolve_keyword(query, &options).await {
|
||||
target = found;
|
||||
}
|
||||
}
|
||||
|
||||
match self
|
||||
.fetch_target(cache, target, page, per_page, options)
|
||||
|
||||
Reference in New Issue
Block a user