Skip to content

Commit

Permalink
Merge pull request #190 from Serhii-DV/dev
Browse files Browse the repository at this point in the history
Version 0.20.0
  • Loading branch information
Serhii-DV authored Feb 23, 2025
2 parents 0040592 + 8e478c5 commit e657963
Show file tree
Hide file tree
Showing 23 changed files with 517 additions and 286 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change log

## 0.20.0 (2025-02-xx)

### Features

- 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

### Fixed

- bandcamp: Fixed the issue with the artist/album filtering on the artist page

## 0.19.0 (2025-01-28)

### Features
Expand Down
211 changes: 103 additions & 108 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"version": "0.19.0",
"version": "0.20.0",
"devDependencies": {
"@github/relative-time-element": "^4.4.4",
"@swc/html": "^1.10.11",
"@types/chrome": "^0.0.299",
"@github/relative-time-element": "^4.4.5",
"@swc/html": "^1.10.16",
"@types/chrome": "^0.0.304",
"@types/isotope-layout": "^3.0.13",
"@types/mustache": "^4.2.5",
"@types/uuid": "^10.0.0",
Expand All @@ -12,7 +12,7 @@
"copy-webpack-plugin": "^12.0.2",
"css-loader": "^7.1.2",
"css-minimizer-webpack-plugin": "^7.0.0",
"eslint": "^9.17.0",
"eslint": "^9.20.1",
"eslint-webpack-plugin": "^4.2.0",
"html-loader": "^5.1.0",
"html-minimizer-webpack-plugin": "^5.0.0",
Expand All @@ -21,13 +21,13 @@
"json-minimizer-webpack-plugin": "^5.0.0",
"mini-css-extract-plugin": "^2.9.2",
"mustache": "^4.2.0",
"prettier": "^3.4.2",
"prettier": "^3.5.1",
"source-map-loader": "^5.0.0",
"terser-webpack-plugin": "^5.3.11",
"ts-loader": "^9.5.2",
"typescript": "^5.7.3",
"uuid": "^11.0.5",
"webpack": "^5.97.1",
"webpack": "^5.98.0",
"webpack-cli": "^6.0.1",
"webpack-dev-server": "^5.2.0",
"webpack-merge": "^6.0.1"
Expand Down
5 changes: 3 additions & 2 deletions src/app/core/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Uuid,
UuidMap
} from 'src/types';
import { log } from '../../utils/console';
import { log, logError } from '../../utils/console';
import { Release } from '../release';
import { Music } from '../music';
import { hasOwnProperty, isObject } from '../../utils/utils';
Expand Down Expand Up @@ -163,13 +163,14 @@ export class Storage {

const obj = storageDataMap[key];

log('[Storage]', obj);
try {
uuidMap[key] = Release.fromStorageObject(obj);
} catch (error) {
try {
uuidMap[key] = Music.fromObject(obj);
} catch (error) {
log('[Storage] Broken storage object.', JSON.stringify(error), obj);
logError('[Storage] Broken storage object.', error);
}
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/app/release.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ReleaseArtist } from './releaseArtist';
import { ReleaseItem } from './releaseItem';
import { Track } from './track';

Expand All @@ -11,6 +12,7 @@ export class Release {
image: string;
keywords: string[];
credit: string;
quality: string;

constructor(
artist: string,
Expand All @@ -22,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 @@ -33,9 +36,10 @@ export class Release {
this.image = image;
this.keywords = keywords;
this.credit = credit;
this.quality = quality;
}

get artist(): string {
get artist(): ReleaseArtist {
return this.releaseItem.artist;
}

Expand Down Expand Up @@ -69,7 +73,7 @@ export class Release {

toStorageObject(): object {
return {
artist: this.releaseItem.artist,
artist: this.releaseItem.artist.toString(),
title: this.releaseItem.title,
url: this.releaseItem.url.toString(),
label: this.label,
Expand All @@ -78,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 @@ -109,7 +114,8 @@ export class Release {
obj.url,
obj.image,
obj.keywords,
obj.credit ?? ''
obj.credit ?? '',
obj.quality ?? ''
);
}
}
42 changes: 42 additions & 0 deletions src/app/releaseArtist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { containsOneOf, splitString } from '../utils/utils';

export class ReleaseArtist {
public names: string[];
public joins: string[];
private artist?: string = undefined;

constructor(names: string[], joins: string[] = []) {
this.names = names;
this.joins = joins.map((join) => join.trim());
}

get asString(): string {
return this.toString();
}

get asArray(): string[] {
const result: string[] = [];
for (let i = 0; i < this.names.length; i++) {
result.push(this.names[i]);
if (i < this.joins.length) {
result.push(this.joins[i]);
}
}
return result;
}

static fromString(input: string): ReleaseArtist {
const useOriginal = containsOneOf(input, ['V/A']);
const names: string[] = useOriginal
? [input]
: splitString(input, /[,\/+|]| Vs | & +/);
const joins: string[] = useOriginal
? []
: (input.match(/[,\/+|]| Vs | & +/g) || []).map((join) => join.trim());
return new ReleaseArtist(names, joins);
}

toString(): string {
return this.artist ?? (this.artist = this.asArray.join(' '));
}
}
11 changes: 8 additions & 3 deletions src/app/releaseItem.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { IReleaseItem, StorageData } from 'src/types';
import { BandcampItem } from './bandcampItem';
import { ReleaseArtist } from './releaseArtist';

export class ReleaseItem extends BandcampItem {
public artist: string;
public artist: ReleaseArtist;
public title: string;
public label: string;

Expand All @@ -15,16 +16,20 @@ export class ReleaseItem extends BandcampItem {
visit?: Date
) {
super(url, undefined, visit, id);
this.artist = artist;
this.artist = ReleaseArtist.fromString(artist);
this.title = title;
this.label = label;
}

get artists(): string[] {
return this.artist.names;
}

toStorageData(): StorageData {
const self = this;
return {
url: self.url.toString(),
artist: self.artist,
artist: self.artist.toString(),
title: self.title,
label: self.label,
image: self.image,
Expand Down
64 changes: 0 additions & 64 deletions src/bandcamp/modules/html.js

This file was deleted.

86 changes: 86 additions & 0 deletions src/bandcamp/modules/html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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').replace('album-', '')
);

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
Loading

0 comments on commit e657963

Please sign in to comment.