After several weeks, tear his hair out, trying to figure it out on his own. I managed to find a very hacky solution to this problem.
You will not like it, though, be careful.
To get the current playable track, even if the sound is transmitted from Beats radio, you will need to consider the OCR approach (taking a screenshot, converting the image to text).
The following Ruby code will help you get started with this solution.
It will check the current track, and if the artist field is empty (which is the case when streaming a track), then it falls into the OCR method.
require 'json' require 'rtesseract' class CurrentTrack def self.check js_command = %Q{var itunes = Application("iTunes"); var currentTrack = itunes.currentTrack; JSON.stringify({ window_bounds: itunes.windows[0].bounds(), name: currentTrack.name(), artist: currentTrack.artist(), position: itunes.playerPosition() }) } command = "osascript -l JavaScript -e '#{js_command}'" result = '#{command}' json = JSON.parse(result, symbolize_names: true) json[:position] = json[:position].to_i json[:cue] = Time.at(json[:position]).utc.strftime('%H:%M:%S') if json[:artist] == '' sc_command = %Q{screencapture -R #{json[:window_bounds][:x]},#{json[:window_bounds][:y].to_i + 30},#{json[:window_bounds][:width]},#{json[:window_bounds][:height]} capture.png} '#{sc_command}' image = RTesseract.new("capture.png", processor: 'none') ocr = image.to_s.split("\n")
You will need to install rtesseract for this to work.
Caveats, this script requires the iTunes mini-player window to be visible somewhere on your desktop.
halfcube
source share