Skip to content

Commit 766c720

Browse files
committed
Store album title as 'dc:relation.isPartOf'
1 parent 42c777d commit 766c720

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3838
_MediaPreviews_ type in the
3939
[app/support/media-files/types.ts](app/support/media-files/types.ts) file.
4040
- `meta`: JSON object with temporary or not essential media metadata. It can
41-
contain the audio/video title and author name (in 'dc:title' and
42-
'dc:creator' fields, respectively) and some special flags:
41+
contain the audio/video title, album title and author name (in 'dc:title',
42+
'dc:relation.isPartOf' and 'dc:creator' fields, respectively) and some
43+
special flags:
4344
- `animatedImage`: true if the video was created from an animated image
4445
- `silent`: true if the video has no audio track
4546
- `inProgress`: true if the media file is currently being processed

app/support/media-files/process.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,22 @@ export async function processMediaFile(
7272
if (info.type === 'audio' || info.type === 'video') {
7373
commonResult.duration = info.duration;
7474

75-
if (info.tags?.title) {
76-
commonResult.meta!['dc:title'] = info.tags.title;
77-
}
75+
if (info.tags) {
76+
const title = getKeyCaseInsensitive(info.tags, 'title');
77+
const artist = getKeyCaseInsensitive(info.tags, 'artist');
78+
const album = getKeyCaseInsensitive(info.tags, 'album');
79+
80+
if (title) {
81+
commonResult.meta!['dc:title'] = title;
82+
}
83+
84+
if (artist) {
85+
commonResult.meta!['dc:creator'] = artist;
86+
}
7887

79-
if (info.tags?.artist) {
80-
commonResult.meta!['dc:creator'] = info.tags.artist;
88+
if (album) {
89+
commonResult.meta!['dc:relation.isPartOf'] = album;
90+
}
8191
}
8292
}
8393

@@ -513,3 +523,12 @@ async function fileProps(filePath: string, origFileName: string, ext: string): P
513523
mimeType: mimeLookup(ext) || 'application/octet-stream',
514524
};
515525
}
526+
527+
/**
528+
* Get a key in a case-insensitive way
529+
*/
530+
function getKeyCaseInsensitive(obj: Record<string, string>, key: string): string | undefined {
531+
key = key.toLowerCase();
532+
const realKey = Object.keys(obj).find((k) => k.toLowerCase() === key);
533+
return realKey ? obj[realKey] : undefined;
534+
}

test/functional/attachments.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ describe('Attachments', () => {
253253
meta: {
254254
'dc:title': 'Improvisation with Sopranino Recorder',
255255
'dc:creator': 'Piermic',
256+
'dc:relation.isPartOf': 'Wikimedia',
256257
},
257258
duration: 24.032653,
258259
createdAt: attObj.createdAt.toISOString(),

test/integration/models/attachment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ describe('Attachments', () => {
252252
expect(att.meta, 'to equal', {
253253
'dc:title': 'Improvisation with Sopranino Recorder',
254254
'dc:creator': 'Piermic',
255+
'dc:relation.isPartOf': 'Wikimedia',
255256
});
256257
});
257258

0 commit comments

Comments
 (0)