I am grabbing a movie trailer from API results in order to show the 'Official Trailer'. I want to show the official trailer instead of featurettes/bloopers etc.
At the moment I am doing this which works for the most part, but some movies don't seem to accept it....
let movieTrailerUrl = data.videos.results.find(element => element.name.toLowerCase() === 'Official Trailer'.toLowerCase()).key;
For example, this movie clearly has available videos but it pulls in zero results...
https://www.themoviedb.org/movie/370172-no-time-to-die?language=en-US
Is there a better way to grab an 'Official Trailer' from the API?
.לא מצאת סרט או סדרה? היכנס כדי ליצור אותם
?רוצה לדרג או להוסיף פריט אל רשימה
?לא חבר אתר
תגובה מאת Travis Bell
ב-ינואר 13, 2022 ב-1:33אחרי חצות יום
Each video object returns a field called
official
that you should be checking instead of anything to do with the name. Studios name their trailers all kinds of different things so that would not be a very reliable way to searching for official trailers.Request
Response
תגובה מאת lowercase
ב-ינואר 13, 2022 ב-4:02אחרי חצות יום
I feel like this doesn't solve the issue of Trailers specifically. Grabbing videos marked 'Official' means you also get anything else marked official - bloopers/featurettes/interviews/teasers etc.
Is the a way to specifically get the 'official movie trailer' as opposed to an 'offical video of any kind'?
Hope that makes sense and appreciate the help.
תגובה מאת Travis Bell
ב-ינואר 13, 2022 ב-4:22אחרי חצות יום
You wouldn't just grab anything marked as official. Instead, grab the items that are
type: Trailer
ANDofficial: true
.תגובה מאת kingluiii
ב-פברואר 26, 2022 ב-5:52לפני חצות יום
what if I only want one trailer ...the final trailer only??
תגובה מאת ticao2 🇧🇷 pt-BR
ב-פברואר 26, 2022 ב-7:23לפני חצות יום
All video responses contain this data:
So I think you should select what you want.
"published_at": I believe it's the date of publication on Youtube.
There is no API Request that returns only the latest, or most recent, official trailer.
תגובה מאת OceanCat
ב-ינואר 24, 2024 ב-7:14לפני חצות יום
Guys, try -> const trailerUrl = movieVids?.results?.find(element => element.name.includes("Official Trailer") || element.name.includes("Trailer")) Use then trailerUrl.key.
It will find any video that have "Official Trailer" or "Trailer" in this name. So you guarantee TRAILER video.