mirror of
https://github.com/p-stream/p-stream.git
synced 2026-03-28 16:28:42 +00:00
add "type" search option
type:movie or type:tv
This commit is contained in:
parent
0399276c4f
commit
791591f06b
3 changed files with 65 additions and 2 deletions
|
|
@ -7,6 +7,8 @@ import {
|
|||
getMediaDetails,
|
||||
getMediaPoster,
|
||||
multiSearch,
|
||||
searchMovies,
|
||||
searchTVShows,
|
||||
} from "./tmdb";
|
||||
import { TMDBContentTypes } from "./types/tmdb";
|
||||
|
||||
|
|
@ -26,6 +28,9 @@ 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;
|
||||
|
|
@ -82,8 +87,25 @@ export async function searchForMedia(query: MWQuery): Promise<MediaItem[]> {
|
|||
yearValue = yearMatch[2];
|
||||
}
|
||||
|
||||
// normal search
|
||||
const data = await multiSearch(queryWithoutYear);
|
||||
// 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 formattedResult = formatTMDBSearchResult(v, v.media_type);
|
||||
return formatTMDBMetaToMediaItem(formattedResult);
|
||||
|
|
|
|||
|
|
@ -248,6 +248,38 @@ export async function multiSearch(
|
|||
return results;
|
||||
}
|
||||
|
||||
export async function searchMovies(
|
||||
query: string,
|
||||
): Promise<TMDBMovieSearchResult[]> {
|
||||
const data = await get<{
|
||||
results: TMDBMovieSearchResult[];
|
||||
}>("search/movie", {
|
||||
query,
|
||||
include_adult: false,
|
||||
page: 1,
|
||||
});
|
||||
return data.results.map((result) => ({
|
||||
...result,
|
||||
media_type: TMDBContentTypes.MOVIE,
|
||||
}));
|
||||
}
|
||||
|
||||
export async function searchTVShows(
|
||||
query: string,
|
||||
): Promise<TMDBShowSearchResult[]> {
|
||||
const data = await get<{
|
||||
results: TMDBShowSearchResult[];
|
||||
}>("search/tv", {
|
||||
query,
|
||||
include_adult: false,
|
||||
page: 1,
|
||||
});
|
||||
return data.results.map((result) => ({
|
||||
...result,
|
||||
media_type: TMDBContentTypes.TV,
|
||||
}));
|
||||
}
|
||||
|
||||
export async function generateQuickSearchMediaUrl(
|
||||
query: string,
|
||||
): Promise<string | undefined> {
|
||||
|
|
|
|||
|
|
@ -114,6 +114,15 @@ export const SearchBarInput = forwardRef<HTMLInputElement, SearchBarProps>(
|
|||
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