-
Notifications
You must be signed in to change notification settings - Fork 188
/
getPSSH.py
47 lines (46 loc) · 2.15 KB
/
getPSSH.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
import requests, xmltodict, json
def get_pssh(mpd_url):
pssh = ''
try:
r = requests.get(url=mpd_url)
r.raise_for_status()
xml = xmltodict.parse(r.text)
mpd = json.loads(json.dumps(xml))
periods = mpd['MPD']['Period']
except Exception as e:
pssh = input(f'\nUnable to find PSSH in MPD: {e}. \nEdit getPSSH.py or enter PSSH manually: ')
return pssh
try:
if isinstance(periods, list):
for idx, period in enumerate(periods):
if isinstance(period['AdaptationSet'], list):
for ad_set in period['AdaptationSet']:
if ad_set['@mimeType'] == 'video/mp4':
try:
for t in ad_set['ContentProtection']:
if t['@schemeIdUri'].lower() == "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":
pssh = t["cenc:pssh"]
except Exception:
pass
else:
if period['AdaptationSet']['@mimeType'] == 'video/mp4':
try:
for t in period['AdaptationSet']['ContentProtection']:
if t['@schemeIdUri'].lower() == "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":
pssh = t["cenc:pssh"]
except Exception:
pass
else:
for ad_set in periods['AdaptationSet']:
if ad_set['@mimeType'] == 'video/mp4':
try:
for t in ad_set['ContentProtection']:
if t['@schemeIdUri'].lower() == "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":
pssh = t["cenc:pssh"]
except Exception:
pass
except Exception:
pass
if pssh == '':
pssh = input('Unable to find PSSH in mpd. Edit getPSSH.py or enter PSSH manually: ')
return pssh