-
Notifications
You must be signed in to change notification settings - Fork 102
foreign multiverse id #12
Comments
Thanks for the feature request, just not exactly sure how I want to handle foreign languages/multiverseids. I'll need to give it some more thought... |
I'm interested in this too, it would allow me to provide localized card images for cockatrice, which people have requested |
Also interested ! |
Hey there, I made a little script to get this. It's probably not perfect but it does the job. You need to have all gatherer pages in the cache directory. Run this to download them all : [..]/mtgjson/build/# for edition in $(ls -1 ../json/|cut -d'.' -f1) ; do node buildSet.js $edition ; done Then the script. You need to have npm modules "mhash", "jsdom" and "jquery". Also update the "dir" variable to fit your needs. var http = require("http");
var fs = require("fs");
var hash = require("mhash");
var env = require("jsdom").env;
if(process.argv.length < 3) {
console.log("Usage: node <script> <editionCode>");
process.exit(-1);
}
var editionCode = process.argv.pop();
var dir = "mtgjson";
var file = dir + "/json/" + editionCode + ".json";
if(!fs.existsSync(file)) {
console.log("File " + file + " not found");
process.exit(-2);
}
var dataRaw = fs.readFileSync(file);
var edition = JSON.parse(dataRaw);
var buildURL = function(multiverseid) {
return "http://gatherer.wizards.com/Pages/Card/Languages.aspx?multiverseid=" + multiverseid;
}
CardForeignMultiverseIdLooker = function(key) {
this.card = edition["cards"][key];
this.key = key;
this.url = buildURL(this.card["multiverseid"]);
this.hash = hash("whirlpool", this.url);
this.file = dir + "/cache/" + this.hash.charAt(0) + "/" + this.hash;
if(!fs.existsSync(this.file)) {
console.log("File " + this.file + " not found, please build the edition with mtgjson first");
process.exit(-3);
}
};
CardForeignMultiverseIdLooker.prototype.process = function() {
var ctx = this;
var html = fs.readFileSync(this.file).toString();
env(html, function(errors, window) {
var $ = require("jquery")(window);
$.each($(".cardItem"), function(k, v) {
var tds = $(v).find("td");
for(var k in ctx.card["foreignNames"]) {
if($(tds.get(1)).text().trim() == ctx.card["foreignNames"][k]["language"]) {
var mid = $(tds.get(0)).children("a").attr("href").split("=").pop()|0;
if(mid && mid > 0)
edition["cards"][ctx.key]["foreignNames"][k]["multiverseid"] = mid;
}
}
});
count++;
console.log("Done " + count + "/" + edition["cards"].length);
if(count == edition["cards"].length) {
fs.writeFileSync(file, JSON.stringify(edition));
}
});
};
var count = 0;
console.log("Processing edition " + edition["name"] + " (" + edition["code"] + ")");
for(var k in edition["cards"]) {
(function(k) { (new CardForeignMultiverseIdLooker(k)).process(); })(k);
} |
This is part of the larger feature of adding full foreign language support which is being tracked now in Inssue #40 |
I've decided to re-open this issue. It's possible I might just add the foreign multiverseid's, without adding all the foreign text as that part (Issue #40 ) would be a TON more work. |
This would be pretty trivial to do on my side. In fact I'm already parsing the pages that contain this information, I'm just throwing it away right now. I'd probably add a 'multiverseid' field to the 'foreignNames' field as that's wouldn't require introducing a new top level key. |
That sounds great! I hope this comes about so we can local parse images in foreign languages for cockatrice :) |
So I'll be making this change later today or tomorrow. I'll basically be adding a 'multiverseid' field to the 'foreignNames' field. In order to make this change, the 'foreignNames' field will now only be present for cards and sets that gatherer has foreign language information specifically for (since multiverseid's are set/card specific). This is a departure from how this field used to be handled, where I would copy the foreignName information from other sets whenever I could. I've never liked that I did this anyways, so :) Lastly, I'll also be removing the 'languagesPrinted' set field, since now the 'foreignNames' field on the cards directly reflect this and thus has the same information. |
Sounds good. Thanks for your continued support of the magic developing community!! |
Latest 3.0.0 version has this info. |
It seems to me that there's something strange on how this is represented for some cards. Let me explain, let's take for example the plains from the ORI-x file: there are 4 different cards named "Plains". Each one of them contains a "foreignNames" array that starts exactly like this:
and then goes on for the other languages. |
@ctrlaltca This is a bug that has been opened with Issue #70 |
Another issue right now is: Why is MultiverseId in ForeignNames a string while MultiverseId in the card object an Int?? I'm having issues parsing due to this undocumented bug. Should it need a separate Issue? |
@phrozen thanks for the heads up, thats a bug. Supposed to be an int like the other one. Just fixed it on the live site. |
I'm checking for collisions for another issue (one with the id) and I just found that actually something is wrong with the Schema itself. For example, I got a Swamp from the Tenth Edition, its the card number 372, has a variations field and the foreignNames i think should only be there once for each card number in the set, the one that corresponds to the art of the printing itself. If there are 4 Swamps in the translations, its because there are 4 Swamp card numbers in the card array (one for each translation), problem is how to know which one is which. |
it might be useful to include the multiverse id in the foreign names field. this would allow me to fetch images in different languages
The text was updated successfully, but these errors were encountered: