A classical analysis (Radio Swiss classic program)

I am not a classical music expert at all, but I happen to have friends who are, and am even married to someone playing the cello (and the ukulele!). I appreciate listening to such music from time to time, in particular Baroque music. A friend made me discover Radio Swiss classic, an online radio playing classical music all day and all night long, with a quite nice variety, and very little speaking between pieces, with no ads (thank you, funders of the radio!). Besides, the voices telling me which piece has just been played are really soothing, so Radio Swiss classic is a good one in my opinion.

Today, instead of anxiously waiting for the results of the French presidential elections, I decided to download the program of the radio in the last years and have a quick look at it, since after all, the website says that the radio aims at relaxing people.

Scraping the program

My webscraping became a bit more elegant because I followed the advice of EP alias expersso, who by the way should really start blogging. I started downloading programs since September 2008 because that’s when I met the friend who told me about Radio Swiss Classic.

datesseq(from=lubridate::ymd("2008-09-01"),to=lubridate::ymd("2017-04-22"),by="1 day")base_url"http://www.radioswissclassic.ch/en/music-programme/search/"get_one_day_programfunction(date,base_url){# in order to see progress
message(date)# build URL
date_as_stringas.character(date)date_as_stringstringr::str_replace_all(date_as_string,"-","")urlpaste0(base_url,date_as_string)# read page
pagetry(xml2::read_html(url),silent=TRUE)if(is(page,"try-error")){message("horribly wrong")closeAllConnections()return(NULL)}else{# find all times, artists and pieces
timesxml2::xml_text(xml2::xml_find_all(page,xpath="//span[@class='time hidden-xs']//text()"))artistsxml2::xml_text(xml2::xml_find_all(page,xpath="//span[@class='titletag']//text()"))piecesxml2::xml_text(xml2::xml_find_all(page,xpath="//span[@class='artist']//text()"))# the last artist and piece are the current ones
artistsartists[1:(length(artists)-1)]piecespieces[1:(length(pieces)-1)]# get a timedate from each time
timedatespaste(as.character(date),times)timedateslubridate::ymd_hm(timedates)timedateslubridate::force_tz(timedates,tz="Europe/Zurich")# format the output
programtibble::tibble(time=timedates,artist=artists,piece=pieces)return(program)}}programspurrr::map(dates,get_one_day_program,base_url=base_url)programsdplyr::bind_rows(programs)save(programs,file="data/radioswissclassic_programs.RData")

There were some days without any program on the website, for which the website said something was horribly wrong with the server.

I’ll have to admit that I don’t even know all the composers in this table but they’re actually all famous according to my live-in classical music expert. Radio Swiss classic allows listeners to rate pieces, so the most popular ones are programmed more often, and well I guess the person making the programs also tend to program famous composers quite often.

Interestingly, but not that surprisingly I guess given the popularity of, say, Mozart, the distribution of occurrences by composers seems to be log-normally distributed.

How long are pieces?

On the website of Radio Swiss classic it is stated that pieces are longer in the evening than during the day, which I wanted to try and see. Because the program of the radio was not corrected for time changes (i.e. on 25 hour-days there are only 24 hours of music according to the online program), I shall only look at pieces whose duration is smaller than 60 minutes, which solves the issue of missing days at the same time.

Conclusion

The website also states that the pieces are more lively in the morning, but I have no data to which to match the titles of the pieces to investigate that claim. Well I have not even looked for such data. Another extension that I would find interesting would be to match each composer’s name to a style and then see how often each style is played. Now I’ll stop relaxing and go stuff my face with food in front of the election results!