-
Notifications
You must be signed in to change notification settings - Fork 2
Feature: support IMDb ID search #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import { | |
| searchMulti, | ||
| searchPerson, | ||
| searchTv, | ||
| findByExternalId, | ||
| } from "@sofa/tmdb/client"; | ||
| import { isTmdbConfigured } from "@sofa/tmdb/config"; | ||
| import { tmdbImageUrl } from "@sofa/tmdb/image"; | ||
|
|
@@ -32,6 +33,40 @@ function requireTmdb() { | |
| } | ||
| } | ||
|
|
||
|
|
||
| // ─── SEARCH BY IMDB ID ───────────────────────────────────────────────── | ||
| const IMDB_ID_REGEX = /^tt\d{7,10}$/i; | ||
|
|
||
| function isImdbIdSearch(query: string) { | ||
| return IMDB_ID_REGEX.test(query.trim()); | ||
|
|
||
| } | ||
|
|
||
| async function searchByImdbId(query: string) { | ||
| const findResult = await findByExternalId(query.toLowerCase(), "imdb_id"); | ||
|
|
||
| // result of all movies found | ||
| const movieResults = (findResult.movie_results ?? []).map((r) => ({ | ||
| ...r, | ||
| media_type: "movie" as const, | ||
| })); | ||
|
|
||
| // result of all shows found | ||
| const tvResults = (findResult.tv_results ?? []).map((r) => ({ | ||
| ...r, | ||
| media_type: "tv" as const, | ||
| })); | ||
|
|
||
| // join all the results | ||
| const results = [...movieResults, ...tvResults]; | ||
| return { | ||
| page: 1, | ||
| total_pages: results.length > 0 ? 1 : 0, | ||
| total_results: results.length, | ||
| results, | ||
| }; | ||
| } | ||
|
|
||
| // ─── Trending ───────────────────────────────────────────────── | ||
|
|
||
| export const trending = os.discover.trending.use(authed).handler(async ({ input, context }) => { | ||
|
|
@@ -219,12 +254,21 @@ export const search = os.discover.search.use(authed).handler(async ({ input }) = | |
| }; | ||
| } | ||
|
|
||
| const raw = | ||
| type === "movie" | ||
| // Old Results without seach by imdb id | ||
| // const raw = | ||
| // type === "movie" | ||
| // ? await searchMovies(query, input.page) | ||
| // : type === "tv" | ||
| // ? await searchTv(query, input.page) | ||
| // : await searchMulti(query, input.page); | ||
|
|
||
| const raw = isImdbIdSearch(query) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Type-filtered search can now return the wrong media kind for IMDb ID queries: with Prompt for AI agents |
||
| ? await searchByImdbId(query) | ||
| : type === "movie" | ||
| ? await searchMovies(query, input.page) | ||
| : type === "tv" | ||
| ? await searchTv(query, input.page) | ||
| : await searchMulti(query, input.page); | ||
| : await searchMulti(query, input.page); | ||
|
|
||
| type SearchResult = { | ||
| id: number; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: This leaves stale commented-out search logic in the procedure, which makes the active IMDb branching harder to read and easier to let drift from the real implementation. Since the new ternary below replaces it, removing this block would keep the search flow clearer.
Prompt for AI agents