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

New translator: FNAC books, movies, music and videogames #3378

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cesar-lizurey
Copy link

A FNAC translator was missing.
I used FNAC books a lot during my studies, so I thought it would be nice to offer what I coded for other people struggling with references on this website.
For non French people: it's more or less like Amazon online, although it's a physical store in the first place.

@cesar-lizurey cesar-lizurey changed the title FNAC books, movies, music and videogames New translator: FNAC books, movies, music and videogames Oct 27, 2024
FNAC.js Outdated
"translatorID": "825f208c-eb96-4372-9d21-b879c3a910bb",
"label": "FNAC",
"creator": "César Lizurey",
"target": "^https?://(www\\.)?fnac\\.com",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"target": "^https?://(www\\.)?fnac\\.com",
"target": "^https?://(www\\.)?fnac\\.com/",

Copy link
Author

Choose a reason for hiding this comment

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

Done :)

FNAC.js Outdated
var match = url.match(/^https:\/\/www\.fnac\.com\/a(\d+)\/([\w-]+)$/);

if (match) {
Z.debug("URL OK");
Copy link
Member

Choose a reason for hiding this comment

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

Remove

Copy link
Author

Choose a reason for hiding this comment

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

Done :)

FNAC.js Outdated

function detectWeb(doc, url) {
// Check if the URL matches the desired format
var match = url.match(/^https:\/\/www\.fnac\.com\/a(\d+)\/([\w-]+)$/);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var match = url.match(/^https:\/\/www\.fnac\.com\/a(\d+)\/([\w-]+)$/);
var match = new URL(url).pathname.match(/^\/a(\d+)\/([\w-]+)$/);

Copy link
Author

Choose a reason for hiding this comment

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

Done :)

FNAC.js Outdated
// Get the second <a> element in the breadcrumb to check the itemType
var secondLink = doc.querySelector('nav.f-breadcrumb > ul.f-breadcrumb__list > li:nth-of-type(2)');
if (secondLink) {
Z.debug("Breadcrumb OK");
Copy link
Member

Choose a reason for hiding this comment

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

Remove

Copy link
Author

Choose a reason for hiding this comment

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

Done :)

Z.debug("URL OK");

// Get the second <a> element in the breadcrumb to check the itemType
var secondLink = doc.querySelector('nav.f-breadcrumb > ul.f-breadcrumb__list > li:nth-of-type(2)');
Copy link
Member

Choose a reason for hiding this comment

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

This seems way too likely to change - how about nav > ul > :nth-child(2)? Still not great, but the less reliance we have on presentation class names, the better.

Copy link
Author

Choose a reason for hiding this comment

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

This seems way too likely to change - how about nav > ul > :nth-child(2)? Still not great, but the less reliance we have on presentation class names, the better.

Actually I wanted to prevent bugs in case of a the apparition of a new "nav" element in the page. The 2 classes have been very consistent for a long time.

item.company = value.textContent.trim();
}
else {
item.publisher = value.textContent.trim();
Copy link
Member

Choose a reason for hiding this comment

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

item.publisher should map to label/company without needing an explicit check.

Copy link
Author

Choose a reason for hiding this comment

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

I don't understand, could you elaborate, please?

}
case 'EAN': {
// Extract the EAN as ISBN if ISBN is empty
item.ISBN = item.ISBN || value.textContent.trim();
Copy link
Member

Choose a reason for hiding this comment

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

But EANs aren't ISBNs as far as I know, so we wouldn't want them in the ISBN field

Copy link
Author

Choose a reason for hiding this comment

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

But EANs aren't ISBNs as far as I know, so we wouldn't want them in the ISBN field

You're right but I didn't see any "EAN" field in Zotero object. Have I missed something?
Considering both are related, I assumed it was more important to get EAN in the ISBN field, but I'm open to any suggestion.

FNAC.js Outdated
}
case 'Nombre de pages': {
// Extract the number of pages
item.numPages = +value.textContent.trim();
Copy link
Member

Choose a reason for hiding this comment

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

Don't convert to number (+) - no point and will just lead to NaN in the field in weird cases.

Copy link
Author

Choose a reason for hiding this comment

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

I added a verification.

FNAC.js Outdated

item.attachments = [
{
title: "Fnac.com Link",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
title: "Fnac.com Link",
title: "Catalog Page",

Copy link
Author

Choose a reason for hiding this comment

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

Done :)

FNAC.js Outdated
Comment on lines 101 to 107
for (var j = 0; j < authorElements.length; j++) {
creators.push({
firstName: authorElements[j].textContent.trim(),
lastName: "",
creatorType: "author"
});
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for (var j = 0; j < authorElements.length; j++) {
creators.push({
firstName: authorElements[j].textContent.trim(),
lastName: "",
creatorType: "author"
});
}
for (let authorElement of authorElements) {
creators.push(ZU.cleanAuthor(authorElement.textContent, 'author'));
}

Copy link
Author

Choose a reason for hiding this comment

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

Done :)

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.

3 participants