-
Notifications
You must be signed in to change notification settings - Fork 21
/
getPSSH.py
65 lines (62 loc) · 2.59 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import requests
import xmltodict
import 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}. \n\nEnter PSSH manually or 'skip': ")
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:
try: # for IW
for ad_set in periods['AdaptationSet']:
if ad_set['@contentType'] == 'video':
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(
f"\nUnable to find PSSH in MPD. Enter PSSH manually or 'skip': ")
return pssh
else:
return pssh