library(tRakt)

That’s all you need to to for basic things. If you’re planning a larger project with lots and lots of data retrieval, you might want to create your own API app on trakt.tv and use trakt_credentials() to set your client id.

Getting data from trakt.tv

1. Find things

Using a text query:

search_query("Game of Thrones", type = "show")
#> # A tibble: 1 x 9
#>   type  score title            year trakt slug            tvdb   imdb      tmdb 
#>   <chr> <dbl> <chr>           <int> <chr> <chr>           <chr>  <chr>     <chr>
#> 1 show   1000 Game of Thrones  2011 1390  game-of-thrones 121361 tt0944947 1399

Search by explicit ID:

search_id("121361", id_type = "tvdb", type = "show")
#> # A tibble: 1 x 9
#>   type  score title            year trakt slug            tvdb   imdb      tmdb 
#>   <chr> <dbl> <chr>           <int> <chr> <chr>           <chr>  <chr>     <chr>
#> 1 show   1000 Game of Thrones  2011 1390  game-of-thrones 121361 tt0944947 1399

Or via whatever’s popular(ish):

Another scenario would be that you’re not necessarily interested in some specific media item, but rather a collection of items that fulfill certain criteria, like being popular on trakt.tv and maybe being from a specific period or genre and whatnot. While you can also filter search_query by other criteria, it’s maybe more useful to filter, let’s say, the most watched movies of the past week by the release year of the movie.

The 5 most popular shows:

shows_popular(limit = 5)
#> # A tibble: 5 x 7
#>   title                year trakt slug                tvdb   imdb      tmdb 
#>   <chr>               <int> <chr> <chr>               <chr>  <chr>     <chr>
#> 1 Game of Thrones      2011 1390  game-of-thrones     121361 tt0944947 1399 
#> 2 Breaking Bad         2008 1388  breaking-bad        81189  tt0903747 1396 
#> 3 The Walking Dead     2010 1393  the-walking-dead    153021 tt1520211 1402 
#> 4 The Big Bang Theory  2007 1409  the-big-bang-theory 80379  tt0898266 1418 
#> 5 Sherlock             2010 19792 sherlock            176941 tt1475582 19885

The 10 most watched (during the past year) movies from 1990-2000:

library(dplyr)

movies_watched(period = "yearly", years = c(1990, 2000)) %>%
  select(watcher_count, title, year)
#> # A tibble: 10 x 3
#>    watcher_count title                                      year
#>            <int> <chr>                                     <int>
#>  1         54470 The Lion King                              1994
#>  2         53985 Toy Story                                  1995
#>  3         47933 The Matrix                                 1999
#>  4         47250 Beauty and the Beast                       1991
#>  5         46451 Aladdin                                    1992
#>  6         38742 Toy Story 2                                1999
#>  7         37118 Home Alone                                 1990
#>  8         31155 Star Wars: Episode I - The Phantom Menace  1999
#>  9         30468 Home Alone 2: Lost in New York             1992
#> 10         27643 Forrest Gump                               1994