knitr::opts_chunk$set( cache = TRUE, collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%", message = FALSE, warning = FALSE, error = FALSE )
tRakt
helps you to retrieve data from trakt.tv, a site similar to IMDb with a wider focus, yet smaller user base. The site also enables media-center integration, so you can automatically sync your collection and watch progress, as well as scrobble playback and ratings via Plex, Kodi and the likes.
And, most importantly, trakt.tv has a publicly available API – which makes this package possible and allows you to collect all that nice data people have contributed.
Please note that while this package is basically an API-client, it is a little more opinionated and might deliver results that do not exactly match the data delivered by the API. The primary motivation for this package is to retrieve data that is easily processable for data analysis and display, which is why it tries hard to coerce most data into tabular form instead of using nested lists, which is what the direct translation of the API results would look like.
Get it from GitHub:
if (!("remotes" %in% installed.packages())) { install.packages("remotes") } remotes::install_github("jemus42/tRakt") library("tRakt")
library(dplyr) # for convenience library(tRakt)
Search for a show, get basic info:
show_info <- search_query("Utopia", type = "show") glimpse(show_info)
Get season information for the show using its trakt ID:
seasons_summary(show_info$trakt, extended = "full") |> glimpse()
Get episode data for the first season, this time using the show's URL slug:
seasons_season("utopia", seasons = 1, extended = "full") |> glimpse()
You cann also get episode data for all seasons, but note that episodes will be included as a list-column and need further unpacking:
seasons_summary("utopia", episodes = TRUE, extended = "full") |> pull(episodes) |> bind_rows() |> glimpse()
Or alternatively, get the trending shows:
shows_trending()
Maybe you just want to know how long it would take you to binge through these shows:
shows_trending(extended = "full") |> transmute( show = glue::glue("{title} ({year})"), runtime_hms = hms::hms(minutes = runtime), aired_episodes = aired_episodes, runtime_aired = hms::hms(minutes = runtime * aired_episodes) ) |> knitr::kable( col.names = c("Show", "Episode Runtime", "Aired Episodes", "Total Runtime (aired)") )
Please note though that episode runtime data may be inaccurate. In my experience, recent shows have fairly accurate runtime data, which is often not the case for older shows.
The API requires at least a client id
for the API calls.
Loading the package (or calling its functions via tRakt::
wil automatically set the app's client id (see trakt_credentials()
) – for extended use you should set your own credentials via environment variables in your .Renviron
like this:
# tRakt trakt_client_id=12fc1de7[...]3d629afdf2 trakt_client_secret=justabunchofstuffhere trakt_username=jemus42
trakt_client_id
Required. It's used in the HTTP headers for the API calls, which is kind of a biggie.trakt_client_secret
: Optional(ish). This is only required if you intend to make an authenticated request, which is only required by a small number of implemented API methods] (see vignette("Implemented-API-methods")
). You can use this package perfectly fine for basic data collection without registering an application on trakt.tv.trakt_username
Optional. For functions that retrieve a user's watched shows or stats, this just sets the default value so you don't have to keep supplying it in individual function calls when you're just looking at your own data anyway.To get your credentials, you have to have an (approved) app over at trakt.tv.
You theoretically never need to supply your own credentials. However, if you want to actually use this package for some project, I do not recommend relying on my credentials.
That would make me a sad panda.
As of now, the trakt.tv API does not have any rate-limiting, but it's not guaranteed to stay like this in the future.
Be nice to their servers.
Please note that the tRakt project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.