Skip to content
This repository has been archived by the owner on Dec 21, 2018. It is now read-only.

foreign multiverse id #12

Closed
aeosynth opened this issue Apr 24, 2014 · 17 comments
Closed

foreign multiverse id #12

aeosynth opened this issue Apr 24, 2014 · 17 comments

Comments

@aeosynth
Copy link

it might be useful to include the multiverse id in the foreign names field. this would allow me to fetch images in different languages

@Sembiance
Copy link
Contributor

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...

@Daenyth
Copy link

Daenyth commented Jul 3, 2014

I'm interested in this too, it would allow me to provide localized card images for cockatrice, which people have requested

@Lazarus974
Copy link

Also interested !

@Lazarus974
Copy link

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);
}

@Sembiance
Copy link
Contributor

This is part of the larger feature of adding full foreign language support which is being tracked now in Inssue #40

@Sembiance
Copy link
Contributor

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.

@Sembiance
Copy link
Contributor

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.

@ZeldaZach
Copy link
Member

That sounds great! I hope this comes about so we can local parse images in foreign languages for cockatrice :)

@Sembiance
Copy link
Contributor

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.

@ZeldaZach
Copy link
Member

Sounds good. Thanks for your continued support of the magic developing community!!

Sembiance added a commit that referenced this issue Aug 18, 2015
@Sembiance
Copy link
Contributor

Latest 3.0.0 version has this info.

@ctrlaltca
Copy link

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:

      "foreignNames": [
        {
          "language": "Chinese Traditional",
          "name": "平原",
          "multiverseid": "399229"
        },
        {
          "language": "Chinese Traditional",
          "name": "平原",
          "multiverseid": "399088"
        },
        {
          "language": "Chinese Traditional",
          "name": "平原",
          "multiverseid": "399095"
        },
        {
          "language": "Chinese Traditional",
          "name": "平原",
          "multiverseid": "399104"
        },

and then goes on for the other languages.
The issues i see here is that every different plain (1,2,3,4) contains an entry in the foreignNames array for itself and for the other cards with its same name.

@Sembiance
Copy link
Contributor

@ctrlaltca This is a bug that has been opened with Issue #70

@phrozen
Copy link

phrozen commented Sep 14, 2015

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?

@Sembiance
Copy link
Contributor

@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.

@phrozen
Copy link

phrozen commented Sep 14, 2015

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.

@Sembiance
Copy link
Contributor

@phrozen I think what you are referring to is detailed in Issue #70

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants