Add option for custom fields to the export modal

This commit is contained in:
JonnyWong16 2020-09-28 23:47:32 -07:00
commit 26fb9a6803
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
6 changed files with 167 additions and 15 deletions

View file

@ -1841,3 +1841,37 @@ def get_export_filepath(filename, images=False):
def check_export_exists(filename):
return os.path.isfile(get_export_filepath(filename))
def get_custom_fields(media_type):
export = Export()
if media_type not in export.MEDIA_TYPES:
return {'metadata_fields': [], 'media_info_fields': []}
media_attrs = export.return_attrs(media_type)
metadata_levels, media_info_levels = export.return_levels(media_type)
metadata_levels_dict = {attr: level for level, attrs in reversed(sorted(metadata_levels.items()))
for attr in attrs}
media_info_levels_dict = {attr: level for level, attrs in reversed(sorted(media_info_levels.items()))
for attr in attrs}
flatten_attrs = helpers.flatten_dict(media_attrs)[0]
custom_metadata_fields = []
custom_media_info_fields = []
for attr in sorted(flatten_attrs):
metadata_level = metadata_levels_dict.get(attr, 9 if not attr.startswith('media.') else None)
media_info_level = media_info_levels_dict.get(attr, 9 if attr.startswith('media.') else None)
if metadata_level is not None:
custom_metadata_fields.append({'field': attr, 'level': metadata_level})
elif media_info_level is not None:
custom_media_info_fields.append({'field': attr, 'level': media_info_level})
custom_fields = {
'metadata_fields': custom_metadata_fields,
'media_info_fields': custom_media_info_fields
}
return custom_fields

View file

@ -1300,6 +1300,18 @@ def dict_merge(a, b, path=None):
return a
#https://stackoverflow.com/a/26853961
def dict_update(*dict_args):
"""
Given any number of dictionaries, shallow copy and merge into a new dict,
precedence goes to key value pairs in latter dictionaries.
"""
result = {}
for dictionary in dict_args:
result.update(dictionary)
return result
def is_hdr(bit_depth, color_space):
bit_depth = cast_to_int(bit_depth)
return bit_depth > 8 and color_space == 'bt2020nc'

View file

@ -6482,10 +6482,41 @@ class WebInterface(object):
@cherrypy.expose
@requireAuth(member_of("admin"))
def export_metadata_modal(self, section_id=None, rating_key=None, **kwargs):
def export_metadata_modal(self, section_id=None, rating_key=None, media_type=None, **kwargs):
return serve_template(templatename="export_modal.html", title="Export Metadata",
section_id=section_id, rating_key=rating_key)
section_id=section_id, rating_key=rating_key, media_type=media_type)
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
@addtoapi()
def get_export_fields(self, media_type=None, **kwargs):
""" Get a list of available custom export fields.
```
Required parameters:
media_type (str): The media type of the fields to return
Optional parameters:
None
Returns:
json:
{"metadata_fields":
[{"field": "addedAt", "level": 1},
...
],
"media_info_fields":
[{"field": "media.aspectRatio", "level": 1},
...
]
}
```
"""
custom_fields = exporter.get_custom_fields(media_type=media_type)
return custom_fields
@cherrypy.expose
@cherrypy.tools.json_out()