Created
February 18, 2022 12:36
-
-
Save qoobaa/d000fb89c6320f99497a1e5f0067be4a to your computer and use it in GitHub Desktop.
Revisions
-
qoobaa created this gist
Feb 18, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ 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)