-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
121 lines (92 loc) · 3.46 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%",
eval = FALSE
)
```
# youtubeR
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![CRAN status](https://www.r-pkg.org/badges/version/youtubeR)](https://CRAN.R-project.org/package=youtubeR)
[![Codecov test coverage](https://codecov.io/gh/kevin-m-kent/youtubeR/branch/main/graph/badge.svg)](https://app.codecov.io/gh/kevin-m-kent/youtubeR?branch=main)
[![R-CMD-check](https://github.com/kevin-m-kent/youtubeR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/kevin-m-kent/youtubeR/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
A package for interacting with the Youtube Data API.
This package is being developed first to aid in the processing of [R4DS Online Learning Community](https://r4ds.io) book club videos.
As such, functionality will be focused where it is needed for that task.
Long-term, we hope to implement the entire YouTube API.
## Installation
::: {.pkgdown-release}
Install the released version of youtubeR from [CRAN](https://cran.r-project.org/):
``` r
# Not yet!
install.packages("youtubeR")
```
:::
::: {.pkgdown-devel}
Install the development version of youtubeR from [GitHub](https://github.com/):
``` r
# install.packages("pak")
pak::pak("kevin-m-kent/youtubeR")
```
:::
## Setting up
### Step 1: Create an OAuth 2.0 client.
We'll add details here about the settings to apply in your client.
You'll need to enable the YouTube Data API v3.
```{r browse}
library(youtubeR)
browse_gc_credentials()
# Copy the client id and client secret.
```
### Step 2: Set up environment variables
```{r env}
# Use the values copied above.
Sys.setenv(YOUTUBE_CLIENT_ID = "12345-ab12c.apps.googleusercontent.com")
Sys.setenv(YOUTUBE_CLIENT_SECRET = "ABCD-eFg_H")
# Ideally, set these in your .Renviron file.
```
### Step 3: Use the package
You should now be set up to call functions in the package.
The first time you call a function interactively, you will be asked to authorize your client to act on your behalf (in your web browser).
## Retrieving Video Status
The goal here is to get the video status (if it is finished processing) for
each video that has been uploaded.
The workflow is as follows:
- Get the playlist ids
- For each playlist, get the video ids
- For each video, get the status
```{r video-status}
my_playlist_id <- get_upload_playlist_id()
video_ids <- get_playlist_video_ids(my_playlist_id)
video_details <- get_video_processing_details(video_ids)
```
## Uploading Videos
Following a similar workflow, we can also upload videos to youtube.
Assuming you already have created the client as above, you will need a snippet and a video path.
The snippet defines the title, description, and other metadata for the video.
The video path is the path to the video file on your local machine.
```{r upload}
snippet <- yt_schema_video_snippet(
title = "video test",
description = "description of this test video",
tags = c("example tag", "another tag")
)
status <- yt_schema_video_status(
privacy_status = "private",
self_declared_made_for_kids = FALSE
)
video_path <- "path/to/video.mp4"
yt_videos_insert(
video_path = video_path,
snippet = snippet,
status = status
)
```