Fix no-status bug, add file organizaiton
authorRhett Aultman <rhett.aultman@meraki.net>
Tue, 15 Dec 2020 18:17:54 +0000 (13:17 -0500)
committerRhett Aultman <rhett.aultman@meraki.net>
Tue, 15 Dec 2020 18:17:54 +0000 (13:17 -0500)
This commit introuduces multiple fixes and improvements:
* The check for recording status complete could fail if there was no
status for a given recording, which the Zoom API apparently does.  A
check for the non-existence of the 'status' key was added.
* The script downloaded all types as MP4 files, which is a mess if there
are CC, M4A, VTT, etc, to also download.  File type detection was added.
* The script organizes all related recordings in subdirectories by
meeting ID.

cloudlink.py

index c644042a5dd35378ca42977eabbc2695a22d1bf4..c8d485f940aeef0e1fb0733baac4f6d0ea5ce315 100644 (file)
@@ -1,3 +1,4 @@
+import os
 import requests 
 import datetime
 
@@ -60,22 +61,33 @@ def get_recording(start_date, next_date):
        # print(data['to'])
 
        for meeting in data['meetings']:
+               os.mkdir('{}{}'.format(PATH, meeting['id']))
                for record in meeting['recording_files']:
-                       if record['status'] != 'completed':
+                       if 'status' in record and record['status'] != 'completed':
                                continue
 
                        download_recording(
                                record['download_url'], 
-                               record['recording_start'].replace(':','-')
+                               record['recording_start'].replace(':','-'),
+                               record['file_type'],
+                               meeting['id']
                        )
 
 
-def download_recording(download_url, filename):
+def download_recording(download_url, filename, filetype, meeting_id):
        print(download_url)
        download_access_url = '{}?access_token={}'.format(download_url, JWT)
        print(download_access_url)
        response = requests.get(download_access_url, stream=True)
-       local_filename = '{}{}.mp4'.format(PATH, filename)
+       suffix = filetype
+       if filetype == 'CC' or filetype == 'TRANSCRIPT' or filetype == '':
+               suffix = 'VTT'
+       elif filetype == 'CHAT':
+               suffix = 'TXT'
+       elif filetype == 'TIMELINE':
+               suffix = 'JSON'
+       suffix = suffix.lower()
+       local_filename = '{}/{}/{}_{}.{}'.format(PATH, meeting_id, filename, filetype, suffix)
 
        with open(local_filename, 'wb') as f:
                for chunk in response.iter_content(chunk_size=8192):