# Necessary library packages to utilize the API:
library(jsonlite)
library(tidyverse)OMDb Basics
Explanation of OMDb Services:
The API I am utilizing is the OMDb API, which takes movie, show, and entertainment data from the IMDb website. Other sites such as Rotten Tomatoes and Metacritic are also featured in some data variables such as Ratings. This API is useful for entertainment marketers who would want to sift through movie and show data (such as profits, ratings, etc) in order to make predictive decisions in the entertainment business. The database is also just fun to go through, especially for people who love to know the finer details of movies and shows such as writers or the amount of awards that were won.
By using an API Key that is emailed to you via the OMDb website (after a free sign-up from https://www.omdbapi.com), you are able to retrieve data from the database itself for whatever means you need:
omdb_url <- "http://www.omdbapi.com/?<OMDb COMMAND HERE>&apikey=<YOUR API KEY HERE>"The ‘OMDb Command Here’ within the above url is where a certain OMDb command can be utilized for scraping, such as ‘t’ for finding movies based on title or ‘y’ which returns values based on release date. The ‘YOUR API KEY HERE’ above is simply the exact API key the user is given from the OMDb website. It is important not to publish your API Key, like in this instance, because others can manipulate it for their own use.
Simple example of retrieving data using OMDb API:
# Using the 't' function within the url and the fromJSON command, we can find
# all available details for the movie "The Matrix":
matrix_info <- fromJSON("http://www.omdbapi.com/?t=The+Matrix&apikey=<YOUR API KEY HERE>")
# Again, I am hiding my API Key.
# Here is how one would just create a vector of the Ratings for the movie "The Matrix":
matrix_info$RatingsThe OMDb website provides many commands/functions for one to utilize with the API.
Brief Demonstration of OMDb:
As to familiarize both myself and those who read this, I am going to demonstrate the use of the OMDb API by finding the IMBD Ratings for Denis Villenueve’s recent movies.
# First, we call upon the OMDb API using our own key, and the data provided
# in the OMBd site so that we can find a few of Villenueve's movies:
blade_runner_2049_info <- fromJSON("http://www.omdbapi.com/?t=Blade+Runner+2049&apikey=<YOUR API KEY HERE>")
dune_info <- fromJSON("http://www.omdbapi.com/?t=Dune&apikey=<YOUR API KEY HERE>")
dune_2_info <- fromJSON("http://www.omdbapi.com/?t=Dune:Part+Two&apikey=<YOUR API KEY HERE>")
# Next, we find the ratings for the specific Villenueve movies we want to research:
villenueve_ratings <- list(blade_runner_2049_info$imdbRating, dune_info$imdbRating,
dune_2_info$imdbRating)
# We can also lsit the movie titles so that the data output is less confusing:
movie_names <- list(blade_runner_2049_info$Title, dune_info$Title, dune_2_info$Title)
movie_year <- list(blade_runner_2049_info$Year, dune_info$Year, dune_2_info$Year)
# Last, we combine the lists to make a comprehensive output on a few of Villenueve's movies:
combined_list <- cbind(movie_names,villenueve_ratings,movie_year)
print(combined_list) The combined list we created will produce an output in the console that looks like this:
movie_names villenueve_ratings movie_year
[1,] "Blade Runner 2049" "8.0" "2017"
[2,] "Dune" "8.0" "2021"
[3,] "Dune: Part Two" "9.1" "2024"