upload recordings to youtube

This commit is contained in:
Josh
2017-05-23 14:43:53 -04:00
parent 24c8952e59
commit 7d96eadbbf
15 changed files with 213 additions and 4 deletions

View File

@ -37,6 +37,18 @@ class @Recordings
COLUMN[c] = i++
constructor: ->
recordingsObject = this
canUpload = {}
# Determine which recordings can be uploaded to Youtube.
$.ajax({
method: 'GET',
async: false,
url: recordingsObject.getRecordingsURL() + '/can_upload'
}).success((res_data) ->
canUpload = res_data
)
# configure the datatable for recordings
this.table = $('#recordings').dataTable({
data: [],
@ -131,6 +143,14 @@ class @Recordings
trigger = recordingActions.find('.recording-update-trigger')
trigger.removeClass(classes.join(' '))
trigger.addClass(cls)
upload_btn = recordingActions.find('.cloud-upload')
if canUpload[row.id]
upload_btn.attr('data-popover-body', '.mail_youtube_popover')
else
upload_btn.attr('data-popover-body', '.mail_popover')
return recordingActions.html()
return data
}
@ -151,6 +171,18 @@ class @Recordings
options.title = I18n.play_recording
$('#recordings').tooltip(options)
options.selector = '.youtube-tooltip'
options.title = I18n.upload_youtube
$('#recordings').tooltip(options)
options.selector = '.upload-tooltip'
options.title = I18n.share
$('#recordings').tooltip(options)
options.selector = '.mail-tooltip'
options.title = I18n.mail_recording
$('#recordings').tooltip(options)
$(document).one "turbolinks:before-cache", =>
@getTable().api().clear().draw().destroy()
@ -273,12 +305,52 @@ class @Recordings
showAlert(I18n.recording_deleted, 4000);
)
@getTable().on 'click', '.upload-button', (event) ->
btn = $(this)
row = table_api.row($(this).closest('tr')).data()
url = recordingsObject.getRecordingsURL()
id = row.id
title = btn.closest('form').find('#video-title').val()
privacy_status = btn.closest('form').find('input[name=privacy_status]:checked').val()
if title == ''
title = row.name
$.ajax({
method: 'POST',
url: url+'/'+id
data: {video_title: title, privacy_status: privacy_status}
})
@getTable().on 'click', '.mail-recording', (event) ->
btn = $(this)
row = table_api.row($(this).closest('tr')).data()
url = recordingsObject.getRecordingsURL()
id = row.id
# Take the username from the header.
username = $('#title-header').text().replace('Welcome ', '').trim()
recording_url = row.playbacks[0].url
webcams_url = getHostName(recording_url) + '/presentation/' + id + '/video/webcams.webm'
subject = username + I18n.recording_mail_subject
body = I18n.recording_mail_body + "\n\n" + recording_url
mailto = "mailto:?subject=" + encodeURIComponent(subject) + "&body=" + encodeURIComponent(body);
window.open(mailto);
@getTable().on 'draw.dt', (event) ->
$('time[data-time-ago]').timeago();
getTable: ->
@table
getHostName = (url) ->
parser = document.createElement('a');
parser.href = url;
parser.origin;
getRecordingsURL: ->
if $(".page-wrapper.rooms").data('main-room')
base_url = Meeting.buildRootURL()+'/'+$('body').data('resource')+'/'+Meeting.getInstance().getAdminId()

View File

@ -89,3 +89,15 @@
color: green;
}
}
.youtube-red {
color: red;
}
.cloud-blue {
color: cornflowerblue;
}
.top-buffer {
margin-top: 8px;
}

View File

