2021-11-16 07:11:20 +08:00
|
|
|
# frozen_string_literal: true
|
2012-07-18 03:39:44 +08:00
|
|
|
# Set encoding to utf-8
|
|
|
|
# encoding: UTF-8
|
|
|
|
|
|
|
|
#
|
|
|
|
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
|
|
|
|
#
|
|
|
|
# Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below).
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2014-04-04 04:23:49 +08:00
|
|
|
# For DEVELOPMENT
|
|
|
|
# Allows us to run the script manually
|
|
|
|
# require File.expand_path('../../../../core/lib/recordandplayback', __FILE__)
|
|
|
|
|
|
|
|
# For PRODUCTION
|
2013-08-26 23:20:33 +08:00
|
|
|
require File.expand_path('../../../lib/recordandplayback', __FILE__)
|
2014-04-04 04:23:49 +08:00
|
|
|
|
2012-07-18 03:39:44 +08:00
|
|
|
require 'rubygems'
|
2021-11-24 10:59:59 +08:00
|
|
|
require 'optimist'
|
2012-07-18 03:39:44 +08:00
|
|
|
require 'yaml'
|
2016-11-29 22:00:19 +08:00
|
|
|
require 'json'
|
2012-07-18 03:39:44 +08:00
|
|
|
|
2021-12-10 04:37:05 +08:00
|
|
|
opts = Optimist.options do
|
2021-11-16 07:11:20 +08:00
|
|
|
opt :meeting_id, 'Meeting id to archive', default: '58f4a6b3-cd07-444d-8564-59116cb53974', type: String
|
2012-07-18 03:39:44 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
meeting_id = opts[:meeting_id]
|
|
|
|
|
|
|
|
# This script lives in scripts/archive/steps while properties.yaml lives in scripts/
|
2017-07-11 05:18:39 +08:00
|
|
|
props = BigBlueButton.read_props
|
2021-11-16 07:11:20 +08:00
|
|
|
presentation_props = YAML.safe_load(File.open('presentation.yml'))
|
2022-04-01 03:37:46 +08:00
|
|
|
filepathPresOverride = "/etc/bigbluebutton/recording/presentation.yml"
|
2022-03-21 21:47:01 +08:00
|
|
|
hasOverride = File.file?(filepathPresOverride)
|
|
|
|
if (hasOverride)
|
2022-03-18 23:16:27 +08:00
|
|
|
presOverrideProps = YAML::load(File.open(filepathPresOverride))
|
|
|
|
presentation_props = presentation_props.merge(presOverrideProps)
|
|
|
|
end
|
|
|
|
|
2013-06-14 04:10:52 +08:00
|
|
|
presentation_props['audio_offset'] = 0 if presentation_props['audio_offset'].nil?
|
2013-06-15 04:50:39 +08:00
|
|
|
presentation_props['include_deskshare'] = false if presentation_props['include_deskshare'].nil?
|
2012-07-18 03:39:44 +08:00
|
|
|
|
|
|
|
recording_dir = props['recording_dir']
|
|
|
|
raw_archive_dir = "#{recording_dir}/raw/#{meeting_id}"
|
2014-04-04 04:23:49 +08:00
|
|
|
log_dir = props['log_dir']
|
2012-07-18 03:39:44 +08:00
|
|
|
|
|
|
|
target_dir = "#{recording_dir}/process/presentation/#{meeting_id}"
|
2021-11-16 07:11:20 +08:00
|
|
|
unless FileTest.directory?(target_dir)
|
2014-04-04 04:23:49 +08:00
|
|
|
FileUtils.mkdir_p "#{log_dir}/presentation"
|
2021-11-16 07:11:20 +08:00
|
|
|
logger = Logger.new("#{log_dir}/presentation/process-#{meeting_id}.log", 'daily')
|
2013-04-03 07:53:08 +08:00
|
|
|
BigBlueButton.logger = logger
|
2021-11-16 07:11:20 +08:00
|
|
|
BigBlueButton.logger.info('Processing script presentation.rb')
|
2013-04-03 07:53:08 +08:00
|
|
|
FileUtils.mkdir_p target_dir
|
2016-01-20 03:52:28 +08:00
|
|
|
|
2016-01-27 03:25:02 +08:00
|
|
|
begin
|
2016-02-13 01:08:33 +08:00
|
|
|
# Create initial metadata.xml
|
2021-11-16 07:11:20 +08:00
|
|
|
b = Builder::XmlMarkup.new(indent: 2)
|
|
|
|
metaxml = b.recording do
|
2016-02-13 01:08:33 +08:00
|
|
|
b.id(meeting_id)
|
2021-11-16 07:11:20 +08:00
|
|
|
b.state('processing')
|
2016-02-13 01:08:33 +08:00
|
|
|
b.published(false)
|
|
|
|
b.start_time
|
|
|
|
b.end_time
|
2017-02-11 02:19:32 +08:00
|
|
|
b.participants
|
2016-02-13 01:08:33 +08:00
|
|
|
b.playback
|
|
|
|
b.meta
|
2021-11-16 07:11:20 +08:00
|
|
|
end
|
|
|
|
metadata_xml = File.new("#{target_dir}/metadata.xml", 'w')
|
2016-02-13 01:08:33 +08:00
|
|
|
metadata_xml.write(metaxml)
|
|
|
|
metadata_xml.close
|
2021-11-16 07:11:20 +08:00
|
|
|
BigBlueButton.logger.info('Created inital metadata.xml')
|
2016-02-13 01:08:33 +08:00
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
BigBlueButton::AudioProcessor.process(raw_archive_dir, "#{target_dir}/audio")
|
|
|
|
events_xml = "#{raw_archive_dir}/events.xml"
|
|
|
|
|
|
|
|
# TODO: Don't copy events.xml to target directory
|
2016-01-27 03:25:02 +08:00
|
|
|
FileUtils.cp(events_xml, target_dir)
|
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
presentation_dir = "#{raw_archive_dir}/presentation"
|
2016-01-27 03:25:02 +08:00
|
|
|
presentations = BigBlueButton::Presentation.get_presentations(events_xml)
|
|
|
|
|
|
|
|
processed_pres_dir = "#{target_dir}/presentation"
|
|
|
|
FileUtils.mkdir_p processed_pres_dir
|
|
|
|
|
2016-01-27 06:16:28 +08:00
|
|
|
# Get the real-time start and end timestamp
|
2021-11-17 23:05:20 +08:00
|
|
|
@doc = Nokogiri::XML(File.read("#{target_dir}/events.xml"))
|
2016-01-27 06:16:28 +08:00
|
|
|
|
2021-11-17 23:05:20 +08:00
|
|
|
meeting_start = BigBlueButton::Events.first_event_timestamp(@doc)
|
|
|
|
meeting_end = BigBlueButton::Events.last_event_timestamp(@doc)
|
2016-01-27 06:16:28 +08:00
|
|
|
match = /.*-(\d+)$/.match(meeting_id)
|
2021-11-16 07:11:20 +08:00
|
|
|
real_start_time = match[1].to_i
|
|
|
|
real_end_time = real_start_time + (meeting_end - meeting_start)
|
2016-01-27 06:16:28 +08:00
|
|
|
|
2016-02-13 01:08:33 +08:00
|
|
|
# Add start_time, end_time and meta to metadata.xml
|
|
|
|
## Load metadata.xml
|
2020-06-17 18:13:07 +08:00
|
|
|
metadata = Nokogiri::XML(File.read("#{target_dir}/metadata.xml"))
|
2016-02-13 01:08:33 +08:00
|
|
|
## Add start_time and end_time
|
|
|
|
recording = metadata.root
|
|
|
|
### Date Format for recordings: Thu Mar 04 14:05:56 UTC 2010
|
2021-11-16 07:11:20 +08:00
|
|
|
start_time = recording.at_xpath('start_time')
|
2016-02-13 01:08:33 +08:00
|
|
|
start_time.content = real_start_time
|
2021-11-16 07:11:20 +08:00
|
|
|
end_time = recording.at_xpath('end_time')
|
2016-02-13 01:08:33 +08:00
|
|
|
end_time.content = real_end_time
|
2017-02-11 02:19:32 +08:00
|
|
|
|
2017-03-11 03:39:20 +08:00
|
|
|
## Copy the breakout and breakout rooms node from
|
|
|
|
## events.xml if present.
|
2021-11-16 07:11:20 +08:00
|
|
|
breakout_xpath = @doc.xpath('recording/breakout')
|
|
|
|
breakout_rooms_xpath = @doc.xpath('recording/breakoutRooms')
|
|
|
|
meeting_xpath = @doc.xpath('recording/meeting')
|
2017-03-10 07:01:15 +08:00
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
recording << meeting_xpath unless meeting_xpath.nil?
|
2017-03-16 00:45:58 +08:00
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
recording << breakout_xpath unless breakout_xpath.nil?
|
2017-03-10 07:01:15 +08:00
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
recording << breakout_rooms_xpath unless breakout_rooms_xpath.nil?
|
2017-03-10 07:01:15 +08:00
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
participants = recording.at_xpath('participants')
|
2017-11-08 23:12:25 +08:00
|
|
|
participants.content = BigBlueButton::Events.get_num_participants(@doc)
|
2017-02-11 02:19:32 +08:00
|
|
|
|
2016-02-13 01:08:33 +08:00
|
|
|
## Remove empty meta
|
2021-11-16 07:11:20 +08:00
|
|
|
## TODO: Clarify reasoning behind creating an empty node to then remove it
|
|
|
|
metadata.search('recording/meta').each(&:remove)
|
2016-02-13 01:08:33 +08:00
|
|
|
## Add the actual meta
|
2021-11-16 07:11:20 +08:00
|
|
|
Nokogiri::XML::Builder.with(metadata.at('recording')) do |xml|
|
|
|
|
xml.meta do
|
|
|
|
BigBlueButton::Events.get_meeting_metadata("#{target_dir}/events.xml").each { |k, v| xml.method_missing(k, v) }
|
|
|
|
end
|
2016-02-13 01:08:33 +08:00
|
|
|
end
|
|
|
|
## Write the new metadata.xml
|
2021-11-16 07:11:20 +08:00
|
|
|
metadata_file = File.new("#{target_dir}/metadata.xml", 'w')
|
|
|
|
metadata = Nokogiri::XML(metadata.to_xml, &:noblanks)
|
2016-02-13 01:08:33 +08:00
|
|
|
metadata_file.write(metadata.root)
|
|
|
|
metadata_file.close
|
2021-11-16 07:11:20 +08:00
|
|
|
BigBlueButton.logger.info('Created an updated metadata.xml with start_time and end_time')
|
2016-01-27 06:16:28 +08:00
|
|
|
|
|
|
|
# Start processing raw files
|
2016-11-29 22:00:19 +08:00
|
|
|
presentation_text = {}
|
2016-01-27 03:25:02 +08:00
|
|
|
presentations.each do |pres|
|
|
|
|
pres_dir = "#{presentation_dir}/#{pres}"
|
|
|
|
num_pages = BigBlueButton::Presentation.get_number_of_pages_for(pres_dir)
|
|
|
|
|
|
|
|
target_pres_dir = "#{processed_pres_dir}/#{pres}"
|
|
|
|
FileUtils.mkdir_p target_pres_dir
|
|
|
|
FileUtils.mkdir_p "#{target_pres_dir}/textfiles"
|
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
images = Dir.glob("#{pres_dir}/#{pres}.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}")
|
2016-01-27 03:25:02 +08:00
|
|
|
if images.empty?
|
|
|
|
pres_name = "#{pres_dir}/#{pres}"
|
2021-11-16 07:11:20 +08:00
|
|
|
if File.exist?("#{pres_name}.pdf")
|
2016-01-27 03:25:02 +08:00
|
|
|
pres_pdf = "#{pres_name}.pdf"
|
|
|
|
BigBlueButton.logger.info("Found pdf file for presentation #{pres_pdf}")
|
2021-11-16 07:11:20 +08:00
|
|
|
elsif File.exist?("#{pres_name}.PDF")
|
2016-01-27 03:25:02 +08:00
|
|
|
pres_pdf = "#{pres_name}.PDF"
|
|
|
|
BigBlueButton.logger.info("Found PDF file for presentation #{pres_pdf}")
|
2021-11-16 07:11:20 +08:00
|
|
|
elsif File.exist?(pres_name.to_s)
|
2016-01-27 03:25:02 +08:00
|
|
|
pres_pdf = pres_name
|
|
|
|
BigBlueButton.logger.info("Falling back to old presentation filename #{pres_pdf}")
|
|
|
|
else
|
2021-11-16 07:11:20 +08:00
|
|
|
pres_pdf = ''
|
2016-01-27 03:25:02 +08:00
|
|
|
BigBlueButton.logger.warn("Could not find pdf file for presentation #{pres}")
|
|
|
|
end
|
2014-01-24 03:03:09 +08:00
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
unless pres_pdf.empty?
|
2016-11-29 22:00:19 +08:00
|
|
|
text = {}
|
2016-01-27 03:25:02 +08:00
|
|
|
1.upto(num_pages) do |page|
|
|
|
|
BigBlueButton::Presentation.extract_png_page_from_pdf(
|
2021-11-16 07:11:20 +08:00
|
|
|
page, pres_pdf, "#{target_pres_dir}/slide-#{page}.png", '1600x1600'
|
|
|
|
)
|
|
|
|
next unless File.exist?("#{pres_dir}/textfiles/slide-#{page}.txt")
|
|
|
|
t = File.read("#{pres_dir}/textfiles/slide-#{page}.txt", encoding: 'UTF-8')
|
|
|
|
text["slide-#{page}"] = t.encode('UTF-8', invalid: :replace)
|
|
|
|
FileUtils.cp("#{pres_dir}/textfiles/slide-#{page}.txt", "#{target_pres_dir}/textfiles")
|
2014-01-24 03:03:09 +08:00
|
|
|
end
|
2016-11-29 22:00:19 +08:00
|
|
|
presentation_text[pres] = text
|
2013-05-18 02:32:14 +08:00
|
|
|
end
|
2016-01-27 03:25:02 +08:00
|
|
|
else
|
2017-09-05 23:03:09 +08:00
|
|
|
BigBlueButton::Presentation.convert_image_to_png(
|
2021-11-16 07:11:20 +08:00
|
|
|
images[0], "#{target_pres_dir}/slide-1.png", '1600x1600'
|
|
|
|
)
|
2013-05-18 02:32:14 +08:00
|
|
|
end
|
2016-09-20 02:52:32 +08:00
|
|
|
|
|
|
|
# Copy thumbnails from raw files
|
2020-06-24 23:42:58 +08:00
|
|
|
FileUtils.cp_r("#{pres_dir}/thumbnails", "#{target_pres_dir}/thumbnails") if File.exist?("#{pres_dir}/thumbnails")
|
2012-07-18 03:39:44 +08:00
|
|
|
end
|
2016-01-20 03:52:28 +08:00
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
BigBlueButton.logger.info('Generating closed captions')
|
2016-08-05 01:23:15 +08:00
|
|
|
ret = BigBlueButton.exec_ret('utils/gen_webvtt', '-i', raw_archive_dir, '-o', target_dir)
|
2021-11-16 07:11:20 +08:00
|
|
|
raise 'Generating closed caption files failed' if ret != 0
|
|
|
|
captions = JSON.parse(File.read("#{target_dir}/captions.json"))
|
2016-08-05 01:23:15 +08:00
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
unless presentation_text.empty?
|
2016-11-29 22:00:19 +08:00
|
|
|
# Write presentation_text.json to file
|
2021-11-16 07:11:20 +08:00
|
|
|
File.open("#{target_dir}/presentation_text.json", 'w') { |f| f.puts presentation_text.to_json }
|
2016-11-29 22:00:19 +08:00
|
|
|
end
|
|
|
|
|
2017-08-19 03:24:54 +08:00
|
|
|
# We have to decide whether to actually generate the webcams video file
|
2016-08-05 01:23:15 +08:00
|
|
|
# We do so if any of the following conditions are true:
|
|
|
|
# - There is webcam video present, or
|
2017-03-21 22:50:12 +08:00
|
|
|
# - There's broadcast video present, or
|
2016-08-05 01:23:15 +08:00
|
|
|
# - There are closed captions present (they need a video stream to be rendered on top of)
|
2021-11-16 07:11:20 +08:00
|
|
|
if !Dir["#{raw_archive_dir}/video/*"].empty? ||
|
|
|
|
!Dir["#{raw_archive_dir}/video-broadcast/*"].empty? ||
|
|
|
|
!captions.empty?
|
2016-10-21 03:39:35 +08:00
|
|
|
webcam_width = presentation_props['video_output_width']
|
|
|
|
webcam_height = presentation_props['video_output_height']
|
2021-03-09 02:14:48 +08:00
|
|
|
webcam_framerate = presentation_props['video_output_framerate']
|
2017-03-21 22:50:12 +08:00
|
|
|
|
|
|
|
# Use a higher resolution video canvas if there's broadcast video streams
|
2021-11-16 07:11:20 +08:00
|
|
|
unless Dir["#{raw_archive_dir}/video-broadcast/*"].empty?
|
2017-03-21 22:50:12 +08:00
|
|
|
webcam_width = presentation_props['deskshare_output_width']
|
|
|
|
webcam_height = presentation_props['deskshare_output_height']
|
2021-03-09 02:14:48 +08:00
|
|
|
webcam_framerate = presentation_props['deskshare_output_framerate']
|
2016-05-18 23:14:04 +08:00
|
|
|
end
|
2012-08-02 04:40:58 +08:00
|
|
|
|
2021-03-09 02:14:48 +08:00
|
|
|
webcam_framerate = 15 if webcam_framerate.nil?
|
2021-11-16 07:11:20 +08:00
|
|
|
processed_audio_file = BigBlueButton::AudioProcessor.get_processed_audio_file(raw_archive_dir, "#{target_dir}/audio")
|
2022-04-30 03:43:24 +08:00
|
|
|
BigBlueButton.process_webcam_videos(target_dir, raw_archive_dir, webcam_width, webcam_height, webcam_framerate, presentation_props['audio_offset'], processed_audio_file, presentation_props['video_formats'], props['showModeratorViewpoint'])
|
2016-10-21 03:39:35 +08:00
|
|
|
end
|
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
if !Dir["#{raw_archive_dir}/deskshare/*"].empty? && presentation_props['include_deskshare']
|
2016-10-21 03:39:35 +08:00
|
|
|
deskshare_width = presentation_props['deskshare_output_width']
|
|
|
|
deskshare_height = presentation_props['deskshare_output_height']
|
2021-03-09 02:14:48 +08:00
|
|
|
deskshare_framerate = presentation_props['deskshare_output_framerate']
|
|
|
|
deskshare_framerate = 5 if deskshare_framerate.nil?
|
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
BigBlueButton.process_deskshare_videos(target_dir, raw_archive_dir, deskshare_width, deskshare_height, deskshare_framerate, presentation_props['video_formats'])
|
2016-02-02 01:23:39 +08:00
|
|
|
end
|
|
|
|
|
2020-12-02 03:04:26 +08:00
|
|
|
# Copy shared notes from raw files
|
2021-11-16 07:11:20 +08:00
|
|
|
FileUtils.cp_r("#{raw_archive_dir}/notes", target_dir) unless Dir["#{raw_archive_dir}/notes/*"].empty?
|
2020-12-02 03:04:26 +08:00
|
|
|
|
2021-11-16 07:11:20 +08:00
|
|
|
process_done = File.new("#{recording_dir}/status/processed/#{meeting_id}-presentation.done", 'w')
|
2016-01-27 03:25:02 +08:00
|
|
|
process_done.write("Processed #{meeting_id}")
|
|
|
|
process_done.close
|
|
|
|
|
2016-02-13 01:08:33 +08:00
|
|
|
# Update state in metadata.xml
|
2016-01-27 06:16:28 +08:00
|
|
|
## Load metadata.xml
|
2020-06-17 18:13:07 +08:00
|
|
|
metadata = Nokogiri::XML(File.read("#{target_dir}/metadata.xml"))
|
2016-01-27 06:16:28 +08:00
|
|
|
## Update status
|
|
|
|
recording = metadata.root
|
2021-11-16 07:11:20 +08:00
|
|
|
state = recording.at_xpath('state')
|
|
|
|
state.content = 'processed'
|
2016-01-27 06:16:28 +08:00
|
|
|
## Write the new metadata.xml
|
2021-11-16 07:11:20 +08:00
|
|
|
metadata_file = File.new("#{target_dir}/metadata.xml", 'w')
|
2016-02-13 01:08:33 +08:00
|
|
|
metadata_file.write(metadata.root)
|
|
|
|
metadata_file.close
|
2021-11-16 07:11:20 +08:00
|
|
|
BigBlueButton.logger.info('Created an updated metadata.xml with state=processed')
|
|
|
|
rescue StandardError => e
|
2016-01-27 03:25:02 +08:00
|
|
|
BigBlueButton.logger.error(e.message)
|
|
|
|
e.backtrace.each do |traceline|
|
|
|
|
BigBlueButton.logger.error(traceline)
|
|
|
|
end
|
|
|
|
exit 1
|
2016-01-20 03:52:28 +08:00
|
|
|
end
|
2021-11-17 23:05:20 +08:00
|
|
|
end
|