-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplaylist.py
57 lines (45 loc) · 1.65 KB
/
playlist.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
'''
Created on Nov 3, 2012
@author: raber
'''
from xml.dom.minidom import parse
class PlaylistParse(object):
'''
classdocs
'''
def __init__(self, playlist):
'''
Constructor
'''
self.dom = parse(playlist)
def getStreams(self):
output = []
streams = self.dom.getElementsByTagName('StreamIndex')
for stream in streams:
stream_dict = dict()
#stream_dict['Node'] = stream
attrs = stream.attributes
for i in range(0, len(attrs)):
attr = attrs.item(i)
stream_dict[attr.name] = attr.value
bitrates = stream.getElementsByTagName('QualityLevel')
stream_dict['Bitrates'] = []
for bitrate in bitrates:
bitrate_dict = dict()
#bitrate_dict['Node'] = bitrate
attrs = bitrate.attributes
for i in range(0, len(attrs)):
attr = attrs.item(i)
bitrate_dict[attr.name] = attr.value
stream_dict['Bitrates'].append(bitrate_dict)
chunks = stream.getElementsByTagName('c')
stream_dict['Chunks'] = []
for chunk in chunks:
chunk_dict = dict()
attrs = chunk.attributes
for i in range(0, len(attrs)):
attr = attrs.item(i)
chunk_dict[attr.name] = attr.value
stream_dict['Chunks'].append(chunk_dict)
output.append(stream_dict)
return output