Demo Application

Learn how TMDB APIs can be integrated into a real-world application.

We'll cover the following

We gained hands-on experience with The Movie Database API endpoints in the previous chapters. Now, we’ll integrate those endpoints into a real-world application.

Workflow

  1. When we run the application, the first page we see is the home page. The home page has two main components using the API endpoints—the navigation bar, and flashcards.
  2. For flashcards, by hovering over them, we can see some basic details of a movie or a TV show. When we click “View Details,” it takes us to the movie or the TV show details page.
  3. The various options shown in the navigation bar (to the left side of the webpage) are discussed below:
    • “MovieTV” or “Home” take us to the home page if we are not already there.
    • “Movies” takes us to the movies page, where we can see the latest, trending, popular, top-rated, upcoming, and currently playing movies.
    • “TV Shows” takes us to the TV page, where we can see the latest, trending, popular, top-rated, airing today, and on the air TV Shows.
    • “People” takes us to the persons page, where we can see all the popular persons on TMDB.
  4. For the navigation bar (right side), we have to select the object to be searched, movie, TV show, or person, then we type in our query in the search bar and finally click the search button or press enter. This takes us to the results page.

API endpoints in use

We have used endpoints in the views.py file.

  1. The index function in line 10 uses the trending endpoint in line 11. The value of media_type is set to all and the value of time_window is set to day. We use this function to display the trending movies and TV shows on the home page.

  2. The search function in line 16 uses the search endpoint in line 22. It takes the media type (movie or TV) and query string from the user and returns the search results. We use include_adult=false to filter the adult content from the results.

  3. The movies function in line 33 is used to display the “Movies” page. It uses multiple endpoints, like the latest movie endpoint in line 34, trending movies in line 35, popular movies in line 36, top movies in line 37, upcoming movies in line 38, and now playing movies in line 39, to display the sets of all these movies.

  4. The tv function in line 50 is used to display the “TV Shows” page. It uses multiple endpoints, like the endpoint for latest TV shows in line 51, trending TV shows in line 52, popular TV shows in line 53, top TV shows in line 54, the endpoint for TV shows airing today in line 55 and on air TV shows in line 56, to display the sets of all these TV shows.

  5. The movie_detail function in line 67 is used to display the details for the selected movie. The function uses the following endpoints:

    • The primary movie details endpoint in line 68 is used to fetch and display all the basic details about the requested movie.
    • The recommendations endpoint in line 69 is used to fetch and display a list of recommended movies for the requested movie.
    • The credits endpoint in line 70 is used to fetch and display all the cast and crew of the requested movie.
    • The videos endpoint in line 71 to fetch and display all the videos of the requested movie.
  6. The tv_detail function in line 81 is used to display the details for the selected TV show. The function uses the following endpoints:

    • The primary tv details endpoint in line 82 is used to fetch and display all the basic details about the requested TV show.
    • The recommendations endpoint in line 83 is used to fetch and display a list of recommended TV shows for the requested TV show.
    • The credits endpoint in line 84 is used to fetch and display all the cast and crew of the requested TV show.
    • The videos endpoint in line 85 is used to fetch and display all the videos of the requested TV show.
  7. The season_detail function in line 95 is used to display the details for the requested season of a TV show. It uses the season endpoint in line 96 that needs season_number to specify which season to return.

  8. The episode_detail function in line 103 is used to display the details for the requested episode of a TV show. It uses the episode endpoint in line 104 that needs episode_number along with season_number to specify which episode to return.

  9. The people_detail function in line 110 is used to display the details for the requested person. It uses the person endpoint in line 111 that takes person_id as the required parameter. The function also uses the combined_credits endpoint with the person_id as the required parameter.

  10. The people function in line 117 is used to display all the popular persons on TMDB. It uses the popular endpoint in line 118 to fetch and display all the popular persons.

Note: The following widget only shows the necessary files required to explain The Movie Database APIs.

Click “Run” to run the application. Next, click on the URL given at the end of the widget to watch the application up and running.

Get hands-on with 1200+ tech skills courses.