Getting Started

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 × 9
#>   type  score title           year trakt  slug           tvdb   imdb      tmdb 
#>   <chr> <dbl> <chr>          <int> <chr>  <chr>          <chr>  <chr>     <chr>
#> 1 show  1250. Gay of Thrones  2013 108159 gay-of-thrones 312618 tt2946308 66901

Search by explicit ID:

search_id("121361", id_type = "tvdb", type = "show")
#> # A tibble: 1 × 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 × 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 Stranger Things      2016 104439 stranger-things     305288 tt4574334 66732

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 × 3
#>    watcher_count title                       year
#>            <int> <chr>                      <int>
#>  1         44201 The Matrix                  1999
#>  2         32589 Home Alone                  1990
#>  3         28468 Fight Club                  1999
#>  4         25847 The Shawshank Redemption    1994
#>  5         24105 Forrest Gump                1994
#>  6         23279 Pulp Fiction                1994
#>  7         23249 Toy Story                   1995
#>  8         22204 Terminator 2: Judgment Day  1991
#>  9         22193 Gladiator                   2000
#> 10         21693 The Lion King               1994