1

I am using download.file to get mp3 files from a website which already allows you to download them (no funny business going on here!) but I want to create a function that scales up to get all the bird songs and very importantly give the right names to the files.

In the example script below you can see how to get one mp3 quite easily but note that the mp3 file is just named "3900" this page is found by going to the bird of choice's site such as the bearded reedling then right clicking on the play button for the song and opening it in a new tab which gives a nonsensical url "https://www.vogelwarte.ch/assets/media/voices/3900.mp3" in relation to the bird name

download.file(url = "https://www.vogelwarte.ch/assets/media/voices/3900.mp3"
          , destfile="~/Desktop/Birdsongs/bearded-reedling.mp3"
          , method="auto"
          , quiet = FALSE
          , cacheOK = TRUE
          , mode="wb"
          , extra = getOption("download.file.extra")
          , headers = NULL)

So my question is how can I keep some kind of consistent file naming while looping through all the bird names on the site so that I know which file belongs to which bird?

Nebulloyd
  • 264
  • 1
  • 9
  • Do you want to automatically detect pairs (like 3900 & bearded-reedling) or are you okay with manually finding the pairs and then afterwards downloading all files? In the latter case you can make a data.frame with each pair in a row and loop/apply/purrr over the rows. – robertdj Mar 20 '20 at 10:06
  • Related post: https://stackoverflow.com/q/31517121/680068 What we are trying to achieve is to find mp3 file link from selected bird page. – zx8754 Mar 20 '20 at 10:44
  • @Robert although since posting this I found an excel doc that gives me names and numbers I would really like to know how to gather this info in future situations where I don't find such a convenient file – Nebulloyd Mar 25 '20 at 17:05
  • 1
    @zx8754 This example is interesting and I would have liked to have done it this way but if you visit the page you will realise that it dynamically loads the bird names in as you scroll down so something a bit more sophisticated is needed to perform this – Nebulloyd Mar 25 '20 at 17:19

0 Answers0