YGOPRODeck icon indicating copy to clipboard operation
YGOPRODeck copied to clipboard

Some cards do not have their correct passcode as id but one of the inofficial ids used for alternative artworks

Open Larikk opened this issue 3 years ago • 4 comments

Query: https://db.ygoprodeck.com/api/v7/cardinfo.php?name=Dark%20Magician

(Shortened) response:

{
    "data": [{
        "id": 46986421,
        "name": "Dark Magician",
        "type": "Normal Monster",
        "desc": "The ultimate wizard in terms of attack and defense.",
        "atk": 2500,
        "def": 2100,
        "level": 7,
        "race": "Spellcaster",
        "attribute": "DARK",
        "archetype": "Dark Magician",
        "card_images": [{
            "id": 46986421,
            "image_url": "https://storage.googleapis.com/ygoprodeck.com/pics/46986421.jpg",
            "image_url_small": "https://storage.googleapis.com/ygoprodeck.com/pics_small/46986421.jpg"
        }, {
            "id": 46986420,
            "image_url": "https://storage.googleapis.com/ygoprodeck.com/pics/46986420.jpg",
            "image_url_small": "https://storage.googleapis.com/ygoprodeck.com/pics_small/46986420.jpg"
        }, {
            "id": 46986414,
            "image_url": "https://storage.googleapis.com/ygoprodeck.com/pics/46986414.jpg",
            "image_url_small": "https://storage.googleapis.com/ygoprodeck.com/pics_small/46986414.jpg"
        }, {
            "id": 46986415,
            "image_url": "https://storage.googleapis.com/ygoprodeck.com/pics/46986415.jpg",
            "image_url_small": "https://storage.googleapis.com/ygoprodeck.com/pics_small/46986415.jpg"
        }, {
            "id": 46986416,
            "image_url": "https://storage.googleapis.com/ygoprodeck.com/pics/46986416.jpg",
            "image_url_small": "https://storage.googleapis.com/ygoprodeck.com/pics_small/46986416.jpg"
        }, {
            "id": 46986417,
            "image_url": "https://storage.googleapis.com/ygoprodeck.com/pics/46986417.jpg",
            "image_url_small": "https://storage.googleapis.com/ygoprodeck.com/pics_small/46986417.jpg"
        }, {
            "id": 46986418,
            "image_url": "https://storage.googleapis.com/ygoprodeck.com/pics/46986418.jpg",
            "image_url_small": "https://storage.googleapis.com/ygoprodeck.com/pics_small/46986418.jpg"
        }, {
            "id": 46986419,
            "image_url": "https://storage.googleapis.com/ygoprodeck.com/pics/46986419.jpg",
            "image_url_small": "https://storage.googleapis.com/ygoprodeck.com/pics_small/46986419.jpg"
        }, {
            "id": 36996508,
            "image_url": "https://storage.googleapis.com/ygoprodeck.com/pics/36996508.jpg",
            "image_url_small": "https://storage.googleapis.com/ygoprodeck.com/pics_small/36996508.jpg"
        }],
    }]
}

id is 46986421 instead of 46986414 and the elements in card_images are not sorted correctly.

Larikk avatar Aug 28 '21 23:08 Larikk

Ok so I began investigations into this and it's basically a result of the SQL GROUP_CONCAT function which is use for card_images. It's a hard one to avoid honestly. However, there is a small workaround for now;

https://db.ygoprodeck.com/api/v7/cardinfo.php?name=Dark%20Magician&includeAliased&num=1&offset=0

includeAliased basically bypasses GROUP_CONCAT and splits them up into separate entries (so you would get multiple Dark Magician responses.

We are then limiting it to 1 result with &num=1&offset=0

AlanOC91 avatar Oct 22 '21 09:10 AlanOC91

Small update: At first I thought that only Dark Magician is affected but I found a lots of other cards were that happens too:

https://db.ygoprodeck.com/api/v7/cardinfo.php?name=Mystic%20Tomato https://db.ygoprodeck.com/api/v7/cardinfo.php?name=Monster%20Reborn

The workaround above does not work if you request more than one card at once. Therefore I built my own by getting the smallest id listed in card_images.

While doing that it is important to take the alternative artworks of Dark Magician and Polymerization that Konami gave their own id into account. Polymerizations alternative artwork has a higher id than the main artwork so just getting the smallest id is fine in that case. Dark Magicians Arkana artwork however has a lower id so we need to hardcode that as an exception.

Example in python:

def extractCardId(card):
    cardVariants = card['card_images']
    ids = map(lambda e: e['id'], cardVariants)
    id = min(ids)

    # Need to make an exception for Dark Magician
    # Polymerization alt artwork is fine because alt id is higher than main id
    if id == 36996508:
        id = 46986414
    
    return id

Larikk avatar Dec 13 '21 00:12 Larikk

Is there maybe any update on this? I had that issue come up twice today when I imported a pack opening into Duelingbook. A few cards were missing since the YDK file had the id of an alternative artwork :/

This issue affects the main site too btw. Both of these cards have the wrong id displayed: https://db.ygoprodeck.com/card/?search=Metalmorph https://db.ygoprodeck.com/card/?search=Mystic%20Tomato

Larikk avatar Jun 03 '22 18:06 Larikk

This issue seems to be present on this endpoint as well:

https://db.ygoprodeck.com/api/v7/cardsetsinfo.php

For example: https://db.ygoprodeck.com/api/v7/cardsetsinfo.php?setcode=SDRR-EN031&includeAliased&num=1&offset=0

This returns the alt. artwork of Polymerization, instead of the original which the irl card uses.

Jacekun avatar Apr 21 '23 06:04 Jacekun