Created
November 2, 2024 16:17
-
-
Save hussainweb/74e30bc7dbe1d143d50655f4d8aa504d to your computer and use it in GitHub Desktop.
Download recordings from Zoom... Only for archive use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from datetime import date, datetime | |
import json | |
from pathlib import Path | |
import os | |
import sys | |
from urllib.request import Request, urlopen, urlretrieve | |
ZOOM_BASE_URL = "https://api.zoom.us/v2/" | |
zoom_user_id = os.environ.get("ZOOM_USER_ID") # User Id or email address | |
zoom_token = os.environ.get("ZOOM_TOKEN") | |
if not zoom_user_id or not zoom_token: | |
print("ZOOM_USER_ID or ZOOM_TOKEN not set.") | |
sys.exit(1) | |
recording_file_extensions = { | |
"MP4": "mp4", | |
"M4A": "m4a", | |
"TIMELINE": "json", | |
"TRANSCRIPT": "vtt", | |
"CHAT": "txt", | |
"CC": "vtt", | |
"CSV": "csv", | |
} | |
today = date.today() | |
year = today.year | |
month = today.month | |
meetings = [] | |
while year >= 2018: | |
recording_start = date(year, month, 1) | |
next_month = month + 1 | |
next_year = year | |
if next_month == 13: | |
next_month = 1 | |
next_year = year + 1 | |
recording_end = date(next_year, next_month, 1) | |
url = f"{ZOOM_BASE_URL}users/{zoom_user_id}/recordings?page_size=300&from={recording_start}&to={recording_end}" | |
print(f"Requesting recordings from {recording_start} to {recording_end}...") | |
req = Request(url, headers={ | |
"content-type": "application/json", | |
"authorization": "Bearer " + zoom_token | |
}) | |
with urlopen(req) as response: | |
meeting_list = response.read() | |
meetings_data = json.loads(meeting_list) | |
for meeting_info in meetings_data["meetings"]: | |
meeting_recordings = [] | |
for recording_info in meeting_info["recording_files"]: | |
if recording_info["file_type"] == "M4A": | |
continue | |
meeting_recordings.append(recording_info) | |
meeting_info["recordings"] = meeting_recordings | |
del meeting_info["recording_files"] | |
meetings.append(meeting_info) | |
month -= 1 | |
if month == 0: | |
year -= 1 | |
month = 12 | |
print(f"Found {len(meetings)} recordings...") | |
download_path = Path("Recordings") | |
download_path.mkdir(exist_ok=True) | |
print("Beginning to download recordings") | |
for meeting in meetings: | |
if meeting["topic"].startswith("Peer Interview"): | |
print(f"Skipping {meeting['topic']}") | |
continue | |
print(f"Processing meeting {meeting['topic']}") | |
meeting_date = datetime.strptime(meeting["start_time"], "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d") | |
path_safe_uuid = "".join(x for x in meeting['uuid'] if x.isalnum()) | |
meeting_path = download_path / f"{meeting_date} - {meeting['topic']} - {path_safe_uuid}" | |
meeting_path.mkdir(exist_ok=True) | |
for recording in meeting["recordings"]: | |
file_name = f"{meeting['topic']} - {recording['recording_type']} - {meeting_date}.{recording_file_extensions[recording['file_type']]}" | |
recording_path = meeting_path / file_name | |
if recording_path.exists() and recording_path.stat().st_size == recording["file_size"]: | |
print(f"We already have the recording {file_name}. Skipping...") | |
continue | |
download_url = recording["download_url"] + "?access_token=" + zoom_token | |
print(f"Downloading {file_name} from {download_url} ({recording['file_size']} bytes)...") | |
urlretrieve(download_url, recording_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment