benjaminkomen / TibiaWikiApi

Expose data from TibiaWiki with a REST API
MIT License
34 stars 2 forks source link

Feature: image of item, creature etc. #75

Open biaggio12 opened 4 years ago

biaggio12 commented 4 years ago

Hey, so far i'm loving the API. Easy and simple to use, but it's missing one feature. I'm not an expert but as far as it's possible would be great if you add the image URL in responses on the creatures and items etc. Would be really usefull

benjaminkomen commented 4 years ago

Hi! Glad you like it!

Which image URL would you prefer to have? Let's take a creature, say a dragon for example. We could add an imageUrl field which could hold https://tibia.fandom.com/wiki/File:Dragon.gif, but that is something we can simply derive from the name attribute (because images of 'things' in TibiaWiki are always structured as 'File:{PAGENAME}.gif' and the page name is in the name field).

But I can imagine you want a direct URL to the image, e.g. https://vignette.wikia.nocookie.net/tibia/images/e/e0/Dragon.gif/revision/latest?cb=20140823213526&path-prefix=en

I think this URL is a bit more dynamic and can change over time, maybe also differ per region you access TibiaWiki from.

biaggio12 commented 4 years ago

Hmm, that's actually kinda pain in the ass. Yea i'd like to have direct URL to img like the second one you posted. I wonder how dynamic it is. I think the URL is changing each time someone edits the article but i'm not really sure. Well if that's gonna help you somehow then i don't think this URL depends on region of access. The URL u sent here is working perfectly fine for me. (I'm accessing it from Poland. )

benjaminkomen commented 4 years ago

Ok, well, let's see what I can do, I think it might be obtainable using the MediaWiki API and if not, we'll just have to be a bit more creative :)

benjaminkomen commented 4 years ago

Ok, the MediaWiki API does support this, e.g.: https://tibia.fandom.com/api.php?action=query&titles=File%3ADragon.gif&prop=imageinfo&iilimit=50&iiend=2007-12-31T23%3A59%3A59Z&iiprop=timestamp%7Cuser%7Curl&format=json results in:

{
  "query": {
    "pages": {
      "1317": {
        "pageid": 1317,
        "ns": 6,
        "title": "File:Dragon.gif",
        "imagerepository": "local",
        "imageinfo": [
          {
            "timestamp": "2014-08-23T21:35:26Z",
            "user": "Kapitan Kuna",
            "url": "https://vignette.wikia.nocookie.net/tibia/images/e/e0/Dragon.gif/revision/latest?cb=20140823213526&path-prefix=en",
            "descriptionurl": "https://tibia.fandom.com/wiki/File:Dragon.gif"
          }
        ]
      }
    }
  }
}