Skip to content

inSileco/omdbr

Repository files navigation

omdbr

R build status CRAN_Status_Badge License: GPL v3 r-universe

The package omdbr is an R client to the OMDb API. User can retrieve information on movies (title, actors, year, genres, etc.) and download cover (if available) using the YTS API.

Prerequisites

This package uses the OMDb API which requires an API Key. You can freely obtain your own here. When you’ll use the package omdbr for the first time, you’ll be guided on how to store your personal API key.

Installation

To install the omdbr package, run the following command:

remotes::install_github("inSileco/omdbr")

and load the package:

library(omdbr)

Example

Objective: Getting information and cover for The Darjeeling Limited movie directed by Wes Anderson.

STEP 1: Find the IMDb identifier of the movie

The package omdbr uses the IMDb ID the retrieves information and cover of a movie. The function find_imdb_id() tries to find this ID.

x <- find_imdb_id("The Darjeeling Limited")
## ────────────────────────────────────────────────────────────────────────────────
## ℹ Searching 'The Darjeeling Limited' in movies title...
## ✔ 2 matches found!
##   Returning the 2 best matches
## ────────────────────────────────────────────────────────────────────────────────
str(x)
## 'data.frame':    2 obs. of  3 variables:
##  $ title : chr  "The Darjeeling Limited" "The Darjeeling Limited (2007)"
##  $ year  : chr  "2007" "2007"
##  $ imdbid: chr  "tt0838221" "tt24819872"
##                           title year     imdbid
## 1        The Darjeeling Limited 2007  tt0838221
## 2 The Darjeeling Limited (2007) 2007 tt24819872

💡 The argument year can be used to reduce results.

💡 You can also find this ID by searching the movie title on the IMDb website and extract it from the URL. The URL of The Darjeeling Limited is: https://imdb.com/title/tt0838221.

STEP 2: Get movie information

To retrieve information about the movie we will use the function get_details():

x <- get_details(imdb_id = "tt0838221")
## ────────────────────────────────────────────────────────────────────────────────
## 
## - imdbid: tt0838221
##   type: movie
##   title: The Darjeeling Limited
##   year: 2007.0
##   runtime: 91.0
##   director: Wes Anderson
##   writer:
##     - Wes Anderson
##     - Roman Coppola
##     - Jason Schwartzman
##   actors:
##     - Owen Wilson
##     - Adrien Brody
##     - Jason Schwartzman
##   genre:
##     - Adventure
##     - Comedy
##     - Drama
##   plot: A year after their father's funeral, three brothers travel across India by train
##     in an attempt to bond with each other.
##   language:
##     - English
##     - Hindi
##     - German
##     - Punjabi
##     - Tibetan
##     - French
##   country:
##     - United States
##     - India
##   imdbrating: 7.2
##   slug: the-darjeeling-limited-2007
## 
## ────────────────────────────────────────────────────────────────────────────────
class(x)
## [1] "data.frame"
##      imdbid  type                  title year runtime     director
## 1 tt0838221 movie The Darjeeling Limited 2007      91 Wes Anderson
##                                           writer
## 1 Wes Anderson, Roman Coppola, Jason Schwartzman
##                                         actors                    genre
## 1 Owen Wilson, Adrien Brody, Jason Schwartzman Adventure, Comedy, Drama
##                                                                                                                      plot
## 1 A year after their father's funeral, three brothers travel across India by train in an attempt to bond with each other.
##                                           language              country
## 1 English, Hindi, German, Punjabi, Tibetan, French United States, India
##   imdbrating                        slug
## 1        7.2 the-darjeeling-limited-2007

💡 Results are stored in data/tt0838221.yml (path can be changed by using the argument path).

If you want to get access to these data you can use the function read_details():

x <- read_details(imdb_id = "tt0838221")
##      imdbid  type                  title year runtime     director
## 1 tt0838221 movie The Darjeeling Limited 2007      91 Wes Anderson
## 2 tt0838221 movie The Darjeeling Limited 2007      91 Wes Anderson
##                                           writer
## 1 Wes Anderson, Roman Coppola, Jason Schwartzman
## 2 Wes Anderson, Roman Coppola, Jason Schwartzman
##                                                      actors
## 1 Owen Wilson, Adrien Brody, Jason Schwartzman, Amara Karan
## 2              Owen Wilson, Adrien Brody, Jason Schwartzman
##                      genre
## 1 Adventure, Comedy, Drama
## 2 Adventure, Comedy, Drama
##                                                                                                                      plot
## 1 A year after their father's funeral, three brothers travel across India by train in an attempt to bond with each other.
## 2 A year after their father's funeral, three brothers travel across India by train in an attempt to bond with each other.
##                                           language              country
## 1 English, Hindi, German, Punjabi, Tibetan, French                  USA
## 2 English, Hindi, German, Punjabi, Tibetan, French United States, India
##   imdbrating                        slug
## 1        7.2 the-darjeeling-limited-2007
## 2        7.2 the-darjeeling-limited-2007

STEP 3: Get movie cover

Now, we can try to download the movie cover with the function get_cover():

get_cover(imdb_id = "tt0838221")
## ✔ Cover found for 'tt0838221' !

💡 Results are stored as follow:

.
├── covers
│   └──tt0838221.jpg
└── data
    └──tt0838221.yml

2 directories, 2 files

Code of Conduct

Please note that the omdbr project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Releases

No releases published

Packages

No packages published

Languages