## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----eval=FALSE, install------------------------------------------------------
# install.packages("tuber")

## ----eval=FALSE, install_g----------------------------------------------------
# devtools::install_github("gojiplus/tuber", build_vignettes = TRUE)

## ----eval=FALSE, loadlib------------------------------------------------------
# library(tuber)

## ----eval=FALSE, auth---------------------------------------------------------
# yt_oauth("998136489867-5t3tq1g7hbovoj46dreqd6k5kd35ctjn.apps.googleusercontent.com", "MbOSt6cQhhFkwETXKur-L9rN")

## ----eval=FALSE, prints-------------------------------------------------------
# ## Waiting for authentication in browser...
# ## Press Esc/Ctrl + C to abort
# ## Authentication complete.

## ----eval=FALSE, getstats-----------------------------------------------------
# get_video_stats(video_ids = "N708P-A45D0")

## ----eval=FALSE, getdetails---------------------------------------------------
# get_video_details(video_ids = "N708P-A45D0")

## ----eval=FALSE, getcaptions--------------------------------------------------
# tracks <- list_captions(video_id = "yJXTXN4xrI8")
# download_caption(tracks$caption_id[[1]])

## ----eval=FALSE, searchvids---------------------------------------------------
# res <- yt_search("Barack Obama")
# head(res[, 1:3])

## ----eval=FALSE, list_comments------------------------------------------------
# res <- list_comment_threads(c(video_id = "N708P-A45D0"))
# head(res)

## ----eval=FALSE, get_channel_vids_stats---------------------------------------
# a <- get_channel_details(
#   channel_ids = "UCT5Cx1l4IS3wHkJXNyuj4TA",
#   part = "contentDetails",
#   simplify = FALSE
# )
# 
# # Uploaded playlists:
# playlist_id <- a$items[[1]]$contentDetails$relatedPlaylists$uploads
# 
# # Get videos on the playlist
# vids <- list_playlist_items(playlist_id = playlist_id)
# 
# # Video ids
# vid_ids <- vids$video_id
# 
# # Get stats for all videos
# res_df <- get_video_stats(vid_ids)
# 
# head(res_df)

## ----eval=FALSE---------------------------------------------------------------
# res <- get_channel_details(usernames = "GoogleDevelopers", part = "id")
# 
# # Parse out channel_id
# if (!is.null(res$items[[1]]$id)) {
#   channel_id <- res$items[[1]]$id
# } else {
#   stop("User not found")
# }
# # channel_id should be UC_x5XG1OV2P6uZZ5FSM9Ttw

