Created
February 18, 2022 12:36
-
-
Save qoobaa/d000fb89c6320f99497a1e5f0067be4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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