Soporte de The Movie Database

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?

6 respuestas (en la página 1 de 1)

Jump to last post

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

$ curl -v "https://api.themoviedb.org/3/movie/370172/videos?api_key=###"

*   Trying 52.84.158.120:443...
* Connected to api.themoviedb.org (52.84.158.120) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=*.themoviedb.org
*  start date: Oct 21 00:00:00 2021 GMT
*  expire date: Nov 18 23:59:59 2022 GMT
*  subjectAltName: host "api.themoviedb.org" matched cert's "*.themoviedb.org"
*  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7f7ef6814800)
> GET /3/movie/370172/videos?api_key=### HTTP/2
> Host: api.themoviedb.org
> user-agent: curl/7.76.1
> accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 200
< content-type: application/json;charset=utf-8
< content-length: 3348
< date: Thu, 13 Jan 2022 18:30:53 GMT
< server: openresty
< access-control-allow-origin: *
< access-control-allow-methods: GET, HEAD, POST, PUT, DELETE, OPTIONS
< access-control-expose-headers: ETag, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, Retry-After, Content-Length, Content-Range
< cache-control: public, max-age=28800
< x-memc: HIT
< x-memc-key: 9a82781b779376ae9e50804d659b41f1cbf52ad8
< x-memc-age: 3720
< x-memc-expires: 12369
< etag: W/"37807fd906823725fe5d9053b0f18e4f"
< vary: Accept-Encoding,Accept-Encoding
< x-cache: Hit from cloudfront
< via: 1.1 6af3b573d8970d5db2a4d03354335b84.cloudfront.net (CloudFront)
< x-amz-cf-pop: SEA19-C3
< x-amz-cf-id: oOK3RhD_WLSoh8yFhWMTOkYUc8AV8gA08O8xXD2cmCRJmY9RLfj9pw==
< age: 6
<
* Connection #0 to host api.themoviedb.org left intact

Response

