Assignment #6

Introduction

The OMDb API is a RESTful web service that serves as a massive digital library, aggregating comprehensive data for movies, television series, and video games #from across the entertainment industry. Beyond standard metadata like titles, directors, and plot summaries, the service is particularly valuable for its ability to pull consolidated critical reception data from IMDb, Rotten Tomatoes, and Metacritic into a single JSON response. By providing a structured gateway to this diverse information, the platform allows researchers and developers to automate the collection of cinematic data that would otherwise require manual searching across multiple websites.

Steps

1) Click this link to put in an email and explain the purpose for a key. After confirming the email and having the purpose approved, you will receive a special API Key to use.

2) Load packages needed

library(tidyverse) # All the tidy things
library(jsonlite)  # Converting json data into data frames
library(magrittr)  # Extracting items from list objects using piping grammar
library(httr)      # Interacting with HTTP verbs
library(knitr)     # Executes the R code chunks in to the final output

3) Load Base URL and Key

base_IMBD_url <- "https://www.omdbapi.com/?&apikey="
API_Key <- "<API_KEY_HERE>"

4) Give example with The Sandlot and Create GET Function

Sandlot_Url <- "http://www.omdbapi.com/?t=The+Sandlot&apikey=<API_KEY_HERE>"

Sandlot_Ratings <- GET(Sandlot_Url) %>% 
    content(as = "text",
            encoding = "UTF-8") %>% 
  fromJSON() %>% 
  use_series(Ratings)

5) Create a function that will replace “The Sandlot” with whatever movie we would like

get_movie_ratings <- function(movie_title) {
  formatted_title <- gsub(" ", "+", movie_title)
  
  api_key <- "<MY_API_KEY_HERE>"
  url <- paste0("http://www.omdbapi.com/?t=", formatted_title, "&apikey=", api_key)
  
  ratings <- GET(url) %>% 
    content(as = "text", encoding = "UTF-8") %>% 
    fromJSON() %>% 
    use_series(Ratings)
  
  return(ratings)
}

6) Let’s Try Some

Lion King:

                   Source  Value
1 Internet Movie Database 8.5/10
2         Rotten Tomatoes    92%
3              Metacritic 88/100

Avengers: End Game

                   Source  Value
1 Internet Movie Database 8.4/10
2         Rotten Tomatoes    94%
3              Metacritic 78/100

Inception

                   Source  Value
1 Internet Movie Database 8.8/10
2         Rotten Tomatoes    87%
3              Metacritic 74/100

Cars

                   Source  Value
1 Internet Movie Database 7.3/10
2         Rotten Tomatoes    74%
3              Metacritic 73/100

Cars 2

                   Source  Value
1 Internet Movie Database 6.2/10
2         Rotten Tomatoes    40%
3              Metacritic 57/100

The Shining

                   Source  Value
1 Internet Movie Database 8.4/10
2         Rotten Tomatoes    84%
3              Metacritic 68/100

The Hangover

                   Source  Value
1 Internet Movie Database 7.7/10
2         Rotten Tomatoes    79%
3              Metacritic 73/100

Toy Story

                   Source  Value
1 Internet Movie Database 8.3/10
2         Rotten Tomatoes   100%
3              Metacritic 96/100

Toy Story 3

                   Source  Value
1 Internet Movie Database 8.3/10
2         Rotten Tomatoes    98%
3              Metacritic 92/100

Explanation of Code

My code allows a user to enter the title of any movie and instantly receive its ratings from IMDb, Rotten Tomatoes, and Metacritic. After viewing the results, they can easily input another movie title and quickly access the same set of ratings again.