Projects
View on GitHub
lacymorrow/movie-trailer
About
Find YouTube trailer URLs for any movie or TV show
Web & App DevelopmentWhat you can do
- 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)
Measured star growth
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Original[!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-trailer
In 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 Eleven
CLI
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.
License
If movie-trailer saved you time, consider sponsoring on GitHub, supporting on Patreon, or buying a coffee.
Explore related projects
Loading…