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.
This commit is contained in:
parent
b6f8258484
commit
f51a1465b4
5 changed files with 16 additions and 2 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
|
@ -34,6 +34,7 @@
|
||||||
"eslint": "^9.32.0",
|
"eslint": "^9.32.0",
|
||||||
"eslint-plugin-import": "^2.32.0",
|
"eslint-plugin-import": "^2.32.0",
|
||||||
"eslint-plugin-only-warn": "^1.1.0",
|
"eslint-plugin-only-warn": "^1.1.0",
|
||||||
|
"iso-639-2": "^3.0.2",
|
||||||
"obsidian": "latest",
|
"obsidian": "latest",
|
||||||
"openapi-fetch": "^0.14.0",
|
"openapi-fetch": "^0.14.0",
|
||||||
"openapi-typescript": "^7.8.0",
|
"openapi-typescript": "^7.8.0",
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@ import type MediaDbPlugin from '../../main';
|
||||||
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||||
import { MusicReleaseModel } from '../../models/MusicReleaseModel';
|
import { MusicReleaseModel } from '../../models/MusicReleaseModel';
|
||||||
import { MediaType } from '../../utils/MediaType';
|
import { MediaType } from '../../utils/MediaType';
|
||||||
import { contactEmail, extractTracksFromMedia, mediaDbVersion, pluginName } from '../../utils/Utils';
|
import { contactEmail, extractTracksFromMedia, getLanguageName, mediaDbVersion, pluginName } from '../../utils/Utils';
|
||||||
import { APIModel } from '../APIModel';
|
import { APIModel } from '../APIModel';
|
||||||
|
import { iso6392 } from 'iso-639-2';
|
||||||
|
|
||||||
// sadly no open api schema available
|
// sadly no open api schema available
|
||||||
|
|
||||||
|
|
@ -187,8 +188,10 @@ export class MusicBrainzAPI extends APIModel {
|
||||||
image: 'https://coverartarchive.org/release-group/' + result.id + '/front-500.jpg',
|
image: 'https://coverartarchive.org/release-group/' + result.id + '/front-500.jpg',
|
||||||
|
|
||||||
artists: result['artist-credit'].map(a => a.name),
|
artists: result['artist-credit'].map(a => a.name),
|
||||||
|
language: releaseData['text-representation'].language ? getLanguageName(releaseData['text-representation'].language) : 'Unknown',
|
||||||
genres: result.genres.map(g => g.name),
|
genres: result.genres.map(g => g.name),
|
||||||
subType: result['primary-type'],
|
subType: result['primary-type'],
|
||||||
|
trackCount: releaseData.media[0]['track-count'] ?? 0,
|
||||||
tracks: tracks,
|
tracks: tracks,
|
||||||
rating: result.rating.value * 2,
|
rating: result.rating.value * 2,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { MediaType } from '../utils/MediaType';
|
import { MediaType } from '../utils/MediaType';
|
||||||
import type { ModelToData } from '../utils/Utils';
|
import type { ModelToData } from '../utils/Utils';
|
||||||
import { mediaDbTag, migrateObject } from '../utils/Utils';
|
import { mediaDbTag, migrateObject, getLanguageName } from '../utils/Utils';
|
||||||
import { MediaTypeModel } from './MediaTypeModel';
|
import { MediaTypeModel } from './MediaTypeModel';
|
||||||
|
|
||||||
export type MusicReleaseData = ModelToData<MusicReleaseModel>;
|
export type MusicReleaseData = ModelToData<MusicReleaseModel>;
|
||||||
|
|
@ -8,9 +8,11 @@ export type MusicReleaseData = ModelToData<MusicReleaseModel>;
|
||||||
export class MusicReleaseModel extends MediaTypeModel {
|
export class MusicReleaseModel extends MediaTypeModel {
|
||||||
genres: string[];
|
genres: string[];
|
||||||
artists: string[];
|
artists: string[];
|
||||||
|
language: string;
|
||||||
image: string;
|
image: string;
|
||||||
rating: number;
|
rating: number;
|
||||||
releaseDate: string;
|
releaseDate: string;
|
||||||
|
trackCount: number;
|
||||||
tracks: {
|
tracks: {
|
||||||
number: number;
|
number: number;
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -42,7 +44,9 @@ export class MusicReleaseModel extends MediaTypeModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.type = this.getMediaType();
|
this.type = this.getMediaType();
|
||||||
|
this.trackCount = obj.trackCount ?? 0;
|
||||||
this.tracks = obj.tracks ?? [];
|
this.tracks = obj.tracks ?? [];
|
||||||
|
this.language = obj.language ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
getTags(): string[] {
|
getTags(): string[] {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import type { TFile, TFolder, App } from 'obsidian';
|
import type { TFile, TFolder, App } from 'obsidian';
|
||||||
import { requestUrl } from 'obsidian';
|
import { requestUrl } from 'obsidian';
|
||||||
import type { MediaTypeModel } from '../models/MediaTypeModel';
|
import type { MediaTypeModel } from '../models/MediaTypeModel';
|
||||||
|
import { iso6392 } from 'iso-639-2';
|
||||||
|
|
||||||
export const pluginName: string = 'obsidian-media-db-plugin';
|
export const pluginName: string = 'obsidian-media-db-plugin';
|
||||||
export const contactEmail: string = 'm.projects.code@gmail.com';
|
export const contactEmail: string = 'm.projects.code@gmail.com';
|
||||||
|
|
@ -318,3 +319,8 @@ export function extractTracksFromMedia(media: any[]): {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
export function getLanguageName(code: string): string | null {
|
||||||
|
const language = iso6392.find(lang => lang.iso6392B === code || lang.iso6392T === code);
|
||||||
|
|
||||||
|
return language?.name ?? null;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue