On my blog a radio channel can be listened, either the live broadcast, or the previous broadcasts from the archive of the channel by a timetable.
I would like to achieve that visitors would be able to save these older broadcasts with their distinctive programme name. When visitors click on the given timestamp, the appropriate or appropriately parameterized URL is loaded into a HTML5 audio object's source.
There are two kinds of URL formats, the first one, only for the current day: http://example.com/20190707080000/20190707090000/channel1.mp3
In this case I can exploit the following hack: instead of the latest URL, I load the following URL into the audio player: http://example.com/20190707080000/20190707090000/channel1.mp3/Title_of_the_programme.mp3
In this case the visitor will be able to save the listened program by the given filename: "Title_of_the_programme.mp3".
The other URLs, for the other days, than the current day, are different, as those programmes were already archived, maybe in a lower bitrate and/or format: http://example.com/2019/07/06/channe11.mp4?start=28800&end=32400 "start" and "end" parameters are for the given second of the day, when the actual programme starts and ends.
In this second case the aforementioned hack doesn't work any more, so I can't load a similar URL into the HTML5 audio player: http://example.com/2019/07/06/channel1.mp4?start=28800&end=32400/Title_of_the_programme.mp4
Unfortunately it doesn't work, when I click on the save as button of the HTML5 audio player, the filename will always be "channel1.mp4", which is suboptimal.
In both cases the full programme is served at once for a GET request.
The "download" attribute, "a[download]" for the HTML "A" element or the same attribute for the HTML5 "audio" element also doesn't work, due to the browser's same origin policy: the domain of the radio is of course different than my blog domain.
Fetching the resulting media file with an Ajax call (XMLhttprequest) into a browser blob also doesn't work, due to the same origin policy. The server of the radio of course doesn't provide the appropriate header field for these Ajax calls: "Access-Control-Allow-Origin: *".
The response headers of the radio programme URLs doesn't contain a "content-disposition" header field, so the filename must be determined by the URL itself.
http://example.com/2019/07/06/channel1.mp4/Title_of_the_programme.mp4?start=28800&end=32400
? With the approach in your solution, the value of theend
query parameter will be parsed as32400/Title_of_the_programme.mp4
– Paraprofessional