Skip to content

Commit f51a146

Browse files
committed
Added language and trackCount fields for music
The language at musicbrainz is in the format of iso-639-2 so I use a package to translate it to a full name of the language.
1 parent b6f8258 commit f51a146

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

bun.lockb

355 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"eslint": "^9.32.0",
3535
"eslint-plugin-import": "^2.32.0",
3636
"eslint-plugin-only-warn": "^1.1.0",
37+
"iso-639-2": "^3.0.2",
3738
"obsidian": "latest",
3839
"openapi-fetch": "^0.14.0",
3940
"openapi-typescript": "^7.8.0",

src/api/apis/MusicBrainzAPI.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import type MediaDbPlugin from '../../main';
33
import type { MediaTypeModel } from '../../models/MediaTypeModel';
44
import { MusicReleaseModel } from '../../models/MusicReleaseModel';
55
import { MediaType } from '../../utils/MediaType';
6-
import { contactEmail, extractTracksFromMedia, mediaDbVersion, pluginName } from '../../utils/Utils';
6+
import { contactEmail, extractTracksFromMedia, getLanguageName, mediaDbVersion, pluginName } from '../../utils/Utils';
77
import { APIModel } from '../APIModel';
8+
import { iso6392 } from 'iso-639-2';
89

910
// sadly no open api schema available
1011

@@ -187,8 +188,10 @@ export class MusicBrainzAPI extends APIModel {
187188
image: 'https://coverartarchive.org/release-group/' + result.id + '/front-500.jpg',
188189

189190
artists: result['artist-credit'].map(a => a.name),
191+
language: releaseData['text-representation'].language ? getLanguageName(releaseData['text-representation'].language) : 'Unknown',
190192
genres: result.genres.map(g => g.name),
191193
subType: result['primary-type'],
194+
trackCount: releaseData.media[0]['track-count'] ?? 0,
192195
tracks: tracks,
193196
rating: result.rating.value * 2,
194197

src/models/MusicReleaseModel.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { MediaType } from '../utils/MediaType';
22
import type { ModelToData } from '../utils/Utils';
3-
import { mediaDbTag, migrateObject } from '../utils/Utils';
3+
import { mediaDbTag, migrateObject, getLanguageName } from '../utils/Utils';
44
import { MediaTypeModel } from './MediaTypeModel';
55

66
export type MusicReleaseData = ModelToData<MusicReleaseModel>;
77

88
export class MusicReleaseModel extends MediaTypeModel {
99
genres: string[];
1010
artists: string[];
11+
language: string;
1112
image: string;
1213
rating: number;
1314
releaseDate: string;
15+
trackCount: number;
1416
tracks: {
1517
number: number;
1618
title: string;
@@ -42,7 +44,9 @@ export class MusicReleaseModel extends MediaTypeModel {
4244
}
4345

4446
this.type = this.getMediaType();
47+
this.trackCount = obj.trackCount ?? 0;
4548
this.tracks = obj.tracks ?? [];
49+
this.language = obj.language ?? '';
4650
}
4751

4852
getTags(): string[] {

src/utils/Utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { TFile, TFolder, App } from 'obsidian';
22
import { requestUrl } from 'obsidian';
33
import type { MediaTypeModel } from '../models/MediaTypeModel';
4+
import { iso6392 } from 'iso-639-2';
45

56
export const pluginName: string = 'obsidian-media-db-plugin';
67
export const contactEmail: string = '[email protected]';
@@ -318,3 +319,8 @@ export function extractTracksFromMedia(media: any[]): {
318319
};
319320
});
320321
}
322+
export function getLanguageName(code: string): string | null {
323+
const language = iso6392.find(lang => lang.iso6392B === code || lang.iso6392T === code);
324+
325+
return language?.name ?? null;
326+
}

0 commit comments

Comments
 (0)