前書き
会社のデイリーミーティングにGoogle Meetを使っているのだが、困ったことに録画したファイルの保存先を別のフォルダに設定することは現状できないらしい。他の人に共有する際に別の録画も見られてしまうのは嫌だったので何とかならないかなと思いGoogle Apps Script(GAS)で自動的にファイル名変更 & フォルダ移動 & Slackへの通知ができたので共有。
ファイルが移動完了した旨の通知が来るようにSlackにアプリを追加
- https://my.slack.com/services/new/incoming-webhook/ へアクセス
- 投稿チャンネルは適当に選択(GASで指定すればどのチャンネルでも通知出来る)
- 「IncomingWebhook Integrationの追加」クリック
- Webhook URLをコピーして控えておく
録画ファイルを現在のフォルダから別フォルダへ移動するコード(GAS)
function move() {
var mydrive = ""; //移動元フォルダURL
var destination = ""; //移動先フォルダURL
var tittle = ""; //会議名
var slackch = ""; //slackのチャンネル名
var webhookUrl = ""; //控えたWebhookURL
var notificationFlag = true; //slackに通知したくなければここをfalseにする
//移動元フォルダ情報と移動先フォルダ情報を取得
var sliceText = "folders/";
var positionToStartSlice = mydrive.search(sliceText) + sliceText.length;
var origin_folderId = mydrive.slice(positionToStartSlice);
var destination_folderId = destination.slice(positionToStartSlice);
//ファイル一覧取得
var origin_folder = DriveApp.getFolderById(origin_folderId);
var LIST = origin_folder.getFiles();
//ファイル名を比較して対象の場合はファイル名をJSTに直した上で移動させる
while (LIST.hasNext()) {
var file = LIST.next();
if (file.getName().indexOf(tittle) === 0) { //前方一致した場合
//ファイル名を分割
var splitText = (String(file)).split('(');
//作成日を抽出
var lastUpdated = file.getLastUpdated();
var Dateformat = Utilities.formatDate(lastUpdated, '"GMT+9"', 'yyyy-MM-dd'); //日付フォーマット変更
//ファイル名変更
var fileid = file.getId()
var getFileid = DriveApp.getFileById(fileid);
getFileid.setName(splitText[0] + "(" + Dateformat + ")");
//ファイルを移動
var destination_folder = DriveApp.getFolderById(destination_folderId);
getFileid.moveTo(destination_folder);
Logger.log('ファイル名「' + splitText[0] + "(" + Dateformat + ")" + '」を移動しました');
//Slack通知
if (notificationFlag == true) {
var options =
{
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify
(
{
"username": "録画データ通知BOT",
"channel": slackch,
"text": '録画ファイル「' + splitText[0] + "(" + Dateformat + ")" + '」を保存しました' + destination,
"link_names": 1
}
)
};
//Slack投稿
UrlFetchApp.fetch(webhookUrl, options);
}
}
}
}
実行する時間の設定
GASにはトリガーという機能があり、設定すると指定した時刻で上記の関数を実行してくれる。
左の一覧から「トリガー」を選択し右下の「トリガーを追加」ボタン押下
以下のようなメニューが表示されるので、例えば毎日午後3時~4時に実行したい場合は以下のようにする。
参考
[GoogleMeetの録画ファイルをマイドライブ以外に保管させる(+おまけ)][link-1]
[link-1]:https://note.com/yasuym1/n/n9d4e2e0402a1
[Google Apps Script で毎日決まった時刻にスクリプトを実行するトリガー設定][link-2]
[link-2]:https://tonari-it.com/gas-trigger-set/