-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.Rmd
135 lines (100 loc) · 5.7 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{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 <img src="https://jemus42.github.io/tRakt/reference/figures/logo.png" align="right" height="120"/>
<!-- badges: start -->
[![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)
<!-- badges: end -->
`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.