Skip to content

Commit

Permalink
Store album title as 'dc:relation.isPartOf'
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmz committed Feb 1, 2025
1 parent 42c777d commit 766c720
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
_MediaPreviews_ type in the
[app/support/media-files/types.ts](app/support/media-files/types.ts) file.
- `meta`: JSON object with temporary or not essential media metadata. It can
contain the audio/video title and author name (in 'dc:title' and
'dc:creator' fields, respectively) and some special flags:
contain the audio/video title, album title and author name (in 'dc:title',
'dc:relation.isPartOf' and 'dc:creator' fields, respectively) and some
special flags:
- `animatedImage`: true if the video was created from an animated image
- `silent`: true if the video has no audio track
- `inProgress`: true if the media file is currently being processed
Expand Down
29 changes: 24 additions & 5 deletions app/support/media-files/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,22 @@ export async function processMediaFile(
if (info.type === 'audio' || info.type === 'video') {
commonResult.duration = info.duration;

if (info.tags?.title) {
commonResult.meta!['dc:title'] = info.tags.title;
}
if (info.tags) {
const title = getKeyCaseInsensitive(info.tags, 'title');
const artist = getKeyCaseInsensitive(info.tags, 'artist');
const album = getKeyCaseInsensitive(info.tags, 'album');

if (title) {
commonResult.meta!['dc:title'] = title;
}

if (artist) {
commonResult.meta!['dc:creator'] = artist;
}

if (info.tags?.artist) {
commonResult.meta!['dc:creator'] = info.tags.artist;
if (album) {
commonResult.meta!['dc:relation.isPartOf'] = album;
}
}
}

Expand Down Expand Up @@ -513,3 +523,12 @@ async function fileProps(filePath: string, origFileName: string, ext: string): P
mimeType: mimeLookup(ext) || 'application/octet-stream',
};
}

/**
* Get a key in a case-insensitive way
*/
function getKeyCaseInsensitive(obj: Record<string, string>, key: string): string | undefined {
key = key.toLowerCase();
const realKey = Object.keys(obj).find((k) => k.toLowerCase() === key);
return realKey ? obj[realKey] : undefined;
}
1 change: 1 addition & 0 deletions test/functional/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ describe('Attachments', () => {
meta: {
'dc:title': 'Improvisation with Sopranino Recorder',
'dc:creator': 'Piermic',
'dc:relation.isPartOf': 'Wikimedia',
},
duration: 24.032653,
createdAt: attObj.createdAt.toISOString(),
Expand Down
1 change: 1 addition & 0 deletions test/integration/models/attachment.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ describe('Attachments', () => {
expect(att.meta, 'to equal', {
'dc:title': 'Improvisation with Sopranino Recorder',
'dc:creator': 'Piermic',
'dc:relation.isPartOf': 'Wikimedia',
});
});

Expand Down

0 comments on commit 766c720

Please sign in to comment.