Closed don-vip closed 1 year ago
As a workaround I use this hack:
static MediaInfoDocument getMediaInfoDocument(String filename) throws MediaWikiApiErrorException, IOException {
// workaround to https://github.com/Wikidata/Wikidata-Toolkit/issues/777
String title = "File:" + filename;
if (fetcher.getEntityDocumentsByTitle("commonswiki", title)
.get(title.split("-")[0]) instanceof MediaInfoDocument doc) {
return doc;
} else {
throw new IllegalStateException("No commons mediaInfo found for filename " + filename);
}
}
Thanks @don-vip! What a honor to have a JOSM developer in this modest repository! :)
This titles.split("-")
should just be titles.split("|")
. Titles cannot contain the |
character and this is the one that is used to encode lists of parameters in this API. See https://commons.wikimedia.org/w/api.php?action=help&modules=wbgetentities
Hi @wetneb, thank you! You're welcome, thank you for the quick fix 👍
This code fails to retrieve the media-info for this file:
It's because of this split, line 169:
As the file name contains a dash, the map key does not match the full title.