Skip to content

Instantly share code, notes, and snippets.

@qoobaa
Created February 18, 2022 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qoobaa/d000fb89c6320f99497a1e5f0067be4a to your computer and use it in GitHub Desktop.
Save qoobaa/d000fb89c6320f99497a1e5f0067be4a to your computer and use it in GitHub Desktop.
require 'json'
require 'open-uri'
require 'open3'
STREAMS_URL = 'https://mixlr-codetest.herokuapp.com/stations/netil-radio/streams'
body = URI.open(STREAMS_URL).read
json = JSON.parse(body)
volumes = json.dig('data', 'attributes', 'streams').map do |stream_name, url|
_, stderr, process_info = Open3.capture3('ffmpeg', '-t', '3', '-i', url, '-af', 'volumedetect', '-f', 'null', '/dev/null')
mean_volume = stderr.match(/mean_volume: (.*) dB/)[1].to_f
max_volume = stderr.match(/max_volume: (.*) dB/)[1].to_f
{stream_name:, mean_volume:, max_volume:}
end
puts JSON.pretty_generate(volumes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment