Skip to content

Instantly share code, notes, and snippets.

@tanho63
Created March 23, 2022 15:46
Show Gist options
  • Save tanho63/401742d060ced1df92cd5dae3ce74b79 to your computer and use it in GitHub Desktop.
Save tanho63/401742d060ced1df92cd5dae3ce74b79 to your computer and use it in GitHub Desktop.
Downloading videos from MLB API with R
# All base R actually but make sure libcurl is installed if you're on Linux
# Devtools -> Copy as cURL -> go to curlconverter.com/#r and paste -> mostly important to get headers in this case
# idk which of these work but this combo works
headers = c(
`User-Agent` = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0',
`Accept` = '*/*',
`Accept-Language` = 'en-US,en;q=0.5',
`Accept-Encoding` = 'gzip, deflate, br',
`Origin` = 'https://www.mlb.com',
`DNT` = '1',
`Connection` = 'keep-alive',
`Referer` = 'https://www.mlb.com/',
`Sec-Fetch-Dest` = 'empty',
`Sec-Fetch-Mode` = 'cors',
`Sec-Fetch-Site` = 'same-site'
)
download.file('https://fastball-clips.mlb.com/634460/home/604c3990-ed00-4b06-9345-ee782cd35259.mp4',
destfile = "x.mp4", # destination file
method = "libcurl", # use curl (because headers)
mode = "wb", # write file as binary
headers = headers) # headers from above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment