Commit 5b36d10c authored by Stan Hu's avatar Stan Hu

Add GOOGLE_DRIVE_ID support

parent 6f96980e
......@@ -6,4 +6,5 @@ gem 'mediainfo', '= 1.3.3'
group :development, :test do
gem 'rubocop', '~> 0.87'
gem 'byebug'
end
......@@ -4,6 +4,7 @@ GEM
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.1)
byebug (11.1.3)
declarative (0.0.10)
declarative-option (0.1.0)
faraday (0.15.4)
......@@ -81,6 +82,7 @@ PLATFORMS
ruby
DEPENDENCIES
byebug
google_drive (= 3.0.3)
httparty (= 0.17.0)
mediainfo (= 1.3.3)
......
......@@ -25,6 +25,7 @@ variables do not exist, Zoom will attempt to load them from config files.
|ZOOM_API_KEY|Zoom API client key|
|ZOOM_API_SECRET|Zoom API secret key|
|GOOGLE_DRIVE_SERVICE_ACCOUNT_KEY|Google Drive credentials|
|GOOGLE_DRIVE_ID|Google Drive ID for destination folder (e.g. `0A1PeuBAntm4LNk9PVB`)|
If `ZOOM_API_KEY` and `ZOOM_API_SECRET` are not available, the script
will attempt to load `zoom_sync.yml`:
......
......@@ -106,16 +106,24 @@ end
# Client to access Google Drive
class GoogleDriveClient
GOOGLE_BASE_FOLDER = 'GitLab Videos Recorded'.freeze
attr_reader :session, :gdrive_id
attr_reader :session
def initialize(config)
def initialize(config, gdrive_id)
@session = GoogleDrive::Session.from_service_account_key(config)
@gdrive_id = gdrive_id
end
def base_collection
@base_collection ||= session.collection_by_id(gdrive_id)
end
# If you want to store videos in a folder, change this
def base_folder
[]
end
def valid_file?(folders, filename, file_size)
dest_folder = session.file_by_title([GOOGLE_BASE_FOLDER] + folders)
dest_folder = base_collection.file_by_title(folders)
return unless dest_folder
......@@ -134,13 +142,13 @@ class GoogleDriveClient
end
def mkdir(sub_directories)
current_path = [GOOGLE_BASE_FOLDER]
current_path = base_folder
dest_folder = nil
sub_directories.each do |dir|
current_folder = session.file_by_title(current_path)
current_folder = base_collection.file_by_title(current_path)
current_path += [dir]
dest_folder = session.file_by_title(current_path)
dest_folder = base_collection.file_by_title(current_path)
unless dest_folder
puts "Creating destination folder #{current_path}"
......@@ -187,7 +195,7 @@ class ZoomSyncher
def initialize
@client = ZoomClient.new(load_zoom_config)
@gdrive_client = GoogleDriveClient.new(load_gdrive_config)
@gdrive_client = GoogleDriveClient.new(load_gdrive_config, load_gdrive_id)
end
def sync
......@@ -294,6 +302,12 @@ class ZoomSyncher
StringIO.new(data)
end
def load_gdrive_id
ENV['GOOGLE_DRIVE_ID'].tap do |gdrive_id|
raise 'GOOGLE_DRIVE_ID not set' unless gdrive_id
end
end
# Discard any audio or videos that aren't longer than 30 seconds
def should_upload?(filename, file_type)
return true if file_type.downcase == 'chat'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment