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

feat(caa dims): add support for new event art archive (EAA) #778

Closed
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions mb_caa_dimensions.changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- **2024.7.21**: New feature: add support for new event art archive (EAA) [vzell request](https://community.metabrainz.org/t/ropdebees-userscripts-support-thread/551947/182)
- **2024.6.10**: Bug fix: compatibility with new beta.MBS ([#770](https://github.com/ROpdebee/mb-userscripts/pull/770))
- **2023.12.3**: Internal changes: update minimum required versions of browsers ([#719](https://github.com/ROpdebee/mb-userscripts/pull/719))
- **2023.6.9**: Internal changes: use unified request interface ([#672](https://github.com/ROpdebee/mb-userscripts/pull/672))
Expand Down
4 changes: 3 additions & 1 deletion mb_caa_dimensions.meta.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// ==UserScript==
// @name MB: Display CAA image dimensions
// @description Displays the dimensions and size of images in the cover art archive.
// @version 2024.6.10
// @version 2024.7.21
// @author ROpdebee
// @license MIT; https://opensource.org/licenses/MIT
// @namespace https://github.com/ROpdebee/mb-userscripts
// @homepageURL https://github.com/ROpdebee/mb-userscripts
// @supportURL https://github.com/ROpdebee/mb-userscripts/issues
// @downloadURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_caa_dimensions.user.js
// @updateURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_caa_dimensions.meta.js
// @match *://*.musicbrainz.org/event/*
// @match *://*.musicbrainz.org/release/*
// @match *://*.musicbrainz.org/release-group/*
// @match *://*.musicbrainz.org/edit/*
// @match *://*.musicbrainz.org/*/edits*
// @match *://*.musicbrainz.org/user/*/votes
// @match *://*.musicbrainz.org/*/open_edits
// @exclude *://*.musicbrainz.org/event/*/edit
// @exclude *://*.musicbrainz.org/release/*/edit
// @exclude *://*.musicbrainz.org/release/*/edit-relationships
// @exclude *://*.musicbrainz.org/release-group/*/edit
Expand Down
2 changes: 1 addition & 1 deletion mb_caa_dimensions.metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"2024.6.10"}
{"version":"2024.7.21"}
12 changes: 7 additions & 5 deletions mb_caa_dimensions.user.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// ==UserScript==
// @name MB: Display CAA image dimensions
// @description Displays the dimensions and size of images in the cover art archive.
// @version 2024.6.10
// @version 2024.7.21
// @author ROpdebee
// @license MIT; https://opensource.org/licenses/MIT
// @namespace https://github.com/ROpdebee/mb-userscripts
// @homepageURL https://github.com/ROpdebee/mb-userscripts
// @supportURL https://github.com/ROpdebee/mb-userscripts/issues
// @downloadURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_caa_dimensions.user.js
// @updateURL https://raw.github.com/ROpdebee/mb-userscripts/dist/mb_caa_dimensions.meta.js
// @match *://*.musicbrainz.org/event/*
// @match *://*.musicbrainz.org/release/*
// @match *://*.musicbrainz.org/release-group/*
// @match *://*.musicbrainz.org/edit/*
// @match *://*.musicbrainz.org/*/edits*
// @match *://*.musicbrainz.org/user/*/votes
// @match *://*.musicbrainz.org/*/open_edits
// @exclude *://*.musicbrainz.org/event/*/edit
// @exclude *://*.musicbrainz.org/release/*/edit
// @exclude *://*.musicbrainz.org/release/*/edit-relationships
// @exclude *://*.musicbrainz.org/release-group/*/edit
Expand Down Expand Up @@ -111,7 +113,7 @@
}));

const CAA_ID_REGEX = /(mbid-[a-f\d-]{36})\/mbid-[a-f\d-]{36}-(\d+)/;
const CAA_DOMAIN = 'coverartarchive.org';
const AA_DOMAINS = /^(cover|event)artarchive\.org$/;
class BaseImage {
constructor(imageUrl, cache, cacheKey) {
_defineProperty(this, "imageUrl", void 0);
Expand Down Expand Up @@ -174,15 +176,15 @@
}
}
function caaUrlToDirectUrl(urlObject) {
if (urlObject.host === CAA_DOMAIN && urlObject.pathname.startsWith('/release/')) {
if (urlObject.host.match(AA_DOMAINS) && urlObject.pathname.match(/^\/(event|release)\//)) {
const [releaseId, imageName] = urlObject.pathname.split('/').slice(2);
urlObject.href = `https://archive.org/download/mbid-${releaseId}/mbid-${releaseId}-${imageName}`;
}
return urlObject;
}
function urlToCacheKey(fullSizeUrl, thumbnailUrl) {
const urlObject = new URL(fullSizeUrl);
if (urlObject.host === CAA_DOMAIN && urlObject.pathname.startsWith('/release-group/')) {
if (urlObject.host.match(AA_DOMAINS) && urlObject.pathname.startsWith('/release-group/')) {
assertDefined(thumbnailUrl, 'Release group image requires a thumbnail URL');
return thumbnailUrl;
}
Expand All @@ -201,7 +203,7 @@
}
function parseCAAIDs(url) {
const urlObject = new URL(url);
if (urlObject.host === CAA_DOMAIN && urlObject.pathname.startsWith('/release/')) {
if (urlObject.host.match(AA_DOMAINS) && urlObject.pathname.match(/^\/(event|release)\//)) {
var _thumbName$match;
const [releaseId, thumbName] = urlObject.pathname.split('/').slice(2);
const imageId = (_thumbName$match = thumbName.match(/^(\d+)/)) === null || _thumbName$match === void 0 ? void 0 : _thumbName$match[0];
Expand Down