Created
September 21, 2021 13:15
-
-
Save fcecagno/b3b9efcc9a719f5b07d346593610c95e to your computer and use it in GitHub Desktop.
Export playback links
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
# encoding: UTF-8 | |
# Run with: | |
# ruby export-playback-links.rb | sudo tee ~/meus-links.csv | |
require 'csv' | |
require 'date' | |
require 'nokogiri' | |
def timestamp_to_date(ms) | |
DateTime.strptime(ms.to_s,'%Q') | |
end | |
def format_date_time(d, timezone_s = "America/Sao_Paulo") | |
timezone = TZInfo::Timezone.get(timezone_s) | |
local_date = timezone.utc_to_local(d) | |
local_date.strftime("%Y-%m-%d %H:%M:%S") | |
end | |
def record_id_to_timestamp(r) | |
r.split("-")[1].to_i | |
end | |
records = [] | |
`find /var/bigbluebutton/published/presentation/ -name metadata.xml`.split("\n").each do |filename| | |
doc = Nokogiri::XML(File.read(filename), nil, "UTF-8") { |x| x.noblanks } | |
xml_node = doc.at_xpath("/recording/id") | |
record = { | |
:record_id => xml_node.content | |
} | |
record[:timestamp] = record_id_to_timestamp(record[:record_id]) | |
record[:recorded_at] = timestamp_to_date(record[:timestamp]) | |
xml_node = doc.at_xpath('/recording/meta/meetingName') | |
record[:name] = xml_node.nil? ? "" : xml_node.text | |
xml_node = doc.at_xpath('/recording/meta/bbb-context') | |
record[:course] = xml_node.nil? ? "" : xml_node.text | |
xml_node = doc.at_xpath('/recording/playback/link') | |
record[:link] = xml_node.nil? ? "" : xml_node.text | |
records << record | |
end | |
records.sort_by!{ |record| record[:timestamp] } | |
s = CSV.generate({:col_sep => "\t"}) do |csv| | |
csv << [ "date", "course", "name", "link" ] | |
records.each do |record| | |
csv << [ record[:recorded_at], record[:course], record[:name], record[:link] ] | |
end | |
end | |
puts s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment