Add custom fields for collections and playlists

This commit is contained in:
JonnyWong16 2020-09-29 19:40:53 -07:00
parent 54433c43e6
commit 97775e2a3b
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
4 changed files with 37 additions and 21 deletions

View file

@ -83,8 +83,9 @@ class Export(object):
'album': 'track',
'track': '',
'photoalbum': 'photo',
'photo': '',
'collection': 'children',
'playlist': 'items'
'playlist': 'item'
}
METADATA_LEVELS = (0, 1, 2, 3, 9)
MEDIA_INFO_LEVELS = (0, 1, 2, 3, 9)
@ -1889,11 +1890,18 @@ def check_export_exists(filename):
return os.path.isfile(get_export_filepath(filename))
def get_custom_fields(media_type):
def get_custom_fields(media_type, sub_media_type=None):
custom_fields = {
'metadata_fields': [],
'media_info_fields': []
}
export = Export()
if media_type not in export.MEDIA_TYPES:
return {'metadata_fields': [], 'media_info_fields': []}
return custom_fields
elif media_type in ('collection', 'playlist') and sub_media_type not in export.MEDIA_TYPES:
return custom_fields
metadata_levels_map, media_info_levels_map = export.return_attrs_level_map(media_type)
@ -1901,23 +1909,24 @@ def get_custom_fields(media_type):
child_media_type = export.CHILD_MEDIA_TYPES[media_type]
while child_media_type:
if child_media_type in ('children', 'item'):
fields_child_media_type = sub_media_type
else:
fields_child_media_type = child_media_type
prefix = prefix + export.PLURAL_MEDIA_TYPES[child_media_type] + '.'
child_metadata_levels_map, child_media_info_levels_map = export.return_attrs_level_map(
child_media_type, prefix=prefix)
fields_child_media_type, prefix=prefix)
metadata_levels_map.update(child_metadata_levels_map)
media_info_levels_map.update(child_media_info_levels_map)
child_media_type = export.CHILD_MEDIA_TYPES[child_media_type]
child_media_type = export.CHILD_MEDIA_TYPES.get(fields_child_media_type)
custom_metadata_fields = [{'field': attr, 'level': level}
for attr, level in sorted(metadata_levels_map.items()) if level]
custom_media_info_fields = [{'field': attr, 'level': level}
for attr, level in sorted(media_info_levels_map.items()) if level]
custom_fields['metadata_fields'] = [{'field': attr, 'level': level}
for attr, level in sorted(metadata_levels_map.items()) if level]
custom_fields['media_info_fields'] = [{'field': attr, 'level': level}
for attr, level in sorted(media_info_levels_map.items()) if level]
custom_fields = {
'metadata_fields': custom_metadata_fields,
'media_info_fields': custom_media_info_fields
}
return custom_fields

View file

@ -6482,16 +6482,18 @@ class WebInterface(object):
@cherrypy.expose
@requireAuth(member_of("admin"))
def export_metadata_modal(self, section_id=None, rating_key=None, media_type=None, **kwargs):
def export_metadata_modal(self, section_id=None, rating_key=None,
media_type=None, sub_media_type=None, **kwargs):
return serve_template(templatename="export_modal.html", title="Export Metadata",
section_id=section_id, rating_key=rating_key, media_type=media_type)
section_id=section_id, rating_key=rating_key,
media_type=media_type, sub_media_type=sub_media_type)
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
@addtoapi()
def get_export_fields(self, media_type=None, **kwargs):
def get_export_fields(self, media_type=None, sub_media_type=None, **kwargs):
""" Get a list of available custom export fields.
```
@ -6499,7 +6501,7 @@ class WebInterface(object):
media_type (str): The media type of the fields to return
Optional parameters:
None
sub_media_type (str): The child media type for collections or playlists
Returns:
json:
@ -6514,7 +6516,8 @@ class WebInterface(object):
}
```
"""
custom_fields = exporter.get_custom_fields(media_type=media_type)
custom_fields = exporter.get_custom_fields(media_type=media_type,
sub_media_type=sub_media_type)
return custom_fields