Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jemus42/trakt
A trakt.tv API wrapper in R.
https://github.com/jemus42/trakt
r r-package rstats trakt trakt-api trakttv
Last synced: 12 days ago
JSON representation
A trakt.tv API wrapper in R.
- Host: GitHub
- URL: https://github.com/jemus42/trakt
- Owner: jemus42
- License: other
- Created: 2014-07-01T11:48:21.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2024-10-01T18:33:59.000Z (about 1 month ago)
- Last Synced: 2024-10-11T18:18:32.770Z (27 days ago)
- Topics: r, r-package, rstats, trakt, trakt-api, trakttv
- Language: R
- Homepage: https://jemus42.github.io/tRakt/
- Size: 19 MB
- Stars: 21
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codemeta: codemeta.json
Awesome Lists containing this project
README
---
output: github_document
editor_options:
chunk_output_type: console
---```{r setup, include = FALSE}
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](https://github.com/jemus42/tRakt/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/jemus42/tRakt/actions/workflows/R-CMD-check.yaml)
[![Coverage status](https://codecov.io/gh/jemus42/tRakt/branch/master/graph/badge.svg)](https://codecov.io/github/jemus42/tRakt?branch=master)
[![CRAN status](https://www.r-pkg.org/badges/version/tRakt)](https://cran.r-project.org/package=tRakt)
[![GitHub release](https://img.shields.io/github/release/jemus42/tRakt.svg?logo=GitHub)](https://github.com/jemus42/tRakt/releases)
[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)`tRakt` helps you to retrieve data from [trakt.tv](https://trakt.tv/), a site similar to [IMDb](https://imdb.com) 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](https://www.plex.tv/), [Kodi](https://kodi.tv/) and the likes.
And, most importantly, [trakt.tv has a publicly available API](https://trakt.docs.apiary.io) – 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:
```r
if (!("remotes" %in% installed.packages())) {
install.packages("remotes")
}
remotes::install_github("jemus42/tRakt")library("tRakt")
```## Usage
```{r}
library(dplyr) # for convenience
library(tRakt)
```Search for a show, get basic info:
```{r}
show_info <- search_query("Utopia", type = "show")
glimpse(show_info)
```Get season information for the show using its trakt ID:
```{r}
seasons_summary(show_info$trakt, extended = "full") |>
glimpse()
```Get episode data for the first season, this time using the show's URL slug:
```{r}
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:
```{r}
seasons_summary("utopia", episodes = TRUE, extended = "full") |>
pull(episodes) |>
bind_rows() |>
glimpse()
```Or alternatively, get the [trending shows](https://trakt.tv/shows/trending):
```{r}
shows_trending()
```Maybe you just want to know how long it would take you to binge through these shows:
```{r}
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:```sh
# 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](http://trakt.tv/oauth/applications).
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](.github/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.