get_caption: Obtaining YouTube video caption/subtitle in a tidy tibble...

Description Usage Arguments Details Value Author(s) References Examples

View source: R/get_caption.R

Description

Use this function for downloading a desired YouTube video caption in a tidy tibble data_frame form and save it as an Excel file in your current working directory.

Usage

1
2
3
4
5
6
7
get_caption(
  url = NULL,
  language = "en",
  savexl = FALSE,
  openxl = FALSE,
  path = getwd()
)

Arguments

url

A string value for a single YouTube video link URL. A typical form should start with "https://www.youtube.com/watch?v=" followed by a unique video ID.

language

two-character language code for the video URL. Set to "en" (English) by default. You can change this to fit with your needs (e.g., "ko" for Korean, "de" for German, etc.).

savexl

A logical value for determining whether or not to save the obtained tidy YouTube caption data as an Excel file. The default is FALSE which does not save it as a file. If set to TRUE, a file named "YouTube_caption_videoID.xlsx" is saved in your specified directory (the default is your current working directory).

openxl

A logical value for determining whether or not to open, if any, the saved YouTube_caption Excel file in your working directory. The default is FALSE. TRUE works only when the preceding argument (i.e., savexl) is set to TRUE.

path

A character vector of full path names; the default corresponds to the working directory, getwd. Tilde expansion (see path.expand) is performed. Missing values will be ignored.

Details

get_caption

See example below.

Value

tibble (advanced data.frame) object for a YouTube video caption will be returned.

Author(s)

JooYoung Seo, jooyoung@psu.edu

Soyoung Choi, sxc940@psu.edu

References

https://pypi.org/project/youtube-transcript-api/

Examples

1
2
3
4
5
6
7
8
9
library(youtubecaption)
# Let's get the video caption out of Hadley Wickham's "You can't do data science in a GUI":
url <- "https://www.youtube.com/watch?v=cpbtcsGE0OA"
caption <- get_caption(url)
caption

# Save the caption as an Excel file and open it right it away
## Changing path to temp for the demonstration purpose only:
get_caption(url = url, savexl = TRUE, openxl = TRUE, path = tempdir())

youtubecaption documentation built on July 1, 2020, 10:56 p.m.