Skip to content

fix(Bandcamp): Fall back to raw release URL for custom domains #8

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

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
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
9 changes: 6 additions & 3 deletions providers/Bandcamp/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ export default class BandcampProvider extends MetadataProvider {
}

export class BandcampReleaseLookup extends ReleaseLookup<BandcampProvider, ReleasePage> {
rawReleaseUrl: URL | undefined;

constructReleaseApiUrl(): URL | undefined {
return undefined;
}
Expand All @@ -140,6 +142,7 @@ export class BandcampReleaseLookup extends ReleaseLookup<BandcampProvider, Relea
}

const webUrl = this.constructReleaseUrl(this.lookup.value, this.lookup);
this.rawReleaseUrl = webUrl;
const { content: release, timestamp } = await this.provider.extractEmbeddedJson<ReleasePage>(
webUrl,
this.options.snapshotMaxTimestamp,
Expand All @@ -153,10 +156,10 @@ export class BandcampReleaseLookup extends ReleaseLookup<BandcampProvider, Relea
const { tralbum: rawRelease } = albumPage;
const { current, packages } = rawRelease;

// Main release URL might use a custom domain, fallback to URL of first package.
// Main release URL might use a custom domain, fallback to the cached `rawReleaseUrl`.
let releaseUrl = new URL(rawRelease.url);
if (!releaseUrl.hostname.endsWith('bandcamp.com') && packages?.length) {
releaseUrl = new URL(packages[0].url);
if (!releaseUrl.hostname.endsWith('bandcamp.com')) {
releaseUrl = this.rawReleaseUrl!;
}

if (rawRelease.item_type === 'track' && rawRelease.album_url) {
Expand Down