Commit b3afa6d8 authored by Stan Hu's avatar Stan Hu

Merge branch 'sh-add-google-drive-id-support' into 'master'

Add Google Shared Drive support

See merge request !15
parents 6f96980e f7c552a3
......@@ -16,8 +16,8 @@ stages:
extends: .ruby-cache
before_script:
- gem install bundler
- (if [ -d vendor ]; then echo "Vendor dir exists"; else apk add build-base; fi);
- bundle install --jobs 4 --path vendor/bundle
- apk add build-base
- bundle install --jobs 4 --path vendor/bundle --without development
cache:
paths:
- vendor
......
source 'https://rubygems.org'
gem 'google_drive', '= 3.0.3'
gem 'google_drive', '~> 3.0.5'
gem 'httparty', '= 0.17.0'
gem 'mediainfo', '= 1.3.3'
group :development, :test do
gem 'rubocop', '~> 0.87'
end
group :development do
gem 'byebug'
end
GEM
remote: https://rubygems.org/
specs:
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.1)
declarative (0.0.10)
byebug (11.1.3)
declarative (0.0.20)
declarative-option (0.1.0)
faraday (0.15.4)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
google-api-client (0.30.8)
google-api-client (0.42.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.5, < 0.10.0)
googleauth (~> 0.9)
httpclient (>= 2.8.1, < 3.0)
mini_mime (~> 1.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.0)
signet (~> 0.10)
google_drive (3.0.3)
google-api-client (>= 0.11.0, < 0.31.0)
signet (~> 0.12)
google_drive (3.0.5)
google-api-client (>= 0.11.0, < 1.0.0)
googleauth (>= 0.5.0, < 1.0.0)
nokogiri (>= 1.5.3, < 2.0.0)
googleauth (0.9.0)
faraday (~> 0.12)
googleauth (0.13.0)
faraday (>= 0.17.3, < 2.0)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (~> 0.7)
signet (~> 0.14)
httparty (0.17.0)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
httpclient (2.8.3)
jwt (2.2.1)
mediainfo (1.3.3)
memoist (0.16.0)
memoist (0.16.2)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
multi_json (1.13.1)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
nokogiri (1.10.4)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
os (1.0.1)
os (1.1.0)
parallel (1.19.2)
parser (2.7.1.4)
ast (~> 2.4.1)
public_suffix (3.1.1)
public_suffix (4.0.5)
rainbow (3.0.0)
regexp_parser (1.7.1)
representable (3.0.4)
......@@ -69,9 +70,9 @@ GEM
rubocop-ast (0.1.0)
parser (>= 2.7.0.1)
ruby-progressbar (1.10.1)
signet (0.11.0)
signet (0.14.0)
addressable (~> 2.3)
faraday (~> 0.9)
faraday (>= 0.17.3, < 2.0)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
uber (0.1.0)
......@@ -81,7 +82,8 @@ PLATFORMS
ruby
DEPENDENCIES
google_drive (= 3.0.3)
byebug
google_drive (~> 3.0.5)
httparty (= 0.17.0)
mediainfo (= 1.3.3)
rubocop (~> 0.87)
......
......@@ -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`:
......
......@@ -16,6 +16,15 @@ require 'ostruct'
require 'httparty'
require 'mediainfo'
module GoogleDrive
# Monkey patches google-drive-ruby to support shared drivers
class Session
def root_collection
@root_collection ||= file_by_id(ENV['GOOGLE_DRIVE_ID'])
end
end
end
# Client to access Zoom.us recordings and paginate records
class ZoomClient
include HTTParty
......@@ -106,16 +115,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
@session.root_collection
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 +151,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}"
......@@ -179,6 +196,8 @@ end
# Iterates through all Zoom.us recordings and transfers them to a folder
# in Google Drive
# rubocop:disable Metrics/ClassLength
class ZoomSyncher
attr_reader :client, :gdrive_client
......@@ -187,7 +206,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 +313,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'
......@@ -342,6 +367,7 @@ class ZoomSyncher
filename.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
end
end
# rubocop:enable Metrics/ClassLength
if $PROGRAM_NAME == __FILE__
syncher = ZoomSyncher.new
......
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