{
  "id": 370172,
  "results": [
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "NO TIME TO DIE | Final US Trailer",
      "key": "N_gD9-Oa0fg",
      "site": "YouTube",
      "size": 1080,
      "type": "Trailer",
      "official": true,
      "published_at": "2021-08-31T15:38:23.000Z",
      "id": "612fbfafc1ffbd00630e8717"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "NO TIME TO DIE | Final International Trailer",
      "key": "FREBR6FH1rg",
      "site": "YouTube",
      "size": 1080,
      "type": "Trailer",
      "official": true,
      "published_at": "2021-08-31T15:31:57.000Z",
      "id": "612fbfc16a34480090f527d7"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "NO TIME TO DIE | Bond is Back | Only in Cinemas October",
      "key": "tTkJQh1_yQY",
      "site": "YouTube",
      "size": 1080,
      "type": "Teaser",
      "official": true,
      "published_at": "2021-07-26T07:58:46.000Z",
      "id": "60fef6347ad08c002d6dee42"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "NO TIME TO DIE l Meet Safin",
      "key": "dCYRog1dosI",
      "site": "YouTube",
      "size": 1080,
      "type": "Featurette",
      "official": true,
      "published_at": "2020-09-14T13:00:03.000Z",
      "id": "5f60f44c706b9f0039082f9f"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "NO TIME TO DIE | Trailer 2",
      "key": "vw2FOYjCz38",
      "site": "YouTube",
      "size": 1080,
      "type": "Trailer",
      "official": true,
      "published_at": "2020-09-03T11:00:01.000Z",
      "id": "5f50dd45c740d900358bbb58"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "NO TIME TO DIE | Trailer Tomorrow",
      "key": "d2sJtfkfggk",
      "site": "YouTube",
      "size": 1080,
      "type": "Teaser",
      "official": true,
      "published_at": "2020-09-02T17:00:02.000Z",
      "id": "5f60f49d31234500376a9696"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "Director Cary Joji Fukunaga on NO TIME TO DIE",
      "key": "g4aSE4FhbG4",
      "site": "YouTube",
      "size": 1080,
      "type": "Featurette",
      "official": true,
      "published_at": "2020-02-25T14:00:08.000Z",
      "id": "5eda62dafea0d7001e929d7e"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "No Time To Die | NBA All-Star Game TV Spot",
      "key": "uI13bxfdrMc",
      "site": "YouTube",
      "size": 1080,
      "type": "Teaser",
      "official": true,
      "published_at": "2020-02-15T16:00:11.000Z",
      "id": "5e54415d35811d001559b389"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "NO TIME TO DIE | Official Game Day Spot 2020",
      "key": "7BgcG_l9J0A",
      "site": "YouTube",
      "size": 1080,
      "type": "Teaser",
      "official": true,
      "published_at": "2020-02-03T00:49:14.000Z",
      "id": "5e54413735811d00195ada8f"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "NO TIME TO DIE Trailer (Global)",
      "key": "BIhNsAtPbPI",
      "site": "YouTube",
      "size": 1080,
      "type": "Trailer",
      "official": true,
      "published_at": "2019-12-04T13:25:16.000Z",
      "id": "5de7b4ec3faba000131346c0"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "NO TIME TO DIE Teaser",
      "key": "QMrGxC60vzk",
      "site": "YouTube",
      "size": 1080,
      "type": "Teaser",
      "official": true,
      "published_at": "2019-12-02T01:20:12.000Z",
      "id": "5de5a543a7e36300146ea75d"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "NO TIME TO DIE",
      "key": "IDxMam77onE",
      "site": "YouTube",
      "size": 1080,
      "type": "Featurette",
      "official": true,
      "published_at": "2019-10-05T05:50:17.000Z",
      "id": "5de72858a7e3630014712cd9"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "Official title reveal of Bond 25",
      "key": "ChJ_afRiUzo",
      "site": "YouTube",
      "size": 1080,
      "type": "Teaser",
      "official": true,
      "published_at": "2019-08-20T15:59:35.000Z",
      "id": "5d5ea961f263ba7c4e94542f"
    },
    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "On set with Bond 25: Jamaica",
      "key": "NQkO0Shirl8",
      "site": "YouTube",
      "size": 1080,
      "type": "Featurette",
      "official": true,
      "published_at": "2019-06-25T12:00:19.000Z",
      "id": "5d405a659cc67b0011777163"
    }
  ]
}

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.

You wouldn't just grab anything marked as official. Instead, grab the items that are type: Trailer AND official: true.

what if I only want one trailer ...the final trailer only??

@kingluiii said:
what if I only want one trailer ...the final trailer only??

All video responses contain this data:

    {
      "iso_639_1": "en",
      "iso_3166_1": "US",
      "name": "NO TIME TO DIE | Final US Trailer",
      "key": "N_gD9-Oa0fg",
      "site": "YouTube",
      "size": 1080,
      "type": "Trailer",
      "official": true,
      "published_at": "2021-08-31T15:38:23.000Z",
      "id": "612fbfafc1ffbd00630e8717"
    },

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.

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.

¿No encuentras una película o serie? Inicia sesión para crearla:

Global

s centrar la barra de búsqueda
p abrir menú de perfil
esc cierra una ventana abierta
? abrir la ventana de atajos del teclado

En las páginas multimedia

b retrocede (o a padre cuando sea aplicable)
e ir a la página de edición

En las páginas de temporada de televisión

(flecha derecha) ir a la temporada siguiente
(flecha izquierda) ir a la temporada anterior

En las páginas de episodio de televisión

(flecha derecha) ir al episodio siguiente
(flecha izquierda) ir al episodio anterior

En todas las páginas de imágenes

a abrir la ventana de añadir imagen

En todas las páginas de edición

t abrir la sección de traducción
ctrl+ s enviar formulario

En las páginas de debate

n crear nuevo debate
w cambiar el estado de visualización
p cambiar público/privado
c cambiar cerrar/abrir
a abrir actividad
r responder al debate
l ir a la última respuesta
ctrl+ enter enviar tu mensaje
(flecha derecha) página siguiente
(flecha izquierda) página anterior

Configuraciones

¿Quieres puntuar o añadir este elemento a una lista?

Iniciar sesión