---
title: "Getting Started"
author: "Lukas Burk"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Getting Started}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  message = FALSE, warning = FALSE, error = FALSE,
  out.width = "100%"
)
```

```{r startup}
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](https://trakt.tv/oauth/applications) and use `trakt_credentials()` to set your `client id`.

# Getting data from trakt.tv

# 1. Find things

Using a text query:

```{r search}
search_query("Game of Thrones", type = "show")
```

Search by explicit ID:

```{r search_id}
search_id("121361", id_type = "tvdb", type = "show")
```

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:

```{r auto-lists}
shows_popular(limit = 5)
```
The 10 most watched (during the past year) movies from 1990-2000:

```{r auto-lists-watched}
library(dplyr)

movies_watched(period = "yearly", years = c(1990, 2000)) %>%
  select(watcher_count, title, year)
```
