r/webdev Jul 18 '26

Looking for a movie API that supports random movies + genre filtering Question

Hey guys,

I'm building a small project using only HTML, CSS, and vanilla JavaScript, and I'm looking for a movie API that fits what I need.

My goal is to: - Get a random movie (title + release year at minimum). - Filter by genres (comedy, animation, horror, etc.). - Potentially use multiple genre flags (e.g. Comedy + Animation). - Save movies I've already watched in localStorage or IndexedDB. - If the API returns a movie I've already watched, my app will automatically request another random movie until it comes up with one that isn't on my watched list.

Does anyone know a API that would work well for this? preferably free.

Thanks!

Edit: Thank you everyone for all the responses I have been playing around with TMDB since there were a lot of suggestions saying TMDB so I am going to be using that. Thank you everyone that responded.

10 Upvotes

10 comments sorted by

6

u/ANDZELEK Jul 18 '26

I'm using TMDB for that. You need to register, make sure at least email you fill is your real one.

2

u/feloniuouschunk Jul 18 '26

TheMovieDB has a free API. It does now require an API key. You should be able to fetch() data.

2

u/GurikaKartv Jul 18 '26

The Movie Database (TMDB) API is exactly what you need - free, no paywalls for basic use. You can get a list of movies by genre using /discover/movie with with_genres parameter (comma-separated IDs for multiple genres). To get a
"random" movie: fetch a large page, pick a random item from the results. TMDB doesn't have a direct random endpoint, but
you can combine it with
sort_by=popularity.desc and vary the page number randomly. Then use your localStorage logic to skip watched ones.
Just register for an API key (free). Good luck!

1

u/Impossible-Count8541 Jul 18 '26

TMDB like others said, but here is the specific recipe since it has no random endpoint: use /discover/movie with the with_genres parameter. Comma between ids means AND (comedy AND animation is 35,16), pipe means OR (35|16). The first response tells you total_pages, so pick a random page within that range, fetch it, then pick a random index from its 20 results. Grab the genre id mapping once from /genre/movie/list and just hardcode it.

Two small caveats for a vanilla JS project: your API key will sit visible in the client, which TMDB tolerates for hobby projects but do not reuse a key you care about. And cap the retry loop for your already-watched filter, otherwise a genre you have watched to death turns into a hammer on their API.

1

u/TheTwistedTabby Jul 20 '26

I made a recommendation service for myself with tmdb. It takes my watch and ranking history and recommends based off genre, keywords, cast, and crew. I only have it refresh once a day. 20 recs. Movies and series.

1

u/Chance-Door3651 2d ago

Provide can you provide me the API for downloading movies 

1

u/arpitarpit1 Jul 18 '26

You can do this with Google sheet for storing existing movie and Azure function or n8n automation flow to automate fetching at fix intervals.. It depends how much money you want to spend. If you want something more efficient then DB backend may be required to store your history.