Skip to contents

This function downloads YouTube videos or Soundcloud or any other platform supported by the youtube-dl library, and converts them into high quality MP3 files. The URL can be for a single video or a whole playlist. It also returns metadata into an (invisible) list.

Usage

get_mp3(
  id,
  mp3 = TRUE,
  repo = "youtube-dl",
  params = "--no-check-certificate",
  start_time = 0,
  end_time = NA,
  overwrite = TRUE,
  open = FALSE,
  delete = open,
  info = TRUE,
  cover = FALSE,
  quiet = FALSE
)

Arguments

id

Character. YouTube URL or ID to search for.

mp3

Boolean. Add mp3 optimal parameters?

repo

Character. Chose repository you installed youtube-dl from. Any of: "youtube-dl" (latest stable version), "yt-dlp" (latest dev version).

params

Character. Additional parameters.

start_time, end_time

Numeric. Start and end time to trim the audio output in seconds.

overwrite

Boolean. Overwrite original file?

open, delete

Boolean. After everything's done, should the file be opened? Should it be deleted?

info

Boolean. Import and return metadata?

cover

Boolean. Google Search its squared cover?

quiet

Boolean. Keep quiet? If not, print messages.

Value

(Invisible) list with id's meta-data.

youtube-dl

More info from the original developers and its code: youtube-dl's Github

See also

Other Scrapper: filesGD(), gtrends_related(), holidays(), ip_data(), readGS(), splot_etf(), stocks_quote()

Other Audio: trim_mp3()

Examples

# You must have "youtube-dl" installed in your OS:
if (FALSE) {
# Download video from YouTube and convert to MP3
get_mp3("https://www.youtube.com/watch?v=lrlKcCdVw9Q")
# OR simply
get_mp3("lrlKcCdVw9Q")
# For dev version, use:
get_mp3("m3RX4LJh0iI", repo = "yt-dlp")
}