mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
Add option for custom fields to the export modal
This commit is contained in:
parent
31e6f4282d
commit
26fb9a6803
6 changed files with 167 additions and 15 deletions
|
@ -26,36 +26,57 @@ DOCUMENTATION :: END
|
|||
<form method="post" class="form" id="export_metadata_form">
|
||||
<input type="hidden" id="export_section_id" name="export_section_id" value="${section_id or ''}" />
|
||||
<input type="hidden" id="export_rating_key" name="export_rating_key" value="${rating_key or ''}" />
|
||||
<input type="hidden" id="export_media_type" name="export_media_type" value="${media_type or ''}" />
|
||||
<div class="form-group">
|
||||
<label for="metadata_export_level_select">Metadata Export Level</label>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<select class="form-control" id="metadata_export_level_select" name="metadata_export_level_select">
|
||||
<option value="1">Level 1 - Basic Metadata</option>
|
||||
<option value="0">Level 0 - Custom</option>
|
||||
<option value="1" selected>Level 1 - Basic Metadata</option>
|
||||
<option value="2">Level 2 - Extended Metadata</option>
|
||||
<option value="3">Level 3 - Advanced Metadata</option>
|
||||
<option value="9">Level 9 - All Metadata</option>
|
||||
## <option value="-999">Custom</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">Select the metadata export level.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="export_custom_metadata_fields">Custom Metadata Fields</label>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<select class="form-control" id="export_custom_metadata_fields" name="export_custom_metadata_fields" data-field_type="Metadata">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">Add additional fields to the selected metadata export level.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="media_info_export_level_select">Media Info Export Level</label>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<select class="form-control" id="media_info_export_level_select" name="media_info_export_level_select">
|
||||
<option value="1">Level 1 - Basic Media Info</option>
|
||||
<option value="0">Level 0 - Custom</option>
|
||||
<option value="1" selected>Level 1 - Basic Media Info</option>
|
||||
<option value="2">Level 2 - Extended Media Info</option>
|
||||
<option value="3">Level 3 - Advanced Media Info</option>
|
||||
<option value="9">Level 9 - All Media Info</option>
|
||||
## <option value="-999">Custom</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">Select the media info export level.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="export_custom_media_info_fields">Custom Media Info Fields</label>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<select class="form-control" id="export_custom_media_info_fields" name="export_custom_media_info_fields" data-field_type="Media Info">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">Add additional fields to the selected media info export level.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="file_format_select">File Format</label>
|
||||
<div class="row">
|
||||
|
@ -83,7 +104,6 @@ DOCUMENTATION :: END
|
|||
Warning: Exporting images may take a long time!<br>
|
||||
Note: Only applies to movies, shows, seasons, artists, albums, collections, and playlists.
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
@ -94,6 +114,56 @@ DOCUMENTATION :: END
|
|||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$('#export_metadata_form').submit(function(e) {
|
||||
e.preventDefault();
|
||||
})
|
||||
|
||||
var optgroups = (function () {
|
||||
var optgroups = [];
|
||||
for (var i = 0; i <= 9; i++) {
|
||||
optgroups.push({$order: i, value: i});
|
||||
}
|
||||
return optgroups
|
||||
})()
|
||||
|
||||
var $export_custom_fields = $('#export_custom_metadata_fields, #export_custom_media_info_fields').selectize({
|
||||
plugins: ['remove_button'],
|
||||
maxItems: null,
|
||||
valueField: 'field',
|
||||
labelField: 'field',
|
||||
sortField: 'field',
|
||||
searchField: ['field'],
|
||||
optgroupField: 'level',
|
||||
optgroups: optgroups,
|
||||
lockOptgroupOrder: true,
|
||||
render: {
|
||||
optgroup_header: function(data, escape) {
|
||||
return '<div class="optgroup-header">' + escape(this.$input.data('field_type') + ' Level: ' + data.value) + '</div>';
|
||||
},
|
||||
option: function (item, escape) {
|
||||
return '<div data-field="' + escape(item.field) + '" data-level="' + escape(item.level) + '">' + escape(item.field) +'</div>';
|
||||
}
|
||||
}
|
||||
});
|
||||
var export_custom_metadata_fields = $export_custom_fields[0].selectize;
|
||||
var export_custom_media_info_fields = $export_custom_fields[1].selectize;
|
||||
|
||||
function getExportFields() {
|
||||
$.ajax({
|
||||
url: 'get_export_fields',
|
||||
data: {
|
||||
media_type: $('#export_media_type').val()
|
||||
},
|
||||
success: function (result) {
|
||||
if (result) {
|
||||
export_custom_metadata_fields.addOption(result.metadata_fields);
|
||||
export_custom_media_info_fields.addOption(result.media_info_fields);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
getExportFields();
|
||||
|
||||
$("#export_metadata").click(function() {
|
||||
var section_id = $('#export_section_id').val();
|
||||
var rating_key = $('#export_rating_key').val();
|
||||
|
@ -102,6 +172,8 @@ DOCUMENTATION :: END
|
|||
var file_format = $('#file_format_select option:selected').val();
|
||||
var include_thumb = $("#export_include_thumb").is(':checked') ? 1 : 0;
|
||||
var include_art = $("#export_include_art").is(':checked') ? 1 : 0;
|
||||
var custom_fields = $.merge($('#export_custom_metadata_fields').val() || [],
|
||||
$('#export_custom_media_info_fields').val() || []).join(',')
|
||||
|
||||
$.ajax({
|
||||
url: 'export_metadata',
|
||||
|
@ -112,7 +184,8 @@ DOCUMENTATION :: END
|
|||
media_info_level: media_info_export_level,
|
||||
file_format: file_format,
|
||||
include_thumb: include_thumb,
|
||||
include_art: include_art
|
||||
include_art: include_art,
|
||||
custom_fields: custom_fields
|
||||
},
|
||||
async: true,
|
||||
success: function (data) {
|
||||
|
|
|
@ -541,17 +541,16 @@ DOCUMENTATION :: END
|
|||
</div>
|
||||
</div>
|
||||
% endif
|
||||
% if _session['user_group'] == 'admin':
|
||||
% if not data['live'] and _session['user_group'] == 'admin':
|
||||
<div class="col-md-12">
|
||||
<div class="table-card-header">
|
||||
<div class="header-bar">
|
||||
<span>Metadata Exports for <strong>${data['title']}</strong></span>
|
||||
</div>
|
||||
<div class="button-bar">
|
||||
% if _session['user_group'] == 'admin':
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-dark export-button" id="toggle-export-modal" data-toggle="modal" data-target="#export-modal"
|
||||
data-section_id="${data['section_id']}" data-rating_key="${data['rating_key']}">
|
||||
data-section_id="${data['section_id']}" data-rating_key="${data['rating_key']}" data-media_type="${data['media_type']}">
|
||||
<i class="fa fa-file-export"></i> Export Metadata
|
||||
</button>
|
||||
</div>
|
||||
|
@ -560,7 +559,6 @@ DOCUMENTATION :: END
|
|||
<i class="fa fa-refresh"></i> Refresh exports
|
||||
</button>
|
||||
</div>
|
||||
% endif
|
||||
<div class="btn-group colvis-button-bar" id="button-bar-export"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -885,7 +883,8 @@ DOCUMENTATION :: END
|
|||
url: 'export_metadata_modal',
|
||||
data: {
|
||||
section_id: $(this).data('section_id'),
|
||||
rating_key: $(this).data('rating_key')
|
||||
rating_key: $(this).data('rating_key'),
|
||||
media_type: $(this).data('media_type')
|
||||
},
|
||||
cache: false,
|
||||
async: true,
|
||||
|
|
|
@ -322,7 +322,7 @@ DOCUMENTATION :: END
|
|||
% if _session['user_group'] == 'admin':
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-dark export-button" id="toggle-export-modal" data-toggle="modal" data-target="#export-modal"
|
||||
data-section_id="${data['section_id']}">
|
||||
data-section_id="${data['section_id']}" data-media_type="${'photoalbum' if data['section_type'] == 'photo' else data['section_type']}">
|
||||
<i class="fa fa-file-export"></i> Export Metadata
|
||||
</button>
|
||||
</div>
|
||||
|
@ -565,7 +565,10 @@ DOCUMENTATION :: END
|
|||
$("#toggle-export-modal").click(function() {
|
||||
$.ajax({
|
||||
url: 'export_metadata_modal',
|
||||
data: { section_id: $(this).data('section_id') },
|
||||
data: {
|
||||
section_id: $(this).data('section_id'),
|
||||
media_type: $(this).data('media_type')
|
||||
},
|
||||
cache: false,
|
||||
async: true,
|
||||
complete: function(xhr, status) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue