Skip to content

Commit

Permalink
feat: Retrieved the movie trailer property
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMachin1997 committed Jun 9, 2024
1 parent 430403e commit 7d949bb
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 246 deletions.
31 changes: 30 additions & 1 deletion src/entertainment/entertainment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
ICreditsQueryResponse,
IExternalIdsQueryResponse,
IKeywordsQueryResponse,
IReviewQuery
IReviewQuery,
IVdoesQueryResponse
} from './entertainment';

@Injectable()
Expand Down Expand Up @@ -232,4 +233,32 @@ export class EntertainmentService {

return originalLanguage;
};

async getTrailerUrl(): Promise<string | null> {
const { data } = await firstValueFrom(
this.httpService.get<IVdoesQueryResponse>(
'https://api.themoviedb.org/3/movie/19995/videos?language=en-U',
{
headers: {
Accept: 'application/json',
Authorization:
// eslint-disable-next-line max-len
'Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI1NDMwNWQxNmE1ZThkN2E3ZWMwZmM2NTk5MzZiY2EzMCIsInN1YiI6IjViMzE0MjQ1OTI1MTQxM2M5MTAwNTIwNCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.iqdLKFCSgeWG3SYso7Rqj297FORviPf9hDdn2kKygTA'
}
}
)
);

if (data.results.length === 0) return null;

// Get the first video which is a "YouTube" and has a type of "Trailer"
const youtubeTrailerVideos = data.results.find(
(el) => el.site === 'YouTube' && el.type === 'Trailer'
);

// If there is no trailer just return null
if (typeof youtubeTrailerVideos === 'undefined') return null;

return `https://www.youtube.com/watch?v=${youtubeTrailerVideos.key}`;
}
}
18 changes: 18 additions & 0 deletions src/entertainment/entertainment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,21 @@ export interface IExternalIdsQueryResponse {
instagram_id: string;
twitter_id: string;
}

export interface IVideosQueryResult {
iso_639_1: string;
iso_3166_1: string;
name: string;
key: string;
site: string;
size: number;
type: string;
official: boolean;
published_at: string;
id: string;
}

export interface IVdoesQueryResponse {
id: number;
results: IVideosQueryResult[];
}
Loading

0 comments on commit 7d949bb

Please sign in to comment.