library(tidyverse)
library(jsonlite)
library(magrittr)
OMDb_endpoint <- "http://www.omdbapi.com/?"
#You would need to use your own api key
API_KeY <- "apikey=810ac94e"
movie_title_search <- paste("s=Batman",
"type=movie",
"page=4", # page number section (look below)
sep = "&")
OMDb_api_get <- paste(OMDb_endpoint,API_KeY,movie_title_search, sep = "&")
OMDb_api_getMovie API tutorial
Intro
For this assignment I took a look at the Open Movie Database, or OMDb, API. This API gets information from films and movies from IMDB.com
Database Variables
Search by ID or Title
You can use search with this API by using the direct title of the film or the IMDb ID. For example Iron man’s IMDb ID is “tt0371746”.
Other distinctions you can search for are:
Type
- Movie, series, or episode
Plot
Full or Short
- This changes the output of the API search
Page
page number to return 1-100
- This is only with a Movie Title search
Grabbing the URL
Now we want to attempt a broad search using a common movie name. For this example I recommend a movie series that has been made multiple times. James Bond would be a good one. For my example we are going to go with Batman
After doing so we should see an output that looks like:
"http://www.omdbapi.com/?&apikey = i=tt3896198&apikey=810ac94e&s=Bat%20Man&type=movie&page=1"
Inputting the data into R
Using the above URL we can pull data into R and create a data frame
First we need to take our search criteria and turn it into lists. Then we want to convert these lists into a data frame that we can observe in R.
#For each of these sections you'll want to edit the "page = " section above.
#Run each code section independantly coordinating to it's own page number.
movie_data_p1 <-
OMDb_api_get %>%
eval() %>%
fromJSON()
movie_data_p2 <-
OMDb_api_get %>%
eval() %>%
fromJSON()
movie_data_p3 <-
OMDb_api_get %>%
eval() %>%
fromJSON()
movie_data_p4 <-
OMDb_api_get %>%
eval() %>%
fromJSON()
Movie_data <-
bind_rows(
movie_data_p1, movie_data_p2, movie_data_p3, movie_data_p4)
movie_pull_df <-
Movie_data %>%
extract2(1) %>%
relocate(imdbID,Title,Year,Type,Poster)Visualization based off Data
Lets try and see a chart visualizing the years of release for these films:
Debuts <- Movie_data$Search$Year
Debuts <- as.numeric(gsub("[^0-9]", "", Movie_data$Search$Year))
timeline <- data.frame(Debut_year = Debuts)
Year_count <- table(timeline$Debut_year)
plot <- data.frame(Year = as.numeric(names(Year_count)),
Count = as.numeric(Year_count))
ggplot(plot, aes(x = Year, y = Count))+
geom_point(color = "yellow", size = 3) +
geom_line(color = "black", size = 0.6) +
labs(title = "Timeline of Batman Movie Debus",
X = "Release Year",
y = "Number of Movies Released")Based on this output we can see that the primary amount of change comes at the year 2005 five. This is when the Christian Bale Batman movies began. The character’s popularity skyrocketed with this movie series. And as the series continued with “The Dark Knight” (Which was left off of this search) more and more films were produced. Many of them animated. Any of those before 2005 are the old Michael Keaton movies and animated films.
Conclusion
In summation, you can use this API for general information regarding your favorite movies. In doing so we are providing quality data to the holders IMDb and in return are able to learn a bit more about their processes.