diff --git a/pandora/config.pandora.jsonc b/pandora/config.pandora.jsonc index 4bc20c76..aad507bf 100644 --- a/pandora/config.pandora.jsonc +++ b/pandora/config.pandora.jsonc @@ -153,6 +153,19 @@ examples (config.SITENAME.jsonc) that are part of this pan.do/ra distribution. {"id": "embeds", "title": "Embeds"} ], /* + "importMetadata" defines what fields (as defined in "itemKeys") will get + populated with imported metadata. There is metadata for "title", + "description", "uploader", "date", "tags", "id", "url", and the value must + be a format string (like "{title} ({id})"). The type of the itemKeys must + be "string", ["string"], "text", "date" or "year". The last two only work + with "{date}". + */ + "importMetadata": { + "keywords": "{tags}", + "summary": "{description}", + "title": "{title}" + }, + /* "itemKeys" defines the metadata associated with each item. Required keys are "*", "id" and "title". Annotation layers can be referenced too, which makes them available in the find element. Adding a key with "annotations" diff --git a/static/js/importMediaDialog.js b/static/js/importMediaDialog.js index 699eabd8..cec2cde1 100644 --- a/static/js/importMediaDialog.js +++ b/static/js/importMediaDialog.js @@ -88,15 +88,36 @@ pandora.ui.importMediaDialog = function(options) { function addMedia(url, callback) { pandora.api.getMediaUrlInfo({url: url}, function(result) { result.data.items.forEach(function(info) { - pandora.api.add({title: info.title}, function(result) { - var edit = { - date: info.date, - director: info.uploader ? [info.uploader] : [], - id: result.data.id, - notes: info.url, - summary: info.description, - topic: info.tags - }; + var infoKeys = [ + "date", "description", "id", "tags", + "title", "uploader", "url" + ]; + var values = Ox.map(pandora.site.importMetadata, function(value, key) { + var type = pandora.site.itemKeys[key].type; + infoKeys.forEach(function(infoKey) { + infoValue = info[infoKey]; + if (key == 'year') { + infoValue = infoValue.substr(0, 4); + } + if (infoKey == 'tags' && Ox.isArray(type)) { + infoValue = infoValue.join(', '); + } + value = value.replace( + new RegExp('\{' + infoKey '\}', 'g'), infoValue + ); + }); + if (Ox.isArray(type)) { + value = [value]; + } + return value; + }); + pandora.api.add({title: values.title || info.title}, function(result) { + var edit = Ox.extend( + Ox.filter(values, function(value, key) { + return key != 'title' + }), + {'id': result.data.id} + ); pandora.api.edit(edit, function(result) { pandora.api.addMediaUrl({ url: info.url, @@ -104,7 +125,6 @@ pandora.ui.importMediaDialog = function(options) { }, function(result) { if (result.data.taskId) { pandora.wait(result.data.taskId, function(result) { - Ox.print('status?', result); callback(edit.id); }); } else {