-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
121 lines (99 loc) · 3.81 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import requests
from requests.auth import AuthBase
import getpass
import json
"""
This program is free software: you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see <https://www.gnu.org/licenses/>.
@author René Beckmann
@copyright 2023, grandcentrix GmbH
"""
BASE_URL = "https://api.bluejeans.com"
class BlueJeansAuth(AuthBase):
def __init__(self, token):
# setup any auth-related data here
self.token = token
def __call__(self, r):
# modify and return the request
r.headers['Authorization'] = f"Bearer {self.token}"
return r
def authenticate(name, pw):
url = BASE_URL + "/oauth2/token#User"
body = {
"grant_type": "password",
"username": name,
"password": pw
}
resp = requests.post(url, json=body)
resp.raise_for_status()
result = resp.json()
return result["access_token"], result["scope"]["user"]
def list_meeting_recordings(session, user_id):
url = BASE_URL + f"/v1/user/{user_id}/meeting_history/recordings"
page = 1
while True:
params = {"pageSize": 10, "pageNumber": page}
print(f"Getting recordings page {page}")
resp = session.get(url, params=params)
resp.raise_for_status()
recordings = resp.json()
if len(recordings) == 0:
return
for rec in recordings:
yield rec
page += 1
def get_recording(session, user_id, rec_id):
url = BASE_URL + f"/v1/user/{user_id}/meeting_history/recordings/{rec_id}"
resp = session.get(url)
resp.raise_for_status()
return resp.json()
def get_recording_download_link(session, user_id, content_id):
url = BASE_URL + f"/v1/user/{user_id}/cms/{content_id}"
print(f"Getting link for content ID {content_id}")
params = {
"isDownloadable": True,
"expiry": 10
}
resp = session.get(url, params=params)
resp.raise_for_status()
return resp.json()
def get_dl_links(session, user_id, recordings):
result = list()
for rec in recordings:
rec_id = rec["recordingEntityId"]
recording = get_recording(session, user_id, rec_id)
for chapter in recording["recordingChapters"]:
content_id = chapter["compositeContentId"]
chapter_name = chapter["chapterName"]
start = chapter["startTimeOffset"]
end = chapter["endTimeOffset"]
dl_info = get_recording_download_link(session, user_id, content_id)
for level in dl_info["contentProperties"]["levels"]:
if int(level["height"]) == 720:
result.append({
"name": chapter_name,
"link": level["file"],
"start": start,
"end": end
})
return result
def main():
name = input("BlueJeans username (email):")
pw = getpass.getpass("BlueJeans password:")
print("Accessing recordings...")
session = requests.session()
token, user_id = authenticate(name, pw)
session.auth = BlueJeansAuth(token)
recordings = list_meeting_recordings(session, user_id)
links = get_dl_links(session, user_id, recordings)
print("Writing recordings to recordings.json")
with open("recordings.json", "w") as f:
json.dump(links, f, indent=2, ensure_ascii=False)
if __name__ == "__main__":
main()