I'm going to put together some loops and insert it all into a MySQL database. Woo.
Note that not all fields are set for each record, as well (or at least that used to be the case) - the following saved me a lot of grief when I first started using this with PHP:
function ifPropertyExists($object, $propertyName, $altValue) {
if (is_object($object)) {
if (property_exists($object, $propertyName)) {
return $object->{$propertyName};
} else {
return $altValue;
}
} else if ((array) $object === $object) {
if (isset($object[$propertyName])) {
return $object[$propertyName];
} else {
return $altValue;
}
}
}
Works for both object and array decided versions of the data
For some bizarro reason, in the Clash Pack both Temple of Mystery and Courser of Kruphix are numbered as #6 in the set. I've checked the card art, and this is on the card as well (card printing error, maybe?).
Technically correct, but obviously causes some issues when getting the image from MagicCards.info, which has Courser as #12. Not sure whether this is the place to fix it, or whether ths should just be here as an FYI for the people who need to be aware of it.
Sorry folks, my face is covered in egg (bonus: it's covering up that embarassed red hue). I did some tests, and couldn't reproduce the duplicate IDs I saw before. I'll just be crawling back to my hole
id is the one I mean, yes - sorry, getting my terminology mixed up.
I'll stick some more checks in my code, to be sure, and try to run an independent simulation (without so may moving parts), to see if I can come up with some concrete examples.
@cyclotis04 Basically, I did a bunch of database inserts using cardId as a primary key, and got duplcate primary key clashes.
Unfortunately, SHA is a hash, not a UUID, so it can't guarantee uniqueness. The bigger the dataset, the bigger the chance of a duplicate.
I've tried a couple of different solutions, but haven't managed to find one yet that passes my basic criteria (must be unique, must be able to be used in a URL / XML without requiring encoding, preferably fixed width, and able to be reproduced predictably from card data, or the same across multiple updates).
The best solution I can come up with from the source data end would be if each card record in MTGJSON were assigned a UUID at initial creation time, but that updates to the file used the fields used to generate the cardId hash when identifying which record to update, so that the ID stays constant.
Edit: It'd actually be handy if each entity described in a record had its own ID, now that I think about it - each record basically describes a single printing of a single playable (of which there can be more than one on a split, flip or double-faced card) on a card. Card, Printing and Playable can all be considered separate entities, potentially needing their own ids for linking purposes.
Hi @Andarilhomtg Thanks for taking on this responsibility
Small question about the cardId field, since I'm working on a new database structure for my site - I've noticed that the SHA1 hashes used for cardIds in MTGJSON aren't necessarily unique. Is it possible to refine the cardId field a bit going forward?
That's a real shame, Sembiance.. You've been a real hero to a lot of projects - quite a lot of the apps on here couldn't have happened without you, including mine. Still, burnout happens.
Would anybody here be keen to form some sort of collaborative development team to help him out? I don't have time to take it all on myself, but I could contribute as part of a group...
I'm new to this forum so I hope this is the right place to post this. If not, pls redirect to correct place.
Has anyone discovered alternative sources for downloading images? I'm creating a new app using mtgjson (what a great resource!) but it will be pretty useless if it can't display card images. Naturally I would like to be able to display any and all cards, old and new. I've been doing quite a bit of searching and this appears to be a big problem for lots of developers.
It looks like it might be possible to get images directly from wizards.com, but I imagine it's not that simple. Plus, I'm not sure whether that's even permissible.
Any update on this topic would be much appreciated!
Up until fairly recently there was another API (mtgapi) that was serving up the images, but that's since been taken down.
The T&Cs for Gatherer, unfortunately, prohibit scraping their site for images (their images are a bit low-res anyway)
Some sites use MagicCards.info as an image source, although I'm not sure what MCI's own stance on this is (of any of their devs frequent these forums, I'd love to hear their position). They use a special set code (included in MTGJSON) and the number of the card in the set (with some exceptions - see this post for information on how to generate missing card numbers) to construct their URL... Some examining of their site should turn up the rest of the info you need
Zendikar Expedition and Battle for Zendikar have been added
I'm doing some fiddling with the database at the moment, which is slowing up other development. Hopefully, by the time I'm finished, the data on the site will be easier to update, and will be able to support promos. Touch wood
37, no kids yet. I started playing with my wife a couple of years ago, and she plays as part of my regular EDH group, as well as partnering me in 2HG when it pops up at FNM
Kudos to @andarilhomtg for keeping MTGJSON maintained, so I could get it up so quickly
Note that not all fields are set for each record, as well (or at least that used to be the case) - the following saved me a lot of grief when I first started using this with PHP:
Works for both object and array decided versions of the data
Technically correct, but obviously causes some issues when getting the image from MagicCards.info, which has Courser as #12. Not sure whether this is the place to fix it, or whether ths should just be here as an FYI for the people who need to be aware of it.
I'll stick some more checks in my code, to be sure, and try to run an independent simulation (without so may moving parts), to see if I can come up with some concrete examples.
Not trying to ruffle any feathers here
Unfortunately, SHA is a hash, not a UUID, so it can't guarantee uniqueness. The bigger the dataset, the bigger the chance of a duplicate.
I've tried a couple of different solutions, but haven't managed to find one yet that passes my basic criteria (must be unique, must be able to be used in a URL / XML without requiring encoding, preferably fixed width, and able to be reproduced predictably from card data, or the same across multiple updates).
The best solution I can come up with from the source data end would be if each card record in MTGJSON were assigned a UUID at initial creation time, but that updates to the file used the fields used to generate the cardId hash when identifying which record to update, so that the ID stays constant.
Edit: It'd actually be handy if each entity described in a record had its own ID, now that I think about it - each record basically describes a single printing of a single playable (of which there can be more than one on a split, flip or double-faced card) on a card. Card, Printing and Playable can all be considered separate entities, potentially needing their own ids for linking purposes.
Small question about the cardId field, since I'm working on a new database structure for my site - I've noticed that the SHA1 hashes used for cardIds in MTGJSON aren't necessarily unique. Is it possible to refine the cardId field a bit going forward?
Thanks Sembiance - you've been amazing
Would anybody here be keen to form some sort of collaborative development team to help him out? I don't have time to take it all on myself, but I could contribute as part of a group...
Seems to have been fixed now
Up until fairly recently there was another API (mtgapi) that was serving up the images, but that's since been taken down.
The T&Cs for Gatherer, unfortunately, prohibit scraping their site for images (their images are a bit low-res anyway)
Some sites use MagicCards.info as an image source, although I'm not sure what MCI's own stance on this is (of any of their devs frequent these forums, I'd love to hear their position). They use a special set code (included in MTGJSON) and the number of the card in the set (with some exceptions - see this post for information on how to generate missing card numbers) to construct their URL... Some examining of their site should turn up the rest of the info you need
Assuming this is because the Expedition cards are only printed in English, even though they can appear in international boosters
I'm doing some fiddling with the database at the moment, which is slowing up other development. Hopefully, by the time I'm finished, the data on the site will be easier to update, and will be able to support promos. Touch wood