Struggling with Discogs translator code

52 views
Skip to first unread message

Michael Freeman

unread,
May 21, 2025, 11:45:50 PMMay 21
to zotero-dev
Hi,

I found Tools --> Developer -- Translator Editor (Scaffold).

However the following code never runs. Using the following link ...

https://www.discogs.com/release/1160181-The-Lady-Of-Rage-Afro-Puffs

... Artist name and track title always end up together in Title. Chrome connector shows generic Metadata translator is running not the Discogs one.

Should I be basing this on the provided Plus Sign Icon --> Scrape Function Using --> Embedded Metadata ?

Code ...

{
"translatorID": "669bb7bd-bc34-46cd-9340-cf8af8187063",
"label": "Discogs",
"creator": "Michael Z Freeman",
"target": "^https?://(www\\.)?discogs\\.com/release(/\\d+)?",
"minVersion": "5.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2025-05-21 12:33:30"
}

function detectWeb(doc, url) {
if (url.includes("/release/")) {
return "audioRecording";
}
return false;
}

function doWeb(doc, url) {
const scriptTag = doc.querySelector('script[type="application/ld+json"]');
if (!scriptTag) return;

let data;
try {
data = JSON.parse(scriptTag.textContent);
} catch (e) {
Zotero.debug("JSON parse error: " + e.message);
return;
}

const item = new Zotero.Item("audioRecording");

item.title = data.name || "(Untitled)";

// Handle artist
if (data.byArtist && data.byArtist.name) {
item.creators.push({
lastName: data.byArtist.name,
creatorType: "performer",
fieldMode: 1
});
}

// Handle date
if (data.datePublished) {
item.date = data.datePublished;
}

// Label
if (data.recordLabel) {
const labels = Array.isArray(data.recordLabel) ? data.recordLabel : [data.recordLabel];
item.label = labels.map(l => l.name).filter(Boolean).join("; ");
}

// Genre
if (data.genre) {
item.genre = Array.isArray(data.genre) ? data.genre.join("; ") : data.genre;
}

// Medium
if (data.musicReleaseFormat) {
item.medium = data.musicReleaseFormat;
}

// Description
if (data.description) {
item.abstractNote = data.description;
}

// Extra
if (data.catalogNumber) {
item.extra = "Catalog Number: " + data.catalogNumber;
}

item.url = url;
item.libraryCatalog = "Discogs";

item.attachments.push({
title: "Discogs Snapshot",
document: doc
});

item.complete();
}

/** BEGIN TEST CASES **/
var testCases = [
]
/** END TEST CASES **/

Abe Jellinek

unread,
May 22, 2025, 11:29:04 AMMay 22
to zoter...@googlegroups.com
Hi Michael,

If that’s the whole contents of the file, it looks right (and runs on my end). But only the section between the top metadata block and the "BEGIN TEST CASES” comment should appear under the Code tab. Zotero manages the rest for you.

If you’re trying to edit in Scaffold and test in Chrome, make sure you click Scaffold’s “Save to Zotero” button, then in the Zotero Connector preferences, go to Advanced -> Reset Translators. I’ll update the documentation to make that more clear.

And there’s no real reason to base this translator on Embedded Metadata. Building the item from scratch seems fine. EM only gets a couple fields.

Best,
Abe

--
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/zotero-dev/92345ecd-90ea-4a71-9708-fb7b36a818cen%40googlegroups.com.

Michael Freeman

unread,
May 23, 2025, 2:16:51 AMMay 23
to zoter...@googlegroups.com

Abe Jellinek

unread,
May 23, 2025, 10:03:04 AMMay 23
to zoter...@googlegroups.com

Michael Freeman

unread,
May 23, 2025, 11:27:50 AMMay 23
to zoter...@googlegroups.com
Oh. Oops ! 

Thanks for the link. It appears to be working now; running lint check.

Michael Freeman

unread,
May 23, 2025, 11:30:17 AMMay 23
to zoter...@googlegroups.com

Michael Freeman

unread,
May 27, 2025, 6:37:44 AMMay 27
to zoter...@googlegroups.com
Hi,

I have resolved all the issues in the PR apart from testing.

How do I create a test ?

Scaffold says "Translator does not support import tests”.

Cheers

Reply all
Reply to author
Forward
0 new messages