Extract/scrape the IDs from a set of YouTube video URLs

Description

This function reads a list of YouTube video URLs from a text file and converts them to a vector object. For example, "https://www.youtube.com/watch?v=73I5dRucCds" has the ID "73I5dRucCds". This function can be used to create an object for the argument videoIDs in the function CollectDataYoutube, that is, by extracting the IDs for a set of YouTube videos and compiling them into a vector, ready for collecting data with CollectDataYoutube.

Usage

1

Arguments

file

The connection to read from. This can be a local file, or a http or ftp connection. It can also be a character string with the file name or URI. The file must be plain text format with the URL of each YouTube video specified on a new line (separated by character return). For example, the first line might contain https://www.youtube.com/watch?v=73I5dRucCds, and the second line might contain https://www.youtube.com/watch?v=6S9r_YbqHy8.

Value

a character vector representing a set of YouTube video IDs, each with number of characters equal to 11 (e.g. "73I5dRucCds").

Note

This function is useful for lots of videos. However, many videos may take a *long* time to collect data from. In such cases it is recommended to use the verbose=TRUE argument for the function CollectDataYoutube, in order to keep track of progress during computation.

Author(s)

Timothy Graham <timothy.graham3@uq.net.au> & Robert Ackland <robert.ackland@anu.edu.au>

See Also

Use CollectDataYoutube for collecting YouTube comments data.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Not run: 
  ## This example shows how to use `GetYoutubeVideoIDs` to extract video IDs from YouTube
  ## video URLs, and then collect data using the function `CollectDataYoutube`

  # Use your own Google Developer API Key here:
  myApiKey <- "1234567890"

  # Authenticate with the Google API
  apiKeyYoutube <- AuthenticateWithYoutubeAPI(apiKeyYoutube=myApiKey)

  # Use the function `GetYoutubeVideoIDs` to automatically generate vector of IDs from
  # a plain text file of video URLs
  videoIDs <- GetYoutubeVideoIDs(file="youtube_to_scrape.txt")

  # Collect the data using function `CollectDataYoutube`
  myYoutubeData <- CollectDataYoutube(videoIDs,apiKeyYoutube,writeToFile=FALSE)

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.