The Open Movie Database is a free API web service that provides structured information about TV shows, movies, and episodes. It can also return data such as titles, release years, genres, IMBD ratings, etc. Analysts may use this to build dashboards, along with recomendation systems, to give a few examples
In the following tutorial, I will demonstrate how to access OMBD from R and retrieve movie data.
To use the OMDB, you must request an API Key from the official website (daily limit of 1,000 requests for non-Patreon users). This can be done by clicking on the API Key section of the home page. After this, you should receive an email with the API Key, and a link to a website that will ensure it’s activated.
From here, we can move on to the R code:
{# Load in packages} library(httr) library(jsonlite) # Convert Json data to data frames library(tidyverse) library(magittr)
url <- paste0("http://www.omdbapi.com/?i=tt3896198&apikey="("OMDB_KEY"), api_key)
This URL code chunk is requesting a list of Batman movies from the OMDB. To simplify it for those who may not be aware:
s= keyword , type= filtering for movies, page= pagination, apikey= authentication
So below, a request is being made to retrieve data about Batman movies
{# List of Batman movies via building the URL} url <- paste0( "https://www.omdbapi.com/?", "s=Batman&", "type=movie&", "page=1&", "apikey=", api_key )
```{# Request for Batty data} resp <- GET(url)
data <- content(as = “text”, encoding = “UTF-8”) %>%
| | | | | | | | |
|-------:|------------|--------|---------|---------|-------------|--------|--------|
| 1 | Batman Begins | 2005 | tt0372784 | movie | [https://m.media-amazon.com/images/M/MV5BMzA2NDQzZDEtNDU5Ni00YTlkLTg2OWEtYmQwM2Y1YTBjMjFjXkEyXkFqcGc\@.\_V1_SX300.jpg](https://m.media-amazon.com/images/M/MV5BMzA2NDQzZDEtNDU5Ni00YTlkLTg2OWEtYmQwM2Y1YTBjMjFjXkEyXkFqcGc@._V1_SX300.jpg) | 521 | True |
| 2 | The Batman | 2022 | tt1877830 | movie | [https://m.media-amazon.com/images/M/MV5BMmU5NGJlMzAtMGNmOC00YjJjLTgyMzUtNjAyYmE4Njg5YWMyXkEyXkFqcGc\@.\_V1_SX300.jpg](https://m.media-amazon.com/images/M/MV5BMmU5NGJlMzAtMGNmOC00YjJjLTgyMzUtNjAyYmE4Njg5YWMyXkEyXkFqcGc@._V1_SX300.jpg) | 521 | True |
| 3 | Batman v Superman: Dawn of Justice | 2016 | tt2975590 | movie | [https://m.media-amazon.com/images/M/MV5BZTJkYjdmYjYtOGMyNC00ZGU1LThkY2ItYTc1OTVlMmE2YWY1XkEyXkFqcGc\@.\_V1_SX300.jpg](https://m.media-amazon.com/images/M/MV5BZTJkYjdmYjYtOGMyNC00ZGU1LThkY2ItYTc1OTVlMmE2YWY1XkEyXkFqcGc@._V1_SX300.jpg) | 521 | True |
| 4 | Batman v Superman: Dawn of Justice | 2016 | tt2975590 | movie | [https://m.media-amazon.com/images/M/MV5BZTJkYjdmYjYtOGMyNC00ZGU1LThkY2ItYTc1OTVlMmE2YWY1XkEyXkFqcGc\@.\_V1_SX300.jpg](https://m.media-amazon.com/images/M/MV5BZTJkYjdmYjYtOGMyNC00ZGU1LThkY2ItYTc1OTVlMmE2YWY1XkEyXkFqcGc@._V1_SX300.jpg) | 521 | True |
| 5 | Batman | 1989 | tt0096895 | movie | [https://m.media-amazon.com/images/M/MV5BYzZmZWViM2EtNzhlMi00NzBlLWE0MWEtZDFjMjk3YjIyNTBhXkEyXkFqcGc\@.\_V1_SX300.jpg](https://m.media-amazon.com/images/M/MV5BYzZmZWViM2EtNzhlMi00NzBlLWE0MWEtZDFjMjk3YjIyNTBhXkEyXkFqcGc@._V1_SX300.jpg) | 521 | True |
| 6 | Batman Returns | 1992 | tt0103776 | movie | [https://m.media-amazon.com/images/M/MV5BZTliMDVkYTktZDdlMS00NTAwLWJhNzYtMWIwMDZjN2ViMGFiXkEyXkFqcGc\@.\_V1_SX300.jpg](https://m.media-amazon.com/images/M/MV5BZTliMDVkYTktZDdlMS00NTAwLWJhNzYtMWIwMDZjN2ViMGFiXkEyXkFqcGc@._V1_SX300.jpg) | 521 | True |
| 7 | Batman & Robin | 1997 | tt0118688 | movie | [https://m.media-amazon.com/images/M/MV5BYzU3ZjE3M2UtM2E4Ni00MDI5LTkyZGUtOTFkMGIyYjNjZGU3XkEyXkFqcGc\@.\_V1_SX300.jpg](https://m.media-amazon.com/images/M/MV5BYzU3ZjE3M2UtM2E4Ni00MDI5LTkyZGUtOTFkMGIyYjNjZGU3XkEyXkFqcGc@._V1_SX300.jpg) | 521 | True |
| 8 | Batman Forever | 1995 | tt0112462 | movie | [https://m.media-amazon.com/images/M/MV5BMTUyNjJhZWItMTZkNS00NDc4LTllNjUtYTg3NjczMzA5ZTViXkEyXkFqcGc\@.\_V1_SX300.jpg](https://m.media-amazon.com/images/M/MV5BMTUyNjJhZWItMTZkNS00NDc4LTllNjUtYTg3NjczMzA5ZTViXkEyXkFqcGc@._V1_SX300.jpg) | 521 | True |
| 9 | The Lego Batman Movie | 2017 | tt4116284 | movie | [https://m.media-amazon.com/images/M/MV5BMTcyNTEyOTY0M15BMl5BanBnXkFtZTgwOTAyNzU3MDI\@.\_V1_SX300.jpg](https://m.media-amazon.com/images/M/MV5BMTcyNTEyOTY0M15BMl5BanBnXkFtZTgwOTAyNzU3MDI@._V1_SX300.jpg) | 521 | True |
| 10 | Batman v Superman: Dawn of Justice (Ultimate Edition) | 2016 | tt18689424 | movie | <https://m.media-amazon.com/images/M/MV5BOTRlNWQwM2ItNjkyZC00MGI3LThkYjktZmE5N2FlMzcyNTIyXkEyXkFqcGdeQXVyMTEyNzgwMDUw._V1_SX300.jpg> | 521 | True |
## Data Applications + Results
Down below is just a few things you can do with the batman movie data.
```{# Count the number of Batman movies}
nrow(movie_data)
# Turns Year into an object
movie_data <- movie_data %>%
mutate(Year = as.numeric(Year))
# Plot the release years between movies
movie_data %>%
mutate(Year = as.numeric(Year)) %>%
ggplot(aes(x = Year)) +
geom_histogram(binwidth = 5, fill = "black") +
labs(title = "Distribution of Batman Movie Release Years")