Search code examples
raudiodownloadmp3

download.file corrupts .mp3 file in R


I'm trying to download a long list of podcasts, but when I use the download.file command in R it corrupts the audio file into a bunch of crackling noises.

Could any of you recommend a dedicated audio-downloading package, or recommend a download.file method that would be better suited for download audio. I went through the ones listed in the help file, but none worked. ("auto", "internal", "wininet", "libcurl", "wget" and "curl")

The downloading portion of the code looks similar to this:

url <- "http://play.podtrac.com/npr-510289/npr.mc.tritondigital.com/NPR_510289/media/anon.npr-mp3/npr/pmoney/2016/06/20160603_pmoney_podcast.mp3?
orgId=1&amp;d=1121&amp;p=510289&amp;story=480606726&amp;t=podcast&amp;e=480606726&amp;siteplayer=true&amp;dl=1"

download.file(url = url, destfile = "test.mp3")

I attempted different audio files from different sites and had similar results.

Edit: In response to the question by VC.One, this a url to the initial section of the Hex code. I added in more than the couple of lines he requested because the first section looked like file information which may or may not be relevant:


Solution

  • Try mode = "wb" in download.file(). I had the same issue you mentioned and this solved it for me.