-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(caa upload): add Musik-Sammler provider
- Loading branch information
Showing
6 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/mb_enhanced_cover_art_uploads/providers/musik_sammler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { assertNonNull } from '@lib/util/assert'; | ||
import { parseDOM, qsa } from '@lib/util/dom'; | ||
|
||
import type { CoverArt } from './base'; | ||
import { CoverArtProvider } from './base'; | ||
|
||
export class MusikSammlerProvider extends CoverArtProvider { | ||
supportedDomains = ['musik-sammler.de']; | ||
name = 'Musik-Sammler'; | ||
favicon = 'https://www.musik-sammler.de/favicon.ico'; | ||
urlRegex = /release\/(?:.*-)?(\d+)(?:\/|$)/; | ||
|
||
async findImages(url: URL): Promise<CoverArt[]> { | ||
const page = parseDOM(await this.fetchPage(url), url.href); | ||
const coverElements = qsa('#imageGallery > li', page); | ||
return coverElements.map((coverLi) => { | ||
const coverSrc = coverLi.getAttribute('data-src'); | ||
assertNonNull(coverSrc, 'Musik-Sammler image without source?'); | ||
return { | ||
url: new URL(coverSrc, 'https://www.musik-sammler.de/'), | ||
}; | ||
}); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
tests/mb_enhanced_cover_art_uploads/providers/musik_sammler.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { MusikSammlerProvider } from '@src/mb_enhanced_cover_art_uploads/providers/musik_sammler'; | ||
|
||
import { itBehavesLike } from '@test-utils/shared_behaviour'; | ||
|
||
import { urlMatchingSpec } from './url_matching_spec'; | ||
import { findImagesSpec } from './find_images_spec'; | ||
|
||
describe('musik-sammler provider', () => { | ||
const provider = new MusikSammlerProvider(); | ||
|
||
describe('url matching', () => { | ||
const supportedUrls = [{ | ||
desc: 'release URLs', | ||
url: 'https://www.musik-sammler.de/release/vanilla-fudge-vanilla-fudge-cd-1539691/', | ||
id: '1539691', | ||
}, { | ||
desc: 'short release URLs', | ||
url: 'https://www.musik-sammler.de/release/1539691/', | ||
id: '1539691', | ||
}]; | ||
|
||
const unsupportedUrls = [{ | ||
desc: 'album URLs', | ||
url: 'https://www.musik-sammler.de/album/vanilla-fudge-vanilla-fudge-995842/', | ||
}, { | ||
desc: 'artist URLs', | ||
url: 'https://www.musik-sammler.de/artist/vanilla-fudge/', | ||
}]; | ||
|
||
// eslint-disable-next-line jest/require-hook | ||
itBehavesLike(urlMatchingSpec, { provider, supportedUrls, unsupportedUrls }); | ||
}); | ||
|
||
describe('extracting images', () => { | ||
const extractionCases = [{ | ||
desc: 'release', | ||
url: 'https://www.musik-sammler.de/release/vanilla-fudge-vanilla-fudge-cd-1539691/', | ||
numImages: 3, | ||
expectedImages: [{ | ||
index: 0, | ||
urlPart: '1539691_1635313476.jpg', | ||
}, { | ||
index: 1, | ||
urlPart: '1539691_1_1635313476.jpg', | ||
}, { | ||
index: 2, | ||
urlPart: '1539691_2_1635313476.jpg', | ||
}], | ||
}]; | ||
|
||
const extractionFailedCases = [{ | ||
desc: 'non-existent release', | ||
url: 'https://www.musik-sammler.de/release/vanilla-fudge-vanilla-fudge-cd-1539/', | ||
}]; | ||
|
||
// eslint-disable-next-line jest/require-hook | ||
itBehavesLike(findImagesSpec, { provider, extractionCases, extractionFailedCases }); | ||
}); | ||
}); |
100 changes: 100 additions & 0 deletions
100
...3330389/extracting-images_1310741912/extracts-covers-for-release_2308446907/recording.har
Large diffs are not rendered by default.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
...0389/extracting-images_1310741912/throws-on-non-existent-release_1189313548/recording.har
Large diffs are not rendered by default.
Oops, something went wrong.