From: Rhett Aultman Date: Tue, 15 Dec 2020 18:17:54 +0000 (-0500) Subject: Fix no-status bug, add file organizaiton X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=a171837eacf71b7d09aeb03a0e34960beb02bcf0;p=zoom-batch-downloader.git Fix no-status bug, add file organizaiton 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. --- diff --git a/cloudlink.py b/cloudlink.py index c644042..c8d485f 100644 --- a/cloudlink.py +++ b/cloudlink.py @@ -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):