Add m3u8 export file format

This commit is contained in:
JonnyWong16 2020-10-02 19:42:24 -07:00
parent be9f06795d
commit 34c9ede9c9
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
6 changed files with 89 additions and 17 deletions

View file

@ -1385,7 +1385,7 @@ def escape_xml(value):
# https://gist.github.com/reimund/5435343/
def dict2xml(d, root_node=None, indent=4, level=0):
def dict_to_xml(d, root_node=None, indent=4, level=0):
wrap = not bool(root_node is None or isinstance(d, list))
root = root_node or 'objects'
root_singular = root[:-1] if root.endswith('s') and isinstance(d, list) else root
@ -1395,9 +1395,9 @@ def dict2xml(d, root_node=None, indent=4, level=0):
if isinstance(d, dict):
for key, value in sorted(d.items()):
if isinstance(value, dict):
children.append(dict2xml(value, key, level=level + 1))
children.append(dict_to_xml(value, key, level=level + 1))
elif isinstance(value, list):
children.append(dict2xml(value, key, level=level + 1))
children.append(dict_to_xml(value, key, level=level + 1))
else:
xml = '{} {}="{}"'.format(xml, key, escape_xml(value))
elif isinstance(d, list):
@ -1405,7 +1405,7 @@ def dict2xml(d, root_node=None, indent=4, level=0):
# Custom tag replacement for collections/playlists
if isinstance(value, dict) and root in ('children', 'items'):
root_singular = value.get('type', root_singular)
children.append(dict2xml(value, root_singular, level=level))
children.append(dict_to_xml(value, root_singular, level=level))
else:
children.append(escape_xml(d))