3 ms·
> I started listening to Classical King FM That's a pretty great station, as long as you aren't listening around 4 AM (5 AM during daylight savings time). 4 A
by tzs 4y ago
> I started listening to Classical King FM
That's a pretty great station, as long as you aren't listening around 4 AM (5 AM during daylight savings time). 4 AM they make me want to scream with frustration.
4 AM is when their daily programming starts. The daily program usually doesn't run exactly 24 hours, so there is usually a gap between the end of one day's programming and the start of the next day's. The shortest gap I've seen was about 30 seconds and the longest was several minutes.
What they do during that gap is play lute or guitar music, usually solo but sometimes part of a small group. For example this morning they played Fernando Sor's Edude in A, OP. 31/19 with guitarist Norbert Kraft.
They seem to choose from all through the range of lute and classical guitar music from the Renaissance through at least the 20th century, and whoever is choosing is doing a great job. A majority of the time I've been awake for their gap music I've enjoyed the piece enough to want to find the sheet music and learn it myself (I dabble in classical guitar).
There are two problems.
1. The gap music does not show up on their playlist [1]. It does show up on the now playing display at the top of the playlist page. So if I'm barely awake in bed I've got to make myself wake up enough to get to a web browser to catch the now playing display.
2. At precisely 4 AM they start the next day's programming, regardless of whether the gap piece that was playing has actually finished.
I thought of having a cron job grab the playlist page with curl, but the now playing data is not part of the page source. It's added by JavaScript.
I suppose I could run something that uses an actual browser and then looks at the DOM to see what the JavaScript puts there.
I just gave that a try and this works on Mac, assuming you have an open Safari window for it to use. It's not pretty, especially that while loop in load_page(). It would be better to do the waiting for page load loop in the shell script.
#!/bin/sh
FILE=${1:-""}
osascript -l JavaScript <<HERE
var app = Application('Safari');
app.includeStandardAdditions = true;
function load_page()
{
let ct = app.windows[0].currentTab;
app.doJavaScript("document.title = 'not ready'", {in: ct});
app.windows[0].currentTab.url = 'https://www.king.org/music-schedule/';
let status = get_status();
while (status != 'complete:Music Playlist | Classical KING FM 98.1') {
status = get_status();
}
}
function get_status()
{
let ct = app.windows[0].currentTab;
return app.doJavaScript("document.readyState + ':' + document.title", {in: ct});
}
function now_playing(file_name)
{
let ct = app.windows[0].currentTab;
let playing = app.doJavaScript("document.getElementsByClassName('player-content')[0].innerText", {in: ct});
console.log(playing);
if (file_name != '') {
let path = Path(file_name)
let s = $.NSString.alloc.initWithUTF8String(playing)
s.writeToFileAtomicallyEncodingError(file_name, true, $.NSUTF8StringEncoding, null)
}
}
load_page();
now_playing("$FILE")
HERE
This could also be done using Apple Shortcuts. I'll have to think about that. A "What's Playing on KING" Shortcut could be useful. Being able to just call out "Hey Siri, what's playing on KING" would be quite convenient.
Oh wait...that would actually probably not work. When I call out "Hey Siri" it is usually my iPhone or iPad that responds, and the Shortcuts action for running JavaScript on a Safari page only works on mobile Safari if the Shortcut is invoked from the share sheet for that page. The shortcut would only work right when invoked on Mac.
[1] https://www.king.org/music-schedule/ https://www.king.org/music-schedule/
- mitthrowaway2 4y agoAhaha, I appreciate your passion for early-morning classical guitar! Fortunately, that's a problem I've never been enough of either an early bird or night owl to notice, even on some nights when I've stayed up working very late.