Skip to content

Add Discogs translator - #3451

Open
Michael-Z-Freeman wants to merge 5 commits into
zotero:masterfrom
Michael-Z-Freeman:Michael-Z-Freeman-Discogs-patch-1
Open

Add Discogs translator#3451
Michael-Z-Freeman wants to merge 5 commits into
zotero:masterfrom
Michael-Z-Freeman:Michael-Z-Freeman-Discogs-patch-1

Conversation

@Michael-Z-Freeman

@Michael-Z-Freeman Michael-Z-Freeman commented May 23, 2025

Copy link
Copy Markdown

A Zotero translator for Discogs, tested on a Discogs release.

Background

This translator was created to improve support for citing music releases and audio recordings, including physical formats such as vinyl, during BA(Hons) Creative Music Technology study at Falmouth University. Existing tools identified Discogs pages as audio recordings but did not reliably populate the relevant release metadata.

Method

The translator reads Discogs release-specific JSON-LD schema. It is intentionally limited to individual release pages, rather than master pages, because a release page supplies metadata such as the record label.

Changes in this update

  • Restricts detection to valid release URLs that contain the Discogs release schema, avoiding pages that cannot be imported as releases.
  • Supports localised Discogs release URLs.
  • Uses Zotero audioRecordingFormat and identifies Discogs as the library catalog.
  • Keeps the release cover image as an attachment.
  • Moves background documentation from the translator source into this PR description.

@AbeJellinek

Copy link
Copy Markdown
Member

Still working on getting CI working again; don't worry about the errors.

Comment thread Discogs.js Outdated
Comment thread Discogs.js Outdated
Comment thread Discogs.js Outdated
Comment thread Discogs.js Outdated
Comment thread Discogs.js

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new Zotero translator for Discogs (www.discogs.com) to enable proper citation of music releases and audio recordings. The translator extracts metadata from Discogs release pages using JSON-LD structured data and maps it to Zotero's audioRecording item type.

Key Changes:

  • New translator that parses JSON-LD data from Discogs release pages
  • Maps release metadata including title, artists, label, format, date, catalog number, and genres
  • Includes three test cases covering various vinyl release formats

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Discogs.js Outdated
Comment thread Discogs.js Outdated
Comment thread Discogs.js
Comment thread Discogs.js
Comment thread Discogs.js
Comment thread Discogs.js Outdated

@AbeJellinek AbeJellinek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, very close!

@Skelbti

Skelbti commented May 25, 2026

Copy link
Copy Markdown

I tested this translator on localised Discogs URLs (e.g. /fr/release/) and identified two bugs, plus added two new fields. Here is a corrected version of doWeb and the target field:

Fix 1target regex does not match localised URLs (/fr/release/, /de/release/, etc.), so the translator never fires for non-English Discogs interfaces:

"target": "^https://www\\.discogs\\.com(/[a-z]{2}(_[A-Z]{2})?)?/release/"

Fix 2ld+json selector should target #release_schema first, as Discogs now injects multiple ld+json blocks in the page header:

let jsonLdScript = doc.querySelector('script[type="application/ld+json"]#release_schema')
    || doc.querySelector('script[type="application/ld+json"]');

Addition 1 — country of release → place:

if (jsonLd.releasedEvent?.location?.name) {
    item.place = jsonLd.releasedEvent.location.name;
}

Addition 2 — release notes → extra (from DOM, HTML-stripped):

let notesEl = doc.querySelector('#release-notes .content_ETGfR [class^="notes_"]')
    || doc.querySelector('[class^="notes_"]');
if (notesEl) {
    let notesText = notesEl.innerHTML
        .replace(/<br\s*\/?>/gi, "\n")
        .replace(/<[^>]+>/g, "")
        .replace(/&quot;/g, '"').replace(/&amp;/g, "&")
        .replace(/\n{3,}/g, "\n\n").trim();
    if (notesText) item.extra = notesText;
}

Full corrected file available on request. Tested on Zotero 9.0.3 / macOS Tahoe.

@Michael-Z-Freeman

Copy link
Copy Markdown
Author

Full corrected file available on request. Tested on Zotero 9.0.3 / macOS Tahoe.

Did your changes get accepted ?

@Michael-Z-Freeman
Michael-Z-Freeman force-pushed the Michael-Z-Freeman-Discogs-patch-1 branch from 53288f7 to 09f47b5 Compare July 26, 2026 09:58
@Michael-Z-Freeman

Copy link
Copy Markdown
Author

@AbeJellinek The branch has been rebased onto current master and updated to address the requested changes:

  • detection is restricted to valid release URLs that contain the Discogs release schema, so non-importable pages are not matched;
  • the code has been linted successfully with npm run lint -- Discogs.js;
  • background/method documentation has been moved from the source into the PR description;
  • the translator now targets the release-specific JSON-LD schema, supports localised release URLs, uses audioRecordingFormat, and records Discogs as the catalog.

Could you please re-review when convenient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants