mirror of
https://github.com/p-stream/p-stream.git
synced 2026-04-19 18:32:06 +00:00
simplify advanced search since it was broken
This commit is contained in:
parent
5c9f8eea8a
commit
a16c84023f
2 changed files with 3 additions and 61 deletions
|
|
@ -7,8 +7,6 @@ import {
|
|||
getMediaDetails,
|
||||
getMediaPoster,
|
||||
multiSearch,
|
||||
searchMovies,
|
||||
searchTVShows,
|
||||
} from "./tmdb";
|
||||
import { TMDBContentTypes } from "./types/tmdb";
|
||||
|
||||
|
|
@ -25,12 +23,6 @@ cache.initialize();
|
|||
// detect "tmdb:123456" or "tmdb:123456:movie" or "tmdb:123456:tv"
|
||||
const tmdbIdPattern = /^tmdb:(\d+)(?::(movie|tv))?$/i;
|
||||
|
||||
// detect "year:YYYY"
|
||||
const yearPattern = /(.+?)\s+year:(\d{4})$/i;
|
||||
|
||||
// detect "type:movie" or "type:tv"
|
||||
const typePattern = /(.+?)\s+type:(movie|tv)$/i;
|
||||
|
||||
export async function searchForMedia(query: MWQuery): Promise<MediaItem[]> {
|
||||
if (cache.has(query)) return cache.get(query) as MediaItem[];
|
||||
const { searchQuery } = query;
|
||||
|
|
@ -77,48 +69,13 @@ export async function searchForMedia(query: MWQuery): Promise<MediaItem[]> {
|
|||
}
|
||||
}
|
||||
|
||||
// year extract logic
|
||||
let yearValue: string | undefined;
|
||||
let queryWithoutYear = searchQuery;
|
||||
const data = await multiSearch(searchQuery);
|
||||
|
||||
const yearMatch = searchQuery.match(yearPattern);
|
||||
if (yearMatch && yearMatch[2]) {
|
||||
queryWithoutYear = yearMatch[1].trim();
|
||||
yearValue = yearMatch[2];
|
||||
}
|
||||
|
||||
// type extract logic
|
||||
let typeValue: string | undefined;
|
||||
let queryWithoutType = queryWithoutYear;
|
||||
|
||||
const typeMatch = queryWithoutYear.match(typePattern);
|
||||
if (typeMatch && typeMatch[2]) {
|
||||
queryWithoutType = typeMatch[1].trim();
|
||||
typeValue = typeMatch[2].toLowerCase();
|
||||
}
|
||||
|
||||
let data: any[];
|
||||
if (typeValue === "movie") {
|
||||
data = await searchMovies(queryWithoutType);
|
||||
} else if (typeValue === "tv") {
|
||||
data = await searchTVShows(queryWithoutType);
|
||||
} else {
|
||||
data = await multiSearch(queryWithoutType);
|
||||
}
|
||||
|
||||
let results = data.map((v) => {
|
||||
const results = data.map((v) => {
|
||||
const formattedResult = formatTMDBSearchResult(v, v.media_type);
|
||||
return formatTMDBMetaToMediaItem(formattedResult);
|
||||
});
|
||||
|
||||
// filter year
|
||||
if (yearValue) {
|
||||
results = results.filter((item) => {
|
||||
const releaseYear = item.release_date?.getFullYear().toString();
|
||||
return releaseYear === yearValue;
|
||||
});
|
||||
}
|
||||
|
||||
const movieWithPosters = results.filter((movie) => movie.poster);
|
||||
const movieWithoutPosters = results.filter((movie) => !movie.poster);
|
||||
|
||||
|
|
|
|||
|
|
@ -104,24 +104,9 @@ export const SearchBarInput = forwardRef<HTMLInputElement, SearchBarProps>(
|
|||
{showTooltip && !props.hideTooltip && (
|
||||
<div className="py-4">
|
||||
<p className="font-bold text-sm mb-1 text-search-text">
|
||||
Advanced Search:
|
||||
Search:
|
||||
</p>
|
||||
<div className="space-y-1.5 text-xs text-search-text">
|
||||
<div>
|
||||
<p className="mb-0.5">Year search:</p>
|
||||
<p className="text-type-secondary italic pl-2">
|
||||
Inception year:2010
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="mb-0.5">Type search:</p>
|
||||
<p className="text-type-secondary italic pl-2">
|
||||
Marvel type:movie
|
||||
</p>
|
||||
<p className="text-type-secondary italic pl-2">
|
||||
Friends type:tv
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="mb-0.5">TMDB ID search:</p>
|
||||
<p className="text-type-secondary italic pl-2">
|
||||
|
|
|
|||
Loading…
Reference in a new issue