-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcheck_search_episodes_in_archive.py
45 lines (40 loc) · 2.37 KB
/
check_search_episodes_in_archive.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from httpx import BasicAuth, HTTPStatusError
from opencast.archive import get_mediapackage
from opencast.client import OpencastClient
from opencast.info import get_me_json
from opencast.search import get_mediapackages
def main():
source_opencast_admin_url = 'https://stable.opencast.org'
source_opencast_presentation_url = 'https://stable.opencast.org'
source_opencast_username = 'admin'
source_opencast_password = 'opencast'
source_auth = BasicAuth(source_opencast_username, source_opencast_password)
with OpencastClient(source_opencast_admin_url, auth=source_auth,
follow_redirects=True) as source_opencast_admin_client:
with OpencastClient(source_opencast_presentation_url, auth=source_auth,
follow_redirects=True) as source_opencast_presentation_client:
me_json = get_me_json(source_opencast_presentation_client)
assert 'roles' in me_json
assert 'ROLE_ADMIN' in me_json.get('roles', [])
for mp in get_mediapackages(source_opencast_presentation_client):
# print(f'Found published episode {mp.get_title()} (ID: {mp.get_identifier()}).')
try:
mp_archive = get_mediapackage(source_opencast_admin_client, mp.get_identifier())
assert mp.get_identifier() == mp_archive.get_identifier()
print(f'Published episode {mp.get_title()} (ID: {mp.get_identifier()}) is in the archive.')
except HTTPStatusError as e:
if e.response.status_code == 404:
print(f'ERROR: Published episode {mp.get_title()} (ID: {mp.get_identifier()}) is not archived.')
elif e.response.status_code == 403:
print(f'ERROR: Access denied for accessing episode {mp.get_title()} '
f'(ID: {mp.get_identifier()}).')
else:
print(f'ERROR: Unable to read episode {mp.get_title()} (ID: {mp.get_identifier()}) '
f'from archive. Http statuscode was {e.response.status_code}')
except:
print(f'ERROR: Unable to read episode {mp.get_title()} (ID: {mp.get_identifier()}) '
f'from archive.')
if __name__ == '__main__':
main()