2019-10-08 03:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-09-05 05:42:13 +08:00
|
|
|
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
|
|
|
|
#
|
2017-10-31 03:04:30 +08:00
|
|
|
# Copyright (c) 2017 BigBlueButton Inc. and by respective authors (see below).
|
2012-09-05 05:42:13 +08:00
|
|
|
#
|
2017-10-31 03:04:30 +08:00
|
|
|
# This program is free software; you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Lesser General Public License as published by the Free
|
|
|
|
# Software Foundation; either version 3.0 of the License, or (at your option)
|
|
|
|
# any later version.
|
2012-09-05 05:42:13 +08:00
|
|
|
#
|
2017-10-31 03:04:30 +08:00
|
|
|
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
# details.
|
2012-09-05 05:42:13 +08:00
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
2012-05-04 02:56:01 +08:00
|
|
|
|
2017-07-10 23:42:40 +08:00
|
|
|
require File.expand_path('../../../lib/recordandplayback', __FILE__)
|
2011-05-10 05:24:41 +08:00
|
|
|
require 'logger'
|
2021-11-24 10:59:59 +08:00
|
|
|
require 'optimist'
|
2011-04-26 05:04:10 +08:00
|
|
|
require 'yaml'
|
|
|
|
|
2019-10-08 03:17:27 +08:00
|
|
|
AUDIO_ARCHIVE_FORMAT = {
|
|
|
|
extension: 'opus',
|
|
|
|
# TODO: consider changing bitrate based on channels or sample rate - this is
|
|
|
|
# overkill if freeswitch is configured in a mono or low quality profile
|
2019-10-23 22:15:59 +08:00
|
|
|
parameters: [
|
|
|
|
%w[-c:a libopus -b:a 128K -f ogg],
|
|
|
|
]
|
2019-10-08 03:17:27 +08:00
|
|
|
}.freeze
|
|
|
|
|
2018-12-15 06:16:12 +08:00
|
|
|
def archive_events(meeting_id, redis_host, redis_port, redis_password, raw_archive_dir, break_timestamp)
|
2017-11-02 00:31:07 +08:00
|
|
|
BigBlueButton.logger.info("Archiving events for #{meeting_id}")
|
2019-10-08 03:17:27 +08:00
|
|
|
redis = BigBlueButton::RedisWrapper.new(redis_host, redis_port, redis_password)
|
|
|
|
events_archiver = BigBlueButton::RedisEventsArchiver.new(redis)
|
2019-10-23 22:15:59 +08:00
|
|
|
events_archiver.store_events(meeting_id, File.join(raw_archive_dir, meeting_id, 'events.xml'), break_timestamp) do |events|
|
2019-10-08 03:17:27 +08:00
|
|
|
# Adjust the audio filenames to match the audio archive format
|
|
|
|
events.xpath('/recording/event[@module="VOICE"]/filename').each do |filename|
|
|
|
|
if filename.content.end_with?('.wav')
|
|
|
|
filename.content = "#{File.basename(filename.content, '.wav')}.#{AUDIO_ARCHIVE_FORMAT[:extension]}"
|
|
|
|
end
|
|
|
|
end
|
2011-05-12 01:52:39 +08:00
|
|
|
end
|
|
|
|
end
|
2011-05-10 05:24:41 +08:00
|
|
|
|
2021-03-24 04:35:08 +08:00
|
|
|
def archive_notes(meeting_id, notes_endpoint, notes_formats, raw_archive_dir)
|
2019-03-06 00:17:48 +08:00
|
|
|
BigBlueButton.logger.info("Archiving notes for #{meeting_id}")
|
2021-03-24 04:35:08 +08:00
|
|
|
events = Nokogiri::XML(File.open("#{raw_archive_dir}/#{meeting_id}/events.xml"))
|
|
|
|
notes_id = BigBlueButton::Events.get_notes_id(events)
|
|
|
|
|
2019-03-12 10:56:29 +08:00
|
|
|
notes_dir = "#{raw_archive_dir}/#{meeting_id}/notes"
|
|
|
|
FileUtils.mkdir_p(notes_dir)
|
2019-03-16 04:19:54 +08:00
|
|
|
|
|
|
|
tmp_note = "#{notes_dir}/tmp_note.txt"
|
2022-06-16 20:13:31 +08:00
|
|
|
base_path_notes = CGI.escape notes_id
|
|
|
|
if base_path_notes != "undefined"
|
|
|
|
BigBlueButton.try_download("#{notes_endpoint}/#{base_path_notes}/export/txt", tmp_note)
|
|
|
|
end
|
2019-03-16 04:19:54 +08:00
|
|
|
if File.exist? tmp_note
|
|
|
|
# If the notes are empty, do not archive them
|
|
|
|
blank = false
|
|
|
|
content = File.open(tmp_note).read
|
|
|
|
if content.strip.empty?
|
|
|
|
blank = true
|
|
|
|
end
|
|
|
|
FileUtils.rm_f(tmp_note)
|
|
|
|
if blank
|
|
|
|
BigBlueButton.logger.info("Empty notes for #{meeting_id}")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
else
|
|
|
|
BigBlueButton.logger.info("Notes were not used in #{meeting_id}")
|
|
|
|
return
|
2011-05-10 05:24:41 +08:00
|
|
|
end
|
|
|
|
|
2019-03-12 10:56:29 +08:00
|
|
|
notes_formats.each do |format|
|
2021-03-24 04:35:08 +08:00
|
|
|
BigBlueButton.try_download("#{notes_endpoint}/#{CGI.escape notes_id}/export/#{format}", "#{notes_dir}/notes.#{format}")
|
2011-05-10 05:24:41 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-31 03:04:30 +08:00
|
|
|
def archive_audio(meeting_id, audio_dir, raw_archive_dir)
|
2019-10-29 01:47:33 +08:00
|
|
|
BigBlueButton.logger.info("Archiving audio #{audio_dir}/#{meeting_id}-*.*")
|
|
|
|
audio_dest_dir = File.join(raw_archive_dir, meeting_id, 'audio')
|
2017-11-07 04:22:43 +08:00
|
|
|
FileUtils.mkdir_p(audio_dest_dir)
|
2019-10-29 01:47:33 +08:00
|
|
|
audio_files = Dir.glob("#{audio_dir}/#{meeting_id}-*.*")
|
2017-11-07 23:03:20 +08:00
|
|
|
if audio_files.empty?
|
|
|
|
BigBlueButton.logger.warn("No audio found for #{meeting_id}")
|
|
|
|
return
|
2011-05-10 05:24:41 +08:00
|
|
|
end
|
2019-10-08 03:17:27 +08:00
|
|
|
audio_files.each do |audio_file|
|
2019-10-29 01:47:33 +08:00
|
|
|
# Recompress the audio only if freeswitch saved an uncompressed wav, otherwise copy
|
|
|
|
if audio_file.end_with?('.wav')
|
|
|
|
output_basename = File.join(audio_dest_dir, File.basename(audio_file, '.wav'))
|
|
|
|
# Note that the encode method saves to a temp file then renames to the
|
|
|
|
# final filename, making this safe for segmented recordings that are
|
|
|
|
# concurrently being processed.
|
|
|
|
BigBlueButton::EDL.encode(audio_file, nil, AUDIO_ARCHIVE_FORMAT, output_basename)
|
|
|
|
else
|
|
|
|
ret = BigBlueButton.exec_ret('rsync', '-stv', audio_file, audio_dest_dir)
|
|
|
|
BigBlueButton.logger.warn("Failed to archive #{audio_file}") if ret != 0
|
|
|
|
end
|
2016-02-26 01:59:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-28 03:02:09 +08:00
|
|
|
def delete_audio(meeting_id, audio_dir)
|
|
|
|
BigBlueButton.logger.info("Deleting audio #{audio_dir}/#{meeting_id}-*.*")
|
|
|
|
Dir.glob("#{audio_dir}/#{meeting_id}-*.*").each do |audio_file|
|
|
|
|
FileUtils.rm_f(audio_file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-31 03:04:30 +08:00
|
|
|
def archive_directory(source, dest)
|
|
|
|
BigBlueButton.logger.info("Archiving contents of #{source}")
|
2017-11-07 04:22:43 +08:00
|
|
|
FileUtils.mkdir_p(dest)
|
|
|
|
ret = BigBlueButton.exec_ret('rsync', '-rstv',
|
2017-10-31 03:04:30 +08:00
|
|
|
"#{source}/", "#{dest}/")
|
|
|
|
if ret != 0
|
|
|
|
BigBlueButton.logger.warn("Failed to archive contents of #{source}")
|
2011-05-10 05:24:41 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-04 03:17:04 +08:00
|
|
|
def archive_has_recording_marks?(meeting_id, raw_archive_dir, break_timestamp)
|
2013-10-03 01:18:26 +08:00
|
|
|
BigBlueButton.logger.info("Fetching the recording marks for #{meeting_id}.")
|
2018-05-16 23:27:12 +08:00
|
|
|
|
2017-11-04 03:17:04 +08:00
|
|
|
doc = Nokogiri::XML(File.open("#{raw_archive_dir}/#{meeting_id}/events.xml"))
|
2017-11-04 04:12:05 +08:00
|
|
|
|
|
|
|
# Find the start and stop timestamps for the current recording segment
|
|
|
|
start_timestamp = BigBlueButton::Events.get_segment_start_timestamp(
|
|
|
|
doc, break_timestamp)
|
|
|
|
end_timestamp = BigBlueButton::Events.get_segment_end_timestamp(
|
|
|
|
doc, break_timestamp)
|
|
|
|
BigBlueButton.logger.info("Segment start: #{start_timestamp}, end: #{end_timestamp}")
|
|
|
|
|
|
|
|
BigBlueButton.logger.info("Checking for recording marks for #{meeting_id} segment #{break_timestamp}")
|
|
|
|
rec_events = BigBlueButton::Events.match_start_and_stop_rec_events(
|
2017-11-07 04:22:43 +08:00
|
|
|
BigBlueButton::Events.get_start_and_stop_rec_events(doc, true))
|
2017-11-04 04:12:05 +08:00
|
|
|
has_recording_marks = false
|
|
|
|
# Scan for a set of recording start/stop events which fits any of these cases:
|
|
|
|
# - Recording started during segment
|
|
|
|
# - Recording stopped during segment
|
|
|
|
# - Recording started before segment and stopped after segment
|
|
|
|
rec_events.each do |rec_event|
|
2017-11-07 04:22:43 +08:00
|
|
|
if (rec_event[:start_timestamp] > start_timestamp and
|
|
|
|
rec_event[:start_timestamp] < end_timestamp) or
|
|
|
|
(rec_event[:stop_timestamp] > start_timestamp and
|
|
|
|
rec_event[:stop_timestamp] < end_timestamp) or
|
|
|
|
(rec_event[:start_timestamp] <= start_timestamp and
|
|
|
|
rec_event[:stop_timestamp] >= end_timestamp)
|
2017-11-04 04:12:05 +08:00
|
|
|
has_recording_marks = true
|
|
|
|
end
|
2013-10-03 01:18:26 +08:00
|
|
|
end
|
2017-11-04 04:12:05 +08:00
|
|
|
BigBlueButton.logger.info("Recording marks found: #{has_recording_marks}")
|
2013-10-03 01:18:26 +08:00
|
|
|
has_recording_marks
|
|
|
|
end
|
|
|
|
|
2011-06-04 00:17:51 +08:00
|
|
|
|
|
|
|
################## START ################################
|
|
|
|
|
2021-11-24 10:59:59 +08:00
|
|
|
opts = Optimist::options do
|
2017-10-31 03:04:30 +08:00
|
|
|
opt :meeting_id, "Meeting id to archive", type: :string
|
2017-11-04 04:12:05 +08:00
|
|
|
opt :break_timestamp, "Chapter break end timestamp", type: :integer
|
2011-12-07 04:22:35 +08:00
|
|
|
end
|
2021-11-24 10:59:59 +08:00
|
|
|
Optimist::die :meeting_id, "must be provided" if opts[:meeting_id].nil?
|
2011-12-07 04:22:35 +08:00
|
|
|
|
|
|
|
meeting_id = opts[:meeting_id]
|
2017-10-31 03:04:30 +08:00
|
|
|
break_timestamp = opts[:break_timestamp]
|
2011-12-07 04:22:35 +08:00
|
|
|
|
2017-07-10 23:42:40 +08:00
|
|
|
props = BigBlueButton.read_props
|
2011-06-04 00:17:51 +08:00
|
|
|
audio_dir = props['raw_audio_src']
|
|
|
|
recording_dir = props['recording_dir']
|
|
|
|
raw_archive_dir = "#{recording_dir}/raw"
|
|
|
|
deskshare_dir = props['raw_deskshare_src']
|
|
|
|
redis_host = props['redis_host']
|
|
|
|
redis_port = props['redis_port']
|
2018-12-15 05:37:21 +08:00
|
|
|
redis_password = props['redis_password']
|
2011-06-04 00:17:51 +08:00
|
|
|
presentation_dir = props['raw_presentation_src']
|
2018-04-25 02:51:37 +08:00
|
|
|
kurento_video_dir = props['kurento_video_src']
|
2018-04-25 23:35:36 +08:00
|
|
|
kurento_screenshare_dir = props['kurento_screenshare_src']
|
2021-10-05 01:33:13 +08:00
|
|
|
mediasoup_video_dir = props['mediasoup_video_src']
|
|
|
|
mediasoup_screenshare_dir = props['mediasoup_screenshare_src']
|
2023-04-19 04:02:26 +08:00
|
|
|
webrtc_recorder_video_dir = props['webrtc_recorder_video_src']
|
|
|
|
webrtc_recorder_screenshare_dir = props['webrtc_recorder_screenshare_src']
|
2014-04-04 04:23:49 +08:00
|
|
|
log_dir = props['log_dir']
|
2019-03-12 10:56:29 +08:00
|
|
|
notes_endpoint = props['notes_endpoint']
|
|
|
|
notes_formats = props['notes_formats']
|
2011-06-04 00:17:51 +08:00
|
|
|
|
2017-11-07 04:22:43 +08:00
|
|
|
# Determine the filenames for the done and fail files
|
|
|
|
if !break_timestamp.nil?
|
|
|
|
done_base = "#{meeting_id}-#{break_timestamp}"
|
|
|
|
else
|
|
|
|
done_base = meeting_id
|
|
|
|
end
|
|
|
|
archive_done_file = "#{recording_dir}/status/archived/#{done_base}.done"
|
|
|
|
archive_norecord_file = "#{recording_dir}/status/archived/#{done_base}.norecord"
|
2011-06-04 00:17:51 +08:00
|
|
|
|
2014-04-04 04:23:49 +08:00
|
|
|
BigBlueButton.logger = Logger.new("#{log_dir}/archive-#{meeting_id}.log", 'daily' )
|
2011-06-04 00:17:51 +08:00
|
|
|
|
2011-12-07 04:22:35 +08:00
|
|
|
target_dir = "#{raw_archive_dir}/#{meeting_id}"
|
2017-11-07 04:22:43 +08:00
|
|
|
FileUtils.mkdir_p target_dir
|
2018-12-15 06:16:12 +08:00
|
|
|
archive_events(meeting_id, redis_host, redis_port, redis_password, raw_archive_dir, break_timestamp)
|
2020-03-28 03:02:09 +08:00
|
|
|
# FreeSWITCH Audio files
|
2017-11-07 04:22:43 +08:00
|
|
|
archive_audio(meeting_id, audio_dir, raw_archive_dir)
|
2020-03-28 03:02:09 +08:00
|
|
|
# Etherpad notes
|
2021-03-24 04:35:08 +08:00
|
|
|
archive_notes(meeting_id, notes_endpoint, notes_formats, raw_archive_dir)
|
2020-03-28 03:02:09 +08:00
|
|
|
# Presentation files
|
|
|
|
archive_directory("#{presentation_dir}/#{meeting_id}/#{meeting_id}", "#{target_dir}/presentation")
|
|
|
|
# Kurento media
|
|
|
|
archive_directory("#{kurento_screenshare_dir}/#{meeting_id}", "#{target_dir}/deskshare")
|
|
|
|
archive_directory("#{kurento_video_dir}/#{meeting_id}", "#{target_dir}/video/#{meeting_id}")
|
2021-10-05 01:33:13 +08:00
|
|
|
# mediasoup media
|
|
|
|
archive_directory("#{mediasoup_screenshare_dir}/#{meeting_id}", "#{target_dir}/deskshare")
|
|
|
|
archive_directory("#{mediasoup_video_dir}/#{meeting_id}", "#{target_dir}/video/#{meeting_id}")
|
2023-04-19 04:02:26 +08:00
|
|
|
# bbb-webrtc-recorder media
|
|
|
|
archive_directory("#{webrtc_recorder_screenshare_dir}/#{meeting_id}", "#{target_dir}/deskshare")
|
|
|
|
archive_directory("#{webrtc_recorder_video_dir}/#{meeting_id}", "#{target_dir}/video/#{meeting_id}")
|
2020-03-28 03:02:09 +08:00
|
|
|
|
|
|
|
# If this was the last (or only) segment in a recording, delete the original media files
|
|
|
|
if break_timestamp.nil?
|
|
|
|
BigBlueButton.logger.info('Deleting originals of archived media files.')
|
|
|
|
# FreeSWITCH Audio files
|
|
|
|
delete_audio(meeting_id, audio_dir)
|
|
|
|
# Kurento media
|
|
|
|
FileUtils.rm_rf("#{kurento_screenshare_dir}/#{meeting_id}")
|
|
|
|
FileUtils.rm_rf("#{kurento_video_dir}/#{meeting_id}")
|
2021-10-05 01:33:13 +08:00
|
|
|
# mediasoup media
|
|
|
|
FileUtils.rm_rf("#{mediasoup_screenshare_dir}/#{meeting_id}")
|
|
|
|
FileUtils.rm_rf("#{mediasoup_video_dir}/#{meeting_id}")
|
2023-04-19 04:02:26 +08:00
|
|
|
# bbb-webrtc-recorder media
|
|
|
|
FileUtils.rm_rf("#{webrtc_recorder_screenshare_dir}/#{meeting_id}")
|
|
|
|
FileUtils.rm_rf("#{webrtc_recorder_video_dir}/#{meeting_id}")
|
2020-03-28 03:02:09 +08:00
|
|
|
end
|
2017-11-07 04:22:43 +08:00
|
|
|
|
|
|
|
if not archive_has_recording_marks?(meeting_id, raw_archive_dir, break_timestamp)
|
|
|
|
BigBlueButton.logger.info("There's no recording marks for #{meeting_id}, not processing recording.")
|
|
|
|
|
|
|
|
if break_timestamp.nil?
|
|
|
|
# we need to delete the keys here because the sanity phase might not
|
2015-03-11 23:12:03 +08:00
|
|
|
# automatically happen for this recording
|
|
|
|
BigBlueButton.logger.info("Deleting redis keys")
|
2018-12-15 05:37:21 +08:00
|
|
|
redis = BigBlueButton::RedisWrapper.new(redis_host, redis_port, redis_password)
|
2017-11-07 04:22:43 +08:00
|
|
|
events_archiver = BigBlueButton::RedisEventsArchiver.new(redis)
|
2014-11-26 22:06:15 +08:00
|
|
|
events_archiver.delete_events(meeting_id)
|
2017-11-07 04:22:43 +08:00
|
|
|
end
|
2014-11-26 22:06:15 +08:00
|
|
|
|
2017-11-07 04:22:43 +08:00
|
|
|
File.open(archive_norecord_file, "w") do |archive_norecord|
|
|
|
|
archive_norecord.write("Archived #{meeting_id} (no recording marks")
|
|
|
|
end
|
2015-03-11 23:12:03 +08:00
|
|
|
|
2017-11-07 04:22:43 +08:00
|
|
|
else
|
|
|
|
File.open(archive_done_file, "w") do |archive_done|
|
|
|
|
archive_done.write("Archived #{meeting_id}")
|
2013-10-03 01:18:26 +08:00
|
|
|
end
|
2011-05-12 01:52:39 +08:00
|
|
|
end
|