bigbluebutton-Github/record-and-playback/core/scripts/utils/captions.rb

104 lines
3.4 KiB
Ruby
Raw Normal View History

# Set encoding to utf-8
# encoding: UTF-8
#
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
#
# Copyright (c) 2019 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/>.
#
# For DEVELOPMENT
# Allows us to run the script manually
# require File.expand_path('../../../../core/lib/recordandplayback', __FILE__)
# For PRODUCTION
require File.expand_path('../../../lib/recordandplayback', __FILE__)
require 'rubygems'
require 'optimist'
require 'yaml'
require 'json'
opts = Optimist::options do
opt :meeting_id, "Meeting id to archive", :type => String
end
meeting_id = opts[:meeting_id]
# This script lives in scripts/archive/steps while properties.yaml lives in scripts/
props = YAML::load(File.open('../../core/scripts/bigbluebutton.yml'))
recording_dir = props['recording_dir']
raw_archive_dir = "#{recording_dir}/raw/#{meeting_id}"
BigBlueButton.logger.info("Setting process dir")
BigBlueButton.logger.info("setting captions dir")
captions_dir = props['captions_dir']
log_dir = props['log_dir']
target_dir = "#{recording_dir}/process/presentation/#{meeting_id}"
2019-05-01 23:01:15 +08:00
# Generate captions.json for API
2019-05-14 04:38:51 +08:00
def create_api_captions_file(captions_meeting_dir)
2019-05-01 23:01:15 +08:00
BigBlueButton.logger.info("Generating closed captions for API")
2019-05-14 04:38:51 +08:00
2019-05-10 22:51:05 +08:00
captions = JSON.load(File.new("#{captions_meeting_dir}/captions_playback.json"))
2019-05-01 23:01:15 +08:00
captions_json = []
captions.each do |track|
caption = {}
caption[:kind] = :captions
caption[:label] = track['localeName']
caption[:lang] = track['locale']
caption[:source] = :live
captions_json << caption
end
2019-05-10 22:51:05 +08:00
File.open("#{captions_meeting_dir}/captions.json", "w") do |f|
2019-05-01 23:01:15 +08:00
f.write(captions_json.to_json)
end
end
if not FileTest.directory?(target_dir)
2019-05-14 04:38:51 +08:00
captions_meeting_dir = "#{captions_dir}/#{meeting_id}"
FileUtils.mkdir_p "#{log_dir}/presentation"
logger = Logger.new("#{log_dir}/presentation/process-#{meeting_id}.log", 'daily')
BigBlueButton.logger = logger
BigBlueButton.logger.info("Processing script captions.rb")
FileUtils.mkdir_p target_dir
begin
BigBlueButton.logger.info("Generating closed captions")
2019-05-10 22:51:05 +08:00
FileUtils.mkdir_p captions_meeting_dir
ret = BigBlueButton.exec_ret('utils/gen_webvtt', '-i', raw_archive_dir, '-o', captions_meeting_dir)
if ret != 0
raise "Generating closed caption files failed"
end
2019-05-10 23:56:29 +08:00
FileUtils.cp("#{captions_meeting_dir}/captions.json", "#{captions_meeting_dir}/captions_playback.json")
2019-05-14 04:38:51 +08:00
create_api_captions_file(captions_meeting_dir)
2019-05-10 23:56:29 +08:00
FileUtils.rm "#{captions_meeting_dir}/captions_playback.json"
rescue Exception => e
BigBlueButton.logger.error(e.message)
e.backtrace.each do |traceline|
BigBlueButton.logger.error(traceline)
end
exit 1
end
end