Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed Image links #142

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
7 changes: 6 additions & 1 deletion src/api/apis/BoardGameGeekAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export class BoardGameGeekAPI extends APIModel {
this.types = [MediaType.BoardGame];
}

processImageLink(boardgameElement: { querySelector: (arg0: string) => { (): any; new (): any; textContent: any } }) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a better type for this, no? I am guessing boardgame has a type that can be used here.

const imageContent = boardgameElement.querySelector('image')?.textContent;
return this.plugin.settings.generateEmbedLinksForImages && imageContent ? `![](${imageContent})` : imageContent ?? undefined;
}

async searchByTitle(title: string): Promise<MediaTypeModel[]> {
console.log(`MDB | api "${this.apiName}" queried by Title`);

Expand Down Expand Up @@ -75,7 +80,7 @@ export class BoardGameGeekAPI extends APIModel {
const boardgame = response.querySelector('boardgame')!;
const title = boardgame.querySelector('name[primary=true]')!.textContent!;
const year = boardgame.querySelector('yearpublished')?.textContent ?? '';
const image = boardgame.querySelector('image')?.textContent ?? undefined;
const image = this.processImageLink(boardgame);
const onlineRating = Number.parseFloat(boardgame.querySelector('statistics ratings average')?.textContent ?? '0');
const genres = Array.from(boardgame.querySelectorAll('boardgamecategory')).map(n => n!.textContent!);
const complexityRating = Number.parseFloat(boardgame.querySelector('averageweight')?.textContent ?? '0');
Expand Down
9 changes: 5 additions & 4 deletions src/api/apis/MALAPI.ts
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reupload the files but the actual changes are on lines

MALAPI: 119, 153, 184

Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ export class MALAPI extends APIModel {
url: result.url,
id: result.mal_id,

plot: result.synopsis,
plot: result.synopsis ? result.synopsis.replace('[Written by MAL Rewrite]', '').trim() : '',
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and line 177 isnt need on the MALAPI.ts, this is suppose to remove the end comment return from pulling plot synopsis. No all of them had it and this was something i personally add on my end, that ened up getting pushed to PR, this doesnt need to be added.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems useful to keep

genres: result.genres?.map((x: any) => x.name) ?? [],
director: [],
writer: [],
studio: result.studios?.map((x: any) => x.name).join(', ') ?? 'unknown',
duration: result.duration ?? 'unknown',
onlineRating: result.score ?? 0,
actors: [],
image: result.images?.jpg?.image_url ?? '',
image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '',

released: true,
premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown',
Expand Down Expand Up @@ -150,7 +150,7 @@ export class MALAPI extends APIModel {
duration: result.duration ?? 'unknown',
onlineRating: result.score ?? 0,
actors: [],
image: result.images?.jpg?.image_url ?? '',
image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '',

released: true,
premiere: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown',
Expand All @@ -174,14 +174,15 @@ export class MALAPI extends APIModel {
url: result.url,
id: result.mal_id,

plot: result.synopsis ? result.synopsis.replace('[Written by MAL Rewrite]', '').trim() : '',
genres: result.genres?.map((x: any) => x.name) ?? [],
writer: [],
studio: result.studios?.map((x: any) => x.name) ?? [],
episodes: result.episodes,
duration: result.duration ?? 'unknown',
onlineRating: result.score ?? 0,
streamingServices: result.streaming?.map((x: any) => x.name) ?? [],
image: result.images?.jpg?.image_url ?? '',
image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '',

released: true,
airedFrom: this.plugin.dateFormatter.format(result.aired?.from, this.apiDateFormat) ?? 'unknown',
Expand Down
4 changes: 2 additions & 2 deletions src/api/apis/MALAPIManga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class MALAPIManga extends APIModel {
chapters: result.chapters,
volumes: result.volumes,
onlineRating: result.score ?? 0,
image: result.images?.jpg?.image_url ?? '',
image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '',

released: true,
publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown',
Expand Down Expand Up @@ -111,7 +111,7 @@ export class MALAPIManga extends APIModel {
chapters: result.chapters,
volumes: result.volumes,
onlineRating: result.score ?? 0,
image: result.images?.jpg?.image_url ?? '',
image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.images?.jpg?.image_url})` ?? '' : result.images?.jpg?.image_url ?? '',

released: true,
publishedFrom: new Date(result.published?.from).toLocaleDateString() ?? 'unknown',
Expand Down
2 changes: 1 addition & 1 deletion src/api/apis/MobyGamesAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class MobyGamesAPI extends APIModel {
publishers: [],
genres: result.genres?.map((x: any) => x.genre_name) ?? [],
onlineRating: result.moby_score,
image: result.sample_cover.image ?? '',
image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.sample_cover.image ?? ''})` ?? '' : result.sample_cover.image ?? '',

released: true,
releaseDate: result.platforms[0].first_release_date ?? 'unknown',
Expand Down
8 changes: 6 additions & 2 deletions src/api/apis/MusicBrainzAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export class MusicBrainzAPI extends APIModel {
dataSource: this.apiName,
url: 'https://musicbrainz.org/release-group/' + result.id,
id: result.id,
image: 'https://coverartarchive.org/release-group/' + result.id + '/front',
image: this.plugin.settings.generateEmbedLinksForImages
? `![](${'https://coverartarchive.org/release-group/' + result.id + '/front'})`
: 'https://coverartarchive.org/release-group/' + result.id + '/front',

artists: result['artist-credit'].map((a: any) => a.name),
subType: result['primary-type'],
Expand Down Expand Up @@ -89,7 +91,9 @@ export class MusicBrainzAPI extends APIModel {
dataSource: this.apiName,
url: 'https://musicbrainz.org/release-group/' + result.id,
id: result.id,
image: 'https://coverartarchive.org/release-group/' + result.id + '/front',
image: this.plugin.settings.generateEmbedLinksForImages
? `![](${'https://coverartarchive.org/release-group/' + result.id + '/front'})`
: 'https://coverartarchive.org/release-group/' + result.id + '/front',

artists: result['artist-credit'].map((a: any) => a.name),
genres: result.genres.map((g: any) => g.name),
Expand Down
6 changes: 3 additions & 3 deletions src/api/apis/OMDbAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class OMDbAPI extends APIModel {
duration: result.Runtime ?? 'unknown',
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
actors: result.Actors?.split(', ') ?? [],
image: result.Poster ?? '',
image: this.plugin.settings.generateEmbedLinksForImages ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '',

released: true,
streamingServices: [],
Expand Down Expand Up @@ -174,7 +174,7 @@ export class OMDbAPI extends APIModel {
duration: result.Runtime ?? 'unknown',
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
actors: result.Actors?.split(', ') ?? [],
image: result.Poster ?? '',
image: this.plugin.settings.generateEmbedLinksForImages ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '',

released: true,
streamingServices: [],
Expand Down Expand Up @@ -204,7 +204,7 @@ export class OMDbAPI extends APIModel {
publishers: [],
genres: result.Genre?.split(', ') ?? [],
onlineRating: Number.parseFloat(result.imdbRating ?? 0),
image: result.Poster ?? '',
image: this.plugin.settings.generateEmbedLinksForImages ? (result.Poster ? `![](${result.Poster})` : '') : result.Poster ? result.Poster : '',

released: true,
releaseDate: this.plugin.dateFormatter.format(result.Released, this.apiDateFormat) ?? 'unknown',
Expand Down
4 changes: 3 additions & 1 deletion src/api/apis/OpenLibraryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export class OpenLibraryAPI extends APIModel {
plot: result.description ?? 'unknown',
pages: result.number_of_pages_median ?? 'unknown',
onlineRating: Number.parseFloat(Number(result.ratings_average ?? 0).toFixed(2)),
image: `https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg`,
image: this.plugin.settings.generateEmbedLinksForImages
? `![](${`https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg`}`
: `https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg`,

released: true,

Expand Down
2 changes: 1 addition & 1 deletion src/api/apis/SteamAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class SteamAPI extends APIModel {
publishers: result['publishers'],
genres: result.genres?.map((x: any) => x.description) ?? [],
onlineRating: Number.parseFloat(result.metacritic?.score ?? 0),
image: result.header_image ?? '',
image: this.plugin.settings.generateEmbedLinksForImages ? `![](${result.header_image ?? ''})` : result.header_image ?? '',

released: !result.release_date?.comming_soon,
releaseDate: this.plugin.dateFormatter.format(result.release_date?.date, this.apiDateFormat) ?? 'unknown',
Expand Down
11 changes: 11 additions & 0 deletions src/settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface MediaDbPluginSettings {
openNoteInNewTab: boolean;
useDefaultFrontMatter: boolean;
enableTemplaterIntegration: boolean;
generateEmbedLinksForImages: boolean;
apiToggle: {
OMDbAPI: {
movie: boolean;
Expand Down Expand Up @@ -83,6 +84,7 @@ const DEFAULT_SETTINGS: MediaDbPluginSettings = {
openNoteInNewTab: true,
useDefaultFrontMatter: true,
enableTemplaterIntegration: false,
generateEmbedLinksForImages: false,
apiToggle: {
OMDbAPI: {
movie: true,
Expand Down Expand Up @@ -279,6 +281,15 @@ export class MediaDbSettingTab extends PluginSettingTab {
void this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Embed image links in YAML')
.setDesc('Save image links as markdown embeds in the frontmatter, for easier handling with e.g. Dataview.')
.addToggle(cb => {
cb.setValue(this.plugin.settings.generateEmbedLinksForImages).onChange(data => {
this.plugin.settings.generateEmbedLinksForImages = data;
void this.plugin.saveSettings();
});
});

containerEl.createEl('h3', { text: 'APIs Per Media Type' });
containerEl.createEl('h5', { text: 'Movies' });
Expand Down