-
Notifications
You must be signed in to change notification settings - Fork 769
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
base: master
Are you sure you want to change the base?
Conversation
FNAC.js
Outdated
"translatorID": "825f208c-eb96-4372-9d21-b879c3a910bb", | ||
"label": "FNAC", | ||
"creator": "César Lizurey", | ||
"target": "^https?://(www\\.)?fnac\\.com", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"target": "^https?://(www\\.)?fnac\\.com", | |
"target": "^https?://(www\\.)?fnac\\.com/", |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this comment.
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-]+)$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var match = url.match(/^https:\/\/www\.fnac\.com\/a(\d+)\/([\w-]+)$/); | |
var match = new URL(url).pathname.match(/^\/a(\d+)\/([\w-]+)$/); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this comment.
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)'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
title: "Fnac.com Link", | |
title: "Catalog Page", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
FNAC.js
Outdated
for (var j = 0; j < authorElements.length; j++) { | ||
creators.push({ | ||
firstName: authorElements[j].textContent.trim(), | ||
lastName: "", | ||
creatorType: "author" | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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')); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
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.