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

foreign multiverse id #12

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

Comments

Projects
None yet
7 participants
@aeosynth

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

This comment has been minimized.

Show comment
Hide comment
@Sembiance

Sembiance Jun 13, 2014

Collaborator

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

Collaborator

Sembiance commented Jun 13, 2014

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

This comment has been minimized.

Show comment
Hide comment
@Daenyth

Daenyth Jul 3, 2014

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

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

This comment has been minimized.

Show comment
Hide comment
@Lazarus974

Lazarus974 Jan 24, 2015

Also interested !

Also interested !

@Lazarus974

This comment has been minimized.

Show comment
Hide comment
@Lazarus974

Lazarus974 Feb 20, 2015

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

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

This comment has been minimized.

Show comment
Hide comment
@Sembiance

Sembiance Jul 13, 2015

Collaborator

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

Collaborator

Sembiance commented Jul 13, 2015

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

@Sembiance Sembiance closed this Jul 13, 2015

@Sembiance

This comment has been minimized.

Show comment
Hide comment
@Sembiance

Sembiance Aug 15, 2015

Collaborator

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.

Collaborator

Sembiance commented Aug 15, 2015

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

This comment has been minimized.

Show comment
Hide comment
@Sembiance

Sembiance Aug 15, 2015

Collaborator

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.

Collaborator

Sembiance commented Aug 15, 2015

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

This comment has been minimized.

Show comment
Hide comment
@ZeldaZach

ZeldaZach Aug 15, 2015

Member

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

Member

ZeldaZach commented Aug 15, 2015

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

@Sembiance

This comment has been minimized.

Show comment
Hide comment
@Sembiance

Sembiance Aug 17, 2015

Collaborator

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.

Collaborator

Sembiance commented Aug 17, 2015

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

This comment has been minimized.

Show comment
Hide comment
@ZeldaZach

ZeldaZach Aug 17, 2015

Member

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

Member

ZeldaZach commented Aug 17, 2015

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

Sembiance added a commit that referenced this issue Aug 18, 2015

@Sembiance

This comment has been minimized.

Show comment
Hide comment
@Sembiance

Sembiance Aug 18, 2015

Collaborator

Latest 3.0.0 version has this info.

Collaborator

Sembiance commented Aug 18, 2015

Latest 3.0.0 version has this info.

@Sembiance Sembiance closed this Aug 18, 2015

@ctrlaltca

This comment has been minimized.

Show comment
Hide comment
@ctrlaltca

ctrlaltca Aug 22, 2015

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.

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

This comment has been minimized.

Show comment
Hide comment
@Sembiance

Sembiance Aug 24, 2015

Collaborator

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

Collaborator

Sembiance commented Aug 24, 2015

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

@phrozen

This comment has been minimized.

Show comment
Hide comment
@phrozen

phrozen 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?

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

This comment has been minimized.

Show comment
Hide comment
@Sembiance

Sembiance Sep 14, 2015

Collaborator

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

Collaborator

Sembiance commented Sep 14, 2015

@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

This comment has been minimized.

Show comment
Hide comment
@phrozen

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

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

This comment has been minimized.

Show comment
Hide comment
@Sembiance

Sembiance Sep 14, 2015

Collaborator

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

Collaborator

Sembiance commented Sep 14, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment