Last active
October 9, 2019 10:48
-
-
Save njh/e5d536a684fda15380302bd648c89dc2 to your computer and use it in GitHub Desktop.
Make spreadsheet of services from a directory containing Radioplayer Service Information XML files
This file contains 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
#!/usr/bin/env ruby | |
# | |
# A little script to read Radioplayer Service Information XML files from a directory and | |
# write one per row to a CSV file | |
# | |
# Input: radioplayer/*.xml | |
# Output: radioplayer_services.csv | |
# | |
require 'csv' | |
require 'nokogiri' | |
CSV.open('radioplayer_services.csv', 'wb') do |csv| | |
csv << [ | |
'Id', | |
'Short Name', | |
'Medium Name', | |
'Long Name', | |
'Console URL', | |
'Low Bitrate Stream', | |
'High Bitrate Stream' | |
] | |
Dir.glob('radioplayer/*.xml') do |filename| | |
doc = Nokogiri::XML(File.open(filename)) | |
doc.remove_namespaces! | |
service = doc.at('/serviceInformation/ensemble/service') | |
return if (!service) | |
streams = [] | |
service.xpath('//listenlive//audioStream').each do |stream| | |
streams.push({ | |
:url => stream.at('audioSource')['url'], | |
:mimeValue => stream.at('audioSource')['mimeValue'], | |
:bitrate => stream.at('bitRate')['target'].to_i, | |
}) | |
end | |
streams.sort_by! {|s| s[:bitrate]} | |
csv << [ | |
service.at('radioplayerId')['id'], | |
service.at('shortName').inner_text, | |
service.at('mediumName').inner_text, | |
service.at('longName').inner_text, | |
service.at('//listenlive/player').inner_text, | |
streams.first[:url], | |
streams.last[:url], | |
] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment