SPD Ratings

Author

Ty McCaw

API Explination

The Open Movie Database (OMDb) is an API that can be used to collect information on various movies. Whether you are looking for ratings or basic information, you can find it here. https://www.omdbapi.com My use for this assignemnt is to find the ratings for my favorite childhood show, Power Rangers S.P.D.

Setting Up the Code

You must library all of your packages first.

# Load packages
library(tidyverse) # All the tidy things
Warning: package 'readr' was built under R version 4.5.2
Warning: package 'forcats' was built under R version 4.5.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.6
✔ forcats   1.0.1     ✔ stringr   1.5.1
✔ ggplot2   3.5.2     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(jsonlite)  # Converting json data into data frames

Attaching package: 'jsonlite'

The following object is masked from 'package:purrr':

    flatten
library(magrittr)  # Extracting items from list objects using piping grammar

Attaching package: 'magrittr'

The following object is masked from 'package:purrr':

    set_names

The following object is masked from 'package:tidyr':

    extract
library(httr)      # Interacting with HTTP verbs

Then get your url set up for the specific movie or show you want to learn more about.

api_key <- "b7f1e3be"

url_endpoint <- "http://www.omdbapi.com/?apikey="

power_rangers <- "&s=power+rangers+S.P.D."

series <- "&type=series"

power_rangers_url <- paste(url_endpoint, api_key, power_rangers, series, sep = "")

You then move into getting the url to obtain the IMDB id.

pr_url_content <- 
  power_rangers_url %>% 
  GET() %>% 
  content(as = "text",
          encoding = "UTF-8") %>% 
  fromJSON() %>% 
  use_series(Search)

Once you have that in a data frame, you will grab the id and form a new url to get the ratings information

spd_id <- pr_url_content$imdbID

spd_ratings_url <- paste(url_endpoint, api_key, "&i=", spd_id, sep = "")

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

Conclusion

Now you have a way to obtain the raitings from any movie or show contained in the OMDb API.