movie-trailer
v3.2.3
Published
Get movie & TV trailer url(s): Oceans Eleven ➔ http://path/to/trailer
Downloads
1,521
Maintainers
Readme
[!IMPORTANT] This library is feature-complete and only receives bug-fix updates. Feature requests still welcome — please open an issue.
Features
- Fetch YouTube trailers for any movie or TV show
- Return one URL or many — videos, IDs, or full URLs
- Async/await, Promise, and callback API
- Use anywhere — browser or Node, UMD bundle (browser support)
- Works in React + Next.js, client and server, via isomorphic-fetch
- Bring your own TMDB API key, or use the default
Install
npm install movie-trailerIn the browser:
<!-- movieTrailer as a window global -->
<script src="https://unpkg.com/movie-trailer"></script>Also available via JSDelivr.
Usage
const movieTrailer = require("movie-trailer");
// or: import movieTrailer from "movie-trailer";
await movieTrailer("Up");
//=> https://www.youtube.com/watch?v=...TV shows
await movieTrailer("Shameless", { videoType: "tv" });
//=> https://www.youtube.com/watch?v=...Many trailers — IDs only
await movieTrailer("Oceans Eleven", { id: true, multi: true });
//=> ["XXXXXXXXX", "XXXXXXXXX", ...]Year disambiguation + multiple URLs
await movieTrailer("Oceans Eleven", { year: "1960", multi: true });
//=> ["https://www.youtube.com/watch?v=...", ...]Legacy positional year
await movieTrailer("Oceans Eleven", 1960);
//=> https://www.youtube.com/watch?v=...[!TIP] Try it live — open in RunKit (example output).
API
movieTrailer(movie [, options] [, callback])
Pass a movie or show title (or null if searching by tmdbId). Returns a Promise that resolves to a YouTube URL — or an array of URLs / IDs depending on options.
| Option | Type | Default | Description |
|---|---|---|---|
| apiKey | string | TMDB default | Use your own TMDB key — get one free |
| id | boolean | false | Return only YouTube video IDs (e.g. "abc123" instead of full URLs) |
| language | string | | Movie release language code (e.g. "de_DE") |
| multi | boolean | false | Return an array of results instead of a single result |
| tmdbId | string \| number | | Search by TMDB content ID instead of a title (pass null as the first argument) |
| year | string \| number | | Release-year disambiguator |
| videoType | "movie" \| "tv" | "movie" | Movie or TV search |
The third argument may also be a Node-style (err, response) => void callback.
Search by TMDB ID
await movieTrailer(null, { tmdbId: 161 }); // Ocean's ElevenCLI
npx movie-trailer --help
# Usage
# $ npx movie-trailer movie
#
# Options
# --api_key, -k Your own TMDB API key
# --id, -i Return just the YouTube video ID
# --language,-l Language code (e.g. 'de_DE')
# --multi, -m Return an array of URLs
# --tmdb_id, -t Search by TMDB ID
# --year, -y Release year
#
# Example
# $ npx movie-trailer 'Oceans Eleven' -y 1960 -m
# => https://www.youtube.com/watch?v=...Related
Part of a small family of media-data utilities:
- album-art — Fetch album and artist cover art.
- movie-art — Get the poster art for a movie.
- movie-info — Get info, images, and ratings about a movie.
Acknowledgments
- TMDB — trailer metadata (subject to the TMDB Terms of Service).
- YouTube — where the trailers actually live.
