Skip to content

Commit

Permalink
show similar movies in detail
Browse files Browse the repository at this point in the history
  • Loading branch information
ovnrain committed Feb 27, 2024
1 parent c758a53 commit 2467eb8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/javbusParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
Property,
Sample,
SearchMoviesPage,
SimilarMovie,
SortBy,
SortOrder,
StarInfo,
Expand Down Expand Up @@ -362,6 +363,22 @@ export async function getMovieDetail(id: string): Promise<MovieDetail> {
})
.filter(({ id, thumbnail }) => Boolean(id) && Boolean(thumbnail));

/* ----------------- 同类影片 ------------------ */
const similarMovies =
doc
.querySelector('#related-waterfall')
?.querySelectorAll('a')
.map((link) => {
const href = link.getAttribute('href');

const id = href?.split('/').pop();
const title = link.getAttribute('title');
const img = formatImageUrl(link.querySelector('img')?.getAttribute('src')) ?? null;

return { id, title, img };
})
.filter((movie): movie is SimilarMovie => Boolean(id) && Boolean(title)) ?? [];

return {
id,
title,
Expand All @@ -376,6 +393,7 @@ export async function getMovieDetail(id: string): Promise<MovieDetail> {
genres,
stars,
samples,
similarMovies,
gid,
uc,
};
Expand Down
7 changes: 7 additions & 0 deletions api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export interface Movie {
tags: string[];
}

export interface SimilarMovie {
id: string;
title: string;
img: string | null;
}

export interface Magnet {
id: string;
link: string;
Expand Down Expand Up @@ -58,6 +64,7 @@ export interface MovieDetail {
stars: Property[];
imageSize: ImageSize | null;
samples: Sample[];
similarMovies: SimilarMovie[];
gid: string | null;
uc: string | null;
}
Expand Down

0 comments on commit 2467eb8

Please sign in to comment.