mirror of
https://github.com/p-stream/p-stream.git
synced 2026-04-21 06:12:24 +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,
|
getMediaDetails,
|
||||||
getMediaPoster,
|
getMediaPoster,
|
||||||
multiSearch,
|
multiSearch,
|
||||||
|
searchMovies,
|
||||||
|
searchTVShows,
|
||||||
} from "./tmdb";
|
} from "./tmdb";
|
||||||
import { TMDBContentTypes } from "./types/tmdb";
|
import { TMDBContentTypes } from "./types/tmdb";
|
||||||
|
|
||||||
|
|
@ -26,6 +28,9 @@ const tmdbIdPattern = /^tmdb:(\d+)(?::(movie|tv))?$/i;
|
||||||
// detect "year:YYYY"
|
// detect "year:YYYY"
|
||||||
const yearPattern = /(.+?)\s+year:(\d{4})$/i;
|
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[]> {
|
export async function searchForMedia(query: MWQuery): Promise<MediaItem[]> {
|
||||||
if (cache.has(query)) return cache.get(query) as MediaItem[];
|
if (cache.has(query)) return cache.get(query) as MediaItem[];
|
||||||
const { searchQuery } = query;
|
const { searchQuery } = query;
|
||||||
|
|
@ -82,8 +87,25 @@ export async function searchForMedia(query: MWQuery): Promise<MediaItem[]> {
|
||||||
yearValue = yearMatch[2];
|
yearValue = yearMatch[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
// normal search
|
// type extract logic
|
||||||
const data = await multiSearch(queryWithoutYear);
|
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) => {
|
let results = data.map((v) => {
|
||||||
const formattedResult = formatTMDBSearchResult(v, v.media_type);
|
const formattedResult = formatTMDBSearchResult(v, v.media_type);
|
||||||
return formatTMDBMetaToMediaItem(formattedResult);
|
return formatTMDBMetaToMediaItem(formattedResult);
|
||||||
|
|
|
||||||
|
|
@ -248,6 +248,38 @@ export async function multiSearch(
|
||||||
return results;
|
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(
|
export async function generateQuickSearchMediaUrl(
|
||||||
query: string,
|
query: string,
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,15 @@ export const SearchBarInput = forwardRef<HTMLInputElement, SearchBarProps>(
|
||||||
Inception year:2010
|
Inception year:2010
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</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>
|
<div>
|
||||||
<p className="mb-0.5">TMDB ID search:</p>
|
<p className="mb-0.5">TMDB ID search:</p>
|
||||||
<p className="text-type-secondary italic pl-2">
|
<p className="text-type-secondary italic pl-2">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue