Import gst-integration-testsuites
[platform/upstream/gstreamer.git] / subprojects / gst-integration-testsuites / testsuites / dashifutils.py
1 # Pastebin PJeVxRyU
2 # -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
3 #
4 # Copyright (c) 2014 Thibault Saunier <thibault.saunier@collabora.com>
5 # Copyright (c) 2017 Sebastian Droege <sebastian@centricular.com>
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the
19 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 # Boston, MA 02110-1301, USA.
21
22 """
23 The GstValidate DASH-IF test-vectors testsuite
24 """
25
26 import json
27 import requests
28 import sys
29 import xml.etree.ElementTree as ET
30
31 TESTVECTOR_URL = "http://testassets.dashif.org:3000/v1/testvectors"
32
33
34 def cleanup_entries(data):
35     # we need to do some minor cleanup of the entries:
36     # * Replace <a href=..>something</a>
37     # * Add __ID corresponding to the testvector unique key on the website
38     d = data["data"]
39     for entry in d:
40         # "testvector": "<a href=\"#testvector/details/58a5e0707459f8cb201b8ceb\">W3C Clear Key - audio only variant</a>",
41         testvector = entry["testvector"]
42         tmp = ET.XML(testvector)
43         _id = tmp.attrib["href"].split('/')[-1]
44         _desc = tmp.text
45         # use a key that is almost certain to be the first one. Ensures entries are sorted by ID
46         entry["A__ID"] = _id
47         entry["testvector_description"] = _desc
48
49         # "url": "<a href=https://media.axprod.net/TestVectors/v7-MultiDRM-MultiKey-MultiPeriod/Manifest_1080p_ClearKey.mpd>Link</a>"
50         # badly formed html, let's just use splitters
51         url = entry["url"]
52         _url = url.split("<a href=")[1].split(">Link<")[0]
53         entry["url"] = _url
54
55
56 def update_testvector_list(outputfile=None):
57     # download and cleanup testvector json
58     resp = requests.get(url=TESTVECTOR_URL)
59     data = json.loads(resp.text)
60     cleanup_entries(data)
61     if outputfile is None:
62         print(json.dumps(data["data"], indent=4, sort_keys=True))
63     else:
64         json.dump(data["data"], fp=open(outputfile, "w"), indent=4, sort_keys=True)
65
66
67 if __name__ == "__main__":
68     if len(sys.argv) > 1:
69         update_testvector_list(sys.argv[1])
70     else:
71         update_testvector_list()