diff --git a/src/model/media.js b/src/model/media.js index ee8b0b8..82a5db0 100644 --- a/src/model/media.js +++ b/src/model/media.js @@ -32,9 +32,12 @@ function exifDate (file) { } function caption (file) { - const desc = file.meta.EXIF ? file.meta.EXIF['ImageDescription'] : null - const caption = file.meta.IPTC ? file.meta.IPTC['Caption-Abstract'] : null - return desc || caption + return tagValue(file, 'EXIF', 'ImageDescription') || + tagValue(file, 'IPTC', 'Caption-Abstract') || + tagValue(file, 'IPTC', 'Headline') || + tagValue(file, 'XMP', 'Description') || + tagValue(file, 'XMP', 'Title') || + tagValue(file, 'XMP', 'Label') } function animated (file) { @@ -43,4 +46,9 @@ function animated (file) { return false } +function tagValue (file, type, name) { + if (!file.meta[type]) return null + return file.meta[type][name] +} + module.exports = Media diff --git a/test/model/media.spec.js b/test/model/media.spec.js index 49b4c70..d752c77 100644 --- a/test/model/media.spec.js +++ b/test/model/media.spec.js @@ -53,26 +53,21 @@ describe('Media', function () { }) describe('caption', function () { - it('uses the EXIF caption if present', function () { - const file = fixtures.file() - file.meta.EXIF['ImageDescription'] = 'some caption' - const media = new Media(file) - should(media.caption).eql('some caption') - }) - - it('uses the IPTC caption if present', function () { - const file = fixtures.file() - file.meta.IPTC['Caption-Abstract'] = 'some caption' - const media = new Media(file) - should(media.caption).eql('some caption') - }) - - it('uses the EXIF caption if both EXIF and IPTC exist', function () { - const file = fixtures.file() - file.meta.EXIF['ImageDescription'] = 'exif caption' - file.meta.IPTC['Caption-Abstract'] = 'iptc caption' - const media = new Media(file) - should(media.caption).eql('exif caption') + it('is read from all standard EXIF/IPTC/XMP tags', function () { + const tags = [ + { type: 'EXIF', tag: 'ImageDescription' }, + { type: 'IPTC', tag: 'Caption-Abstract' }, + { type: 'IPTC', tag: 'Headline' }, + { type: 'XMP', tag: 'Description' }, + { type: 'XMP', tag: 'Title' }, + { type: 'XMP', tag: 'Label' } + ] + tags.forEach(t => { + const file = fixtures.file() + file.meta[t.type][t.tag] = 'some caption' + const media = new Media(file) + should(media.caption).eql('some caption') + }) }) }) })