knitr::opts_chunk$set(
  cache = TRUE,
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%",
  message = FALSE, warning = FALSE, error = FALSE
)

tRakt

R-CMD-check Coverage status CRAN status GitHub release Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.

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.

Installation

Get it from GitHub:

if (!("remotes" %in% installed.packages())) {
  install.packages("remotes")
}
remotes::install_github("jemus42/tRakt")

library("tRakt")

Usage

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.

Credentials

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

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.

Code of Conduct

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.



jemus42/tRakt documentation built on Feb. 3, 2024, 10:58 p.m.