Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(caa upload): split maximisation code
Browse files Browse the repository at this point in the history
Split maximisation code into two functions: A generic one using
ImageMaxURL, and one for exceptional providers, like Discogs.
This split will make it easier to handle Apple Music exceptions.
ROpdebee committed Oct 20, 2021

Verified

This commit was signed with the committer’s verified signature.
jasnell James M Snell
1 parent a75b5c9 commit 682d742
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/mb_enhanced_cover_art_uploads/maximise.ts
Original file line number Diff line number Diff line change
@@ -29,12 +29,15 @@ export interface MaximisedImage {
}

export async function* getMaximisedCandidates(smallurl: URL): AsyncIterableIterator<MaximisedImage> {
// Workaround maxurl discogs difficulties
if (smallurl.hostname === 'img.discogs.com') {
yield getMaximisedCandidatesDiscogs(smallurl);
return;
const exceptions = await maximiseExceptions(smallurl);
if (exceptions) {
yield* exceptions;
} else {
yield* maximiseGeneric(smallurl);
}
}

async function* maximiseGeneric(smallurl: URL): AsyncIterableIterator<MaximisedImage> {
const p = new Promise<maxurlResult[]>((resolve) => {
maxurl(smallurl.href, {
...options,
@@ -58,12 +61,21 @@ export async function* getMaximisedCandidates(smallurl: URL): AsyncIterableItera
}
}

async function getMaximisedCandidatesDiscogs(smallurl: URL): Promise<MaximisedImage> {
async function maximiseExceptions(smallurl: URL): Promise<MaximisedImage[] | undefined> {
// Various workarounds for certain image providers
if (smallurl.hostname === 'img.discogs.com') {
return maximiseDiscogs(smallurl);
}

return;
}

async function maximiseDiscogs(smallurl: URL): Promise<MaximisedImage[]> {
// Workaround for maxurl returning broken links and webp images
const fullSizeURL = await DiscogsProvider.maximiseImage(smallurl);
return {
return [{
url: fullSizeURL,
filename: fullSizeURL.pathname.split('/').at(-1),
headers: {},
};
}];
}

0 comments on commit 682d742

Please sign in to comment.