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

Version 0.20.0 #190

Merged
merged 14 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Feature] 191 Auto Detect Digital Audio Quality (#192)
* Convert to TS

* Auto detect digital release audio quality

* Update changelog
  • Loading branch information
Serhii-DV authored Feb 16, 2025
commit 8eb1d44a4b4dfe81ed020e5eb6a49232e32ce694
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- discogs/popup: Detect multiple artists in the title if they are
- discogs: Improved search for Draft release in popup
- bandcamp: Auto-detection of the digital release audio quality

## 0.19.0 (2025-01-28)

Expand Down
11 changes: 8 additions & 3 deletions src/app/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class Release {
image: string;
keywords: string[];
credit: string;
quality: string;

constructor(
artist: string,
Expand All @@ -23,7 +24,8 @@ export class Release {
url: string,
image: string,
keywords: string[],
credit: string
credit: string,
quality: string = ''
) {
this.releaseItem = new ReleaseItem(url, artist, title);
this.label = label;
Expand All @@ -34,6 +36,7 @@ export class Release {
this.image = image;
this.keywords = keywords;
this.credit = credit;
this.quality = quality;
}

get artist(): ReleaseArtist {
Expand Down Expand Up @@ -79,7 +82,8 @@ export class Release {
tracks: this.tracks.map((track) => track.toStorageObject()),
image: this.image,
keywords: this.keywords,
credit: this.credit
credit: this.credit,
quality: this.quality
};
}

Expand Down Expand Up @@ -110,7 +114,8 @@ export class Release {
obj.url,
obj.image,
obj.keywords,
obj.credit ?? ''
obj.credit ?? '',
obj.quality ?? ''
);
}
}
64 changes: 0 additions & 64 deletions src/bandcamp/modules/html.js

This file was deleted.

84 changes: 84 additions & 0 deletions src/bandcamp/modules/html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { ReleaseItem } from '../../app/releaseItem';
import { element, getDataAttribute } from '../../utils/html';
import {
removeInvisibleChars,
trimCharactersFromString
} from '../../utils/utils';

export function getMusicAlbumSchemaData(): any {
const jsonLdScript = document.querySelector(
'script[type="application/ld+json"]'
);
return jsonLdScript ? JSON.parse(jsonLdScript.textContent || '') : null;
}

function createReleaseItemFromMusicGridElement(element: Element): ReleaseItem {
let artist = (element.querySelector('.artist-override') as HTMLElement)
?.innerText;

if (!artist) {
artist = (
document.querySelector('#band-name-location .title') as HTMLElement
).innerText;
}

artist = trimCharactersFromString(artist, ' -\n');
artist = removeInvisibleChars(artist);

const titleParts = (
element.querySelector('.title') as HTMLElement
).innerText.split('\n');
const title = removeInvisibleChars(titleParts[0]);
const url =
(element.querySelector('a') as HTMLAnchorElement).getAttribute('href') ||
'';
const itemId = parseInt(getDataAttribute(element, 'item-id'));

return new ReleaseItem(
(url[0] === '/' ? window.location.origin : '') + url,
artist,
title,
itemId
);
}

export function getReleaseItems(): ReleaseItem[] {
const releaseItems: ReleaseItem[] = [];
const releaseElements = document.querySelectorAll(
'#music-grid .music-grid-item'
);

releaseElements.forEach((element) => {
const releaseItem = createReleaseItemFromMusicGridElement(element);
releaseItems.push(releaseItem);
});

return releaseItems;
}

export function getBandPhotoSrc(): string | undefined {
const bandPhoto = document.querySelector('.band-photo') as HTMLImageElement;
return bandPhoto ? bandPhoto.src : undefined;
}

export function extractBCSearchInputStyle(): CSSStyleDeclaration | null {
const bcSearchInputElement = document.querySelector(
'input.search-bar'
) as HTMLInputElement;
return bcSearchInputElement
? window.getComputedStyle(bcSearchInputElement)
: null;
}

export function getDigitalAudioQuality(): string {
return (
extractAudioQuality(element('.digital .audio-quality')?.innerText ?? '') ??
''
);
}

function extractAudioQuality(input: string): string | null {
const match = input.match(/(\d+-bit\/\d+(?:\.\d+)?kHz)/);

return match ? match[1] : null;
}
6 changes: 5 additions & 1 deletion src/bandcamp/pages/page-album.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { logInfo } from '../../utils/console';
import { getMusicAlbumSchemaData } from '../modules/html.js';
import {
getDigitalAudioQuality,
getMusicAlbumSchemaData
} from '../modules/html';
import { createReleaseFromSchema } from '../../utils/schema';
import { chromeListenToMessage } from '../../utils/chrome';
import { Storage } from '../../app/core/storage';
Expand All @@ -12,6 +15,7 @@ export function setupPageAlbum(pageType) {
logInfo('Setup page album');
const schema = getMusicAlbumSchemaData();
const release = createReleaseFromSchema(schema);
release.quality = getDigitalAudioQuality();
storage.save(release);

chromeListenToMessage((message, sender, sendResponse) => {
Expand Down
2 changes: 1 addition & 1 deletion src/bandcamp/pages/page-music.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
extractBCSearchInputStyle,
getBandPhotoSrc,
getReleaseItems as getReleaseItemsFromPage
} from '../modules/html.js';
} from '../modules/html';
import { log } from '../../utils/console';
import { chromeListenToMessage } from '../../utils/chrome';
import { Music } from '../../app/music';
Expand Down
9 changes: 3 additions & 6 deletions src/discogs/app/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface MetadataParams {
trackQty: number;
formatFileType: string;
formatDescription: string;
freeText: string;
country?: string;
released: Released;
tracklist: string;
Expand Down Expand Up @@ -122,12 +123,7 @@ export class Metadata {
]),
qty: convertMetadataValue(params.trackQty.toString()),
description: convertMetadataValue(params.formatDescription),
freeText: convertMetadataValue([
'24-bit/44.1kHz',
'16-bit/44.1kHz',
'320 kbps',
'128 kbps'
])
freeText: convertMetadataValue([params.freeText, '320 kbps', '128 kbps'])
};
this.country = convertMetadataValue([
params.country ?? config.metadata.country,
Expand Down Expand Up @@ -161,6 +157,7 @@ export class Metadata {
trackQty: release.tracksQty,
formatFileType: 'FLAC',
formatDescription: 'Album',
freeText: release.quality,
genres: {
keywords: release.keywords,
autoDetectedGenres: discogsGenres,
Expand Down