@ -170,6 +170,41 @@ class BbbController < ApplicationController
render_bbb_response bbb_res
end
# POST /rooms/:room_id/recordings/:record_id
# POST /rooms/:room_id/:id/recordings/:record_id
def youtube_publish
# If we can't get the client, then they don't have a Youtube account.
begin
client = Yt::Account.new(access_token: current_user.token)
video = client.upload_video(get_webcams_url(params[:record_id]),
title: params[:video_title],
description: t('youtube_description'),
privacy_status: params[:privacy_status])
rescue
# In this case, they don't have a youtube channel connected to their account, so prompt to create one.
redirect_to 'https://m.youtube.com/create_channel'
end
end
# GET /rooms/:room_id/recordings/can_upload
def can_upload
upload_data = {}
bbb_get_recordings[:recordings].each{ |recording_data|
next if recording_data[:recordID] == ""
# The recording is uploadable if it contains webcam data and they are logged in thorugh Google.
uploadable = Faraday.head(get_webcams_url(recording_data[:recordID])).status == 200 &&
Rails.application.config.omniauth_google &&
current_user.provider == 'google'
upload_data[recording_data[:recordID]] = uploadable
}
render json: upload_data
end
def get_webcams_url(recording_id)
uri = URI.parse(ENV['BIGBLUEBUTTON_ENDPOINT'])
uri.scheme + '://' + uri.host + '/presentation/' + recording_id + '/video/webcams.webm'
end
private
def load_room!

View File

@ -141,6 +141,7 @@ module BbbApi
end
res[:recordings].each do |recording|
next if recording.key?(:error)
pref_preview = {}
recording[:length] = recording[:playback][:format].is_a?(Hash) ? recording[:playback][:format][:length] : recording[:playback][:format].first[:length]
# create a playbacks attribute on recording for playback formats

View File

@ -26,6 +26,7 @@ class User < ApplicationRecord
user.username = self.send("#{auth_hash['provider']}_username", auth_hash) rescue nil
user.email = self.send("#{auth_hash['provider']}_email", auth_hash) rescue nil
user.name = auth_hash['info']['name']
user.token = auth_hash['credentials']['token']
user.save!
user
end

View File

@ -15,7 +15,7 @@
<% content_for :title do %>
<div class="title">
<h2>
<h2 id = 'title-header'>
<% if admin? && !@meeting_running %>
<%= t('admin_room_title', user: @user.name) %>
<% else %>

View File

@ -55,6 +55,40 @@
<%= t('no') %>
</button>
</div>
<div class="youtube-popover">
<form class = "form-inline">
<div class = "row">
<div class="col-xs-5">
<input type="title" class="form-control" id="video-title" placeholder="<%= t('video_title') %>">
</div>
<div class="col-xs-4 col-xs-offset-2">
<button type="button" class="btn btn-success upload-button centered" data-dismiss="popover">
<%= t('upload') %>
</button>
</div>
</div>
<div class = "row top-buffer text-center">
<form class="privacy_form">
<label class="radio-inline"><input type="radio" name="privacy_status" value="public" checked><%= t('youtube_privacy_options.public') %> </label>
<label class="radio-inline"><input type="radio" name="privacy_status" value="unlisted"><%= t('youtube_privacy_options.unlisted') %></label>
</form>
</div>
</form>
</div>
<div class='mail_youtube_popover'>
<button type="button" class="btn btn-default mail-recording mail-tooltip">
<%= icon('envelope-o') %>
</button>
<button type="button" class="btn btn-default has-popover youtube-upload youtube-tooltip"
data-placement="top" data-popover-body=".youtube-popover">
<div class = 'youtube-red'> <%= icon('youtube-play') %> </div>
</button>
</div>
<div class='mail_popover'>
<button type="button" class="btn btn-default mail-recording mail-tooltip">
<%= icon('envelope-o') %>
</button>
</div>
<div class="recording-visibility-popover">
<button type="button" class="btn btn-default btn-success recording-update" data-visibility="published">
<%= t('client.published') %>
@ -72,6 +106,10 @@
data-popover-title="<%= t('change_recording_visibility') %>">
<%= icon('eye') %>
</button>
<button type="button" class="btn btn-default has-popover cloud-upload upload-tooltip"
data-placement="top">
<div class = 'cloud-blue'> <%= icon('cloud-upload') %> </div>
</button>
<a tabindex="0" role="button" class="btn btn-default has-popover delete-tooltip"
data-placement="top" data-popover-body=".delete-popover-body"
data-popover-title="<%= t('are_you_sure') %>">