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
Wikimedia #21
Comments
This would be possible quiet easy but I just suggested a Generic JSON API source in #22 where you also could add your opinion if you want to. Since the Wikimedia picture would be an XML response we would have to think of another solution but it would be also possible to add a Generic XML API source. |
Wikimedia Commons also has its own API. What I've found
I tried the next sources, but failed:
It seems |
The following works:
References
{
"parse": {
"title": "API",
"pageid": 0,
"images": [
"Geraldine_Ulmar_in_Gilbert_and_Sullivan's_The_Mikado.jpg"
]
}
} Edit:
|
This is actually a bit more involved.
Possible fixes:
@ifl0w Any opinions? |
@Lucki I'd not remove the encoding entirely since I'd assume that this could break existing setups. If the Another somewhat hacky approach could also be to simply call |
I'm sorry, we can't use
No matter how we encode and decode - it's never matching the correct URL copied from Firefox. |
I do not understand the problem exactly, but an api call https://commons.wikimedia.org/w/api.php?action=parse&format=json&pageid=18176574&prop=images&formatversion=2 is also available (18176574 is the page id of MediaWiki:feed-potd-transcludeme) . Does this solve something? |
For this particular case that's a workaround, yes. The problem is for other sites where it's not this easily possible. A general solution would be better. |
Here is an example on how to find the latest picture in plain js: const https = require('https');
const fs = require('fs');
const resolution = process.argv.at(2) || '1280px' // 1024px 2560px
const url = 'https://commons.wikimedia.org/w/api.php?action=featuredfeed&feed=potd&feedformat=atom';
const match1 = 'href="https://commons.wikimedia.org/wiki/Special'
const match2 = 'typeof="mw:File"'
const getUrl = (url) => {
return new Promise((resolve) => {
https.get(url, resp => {
let data = ''
resp.on('data', c => data += c)
resp.on('end', () => {
resolve(data)
})
})
})
}
const download = (url, dest) => {
return new Promise((resolve) => {
const file = fs.createWriteStream(dest);
https.get(url, resp => {
resp.pipe(file);
file.on('finish', () => file.close(resolve))
})
})
}
(async () => {
const data = await getUrl(url)
const urls = data.split(/\n/).filter(l => l.includes(match1)).map(l => l.split(/"/)[5])
const lastUrl = urls.slice(-1)[0]
const data2 = await getUrl(lastUrl)
const picUrl = data2.split(/\n/).filter(l => l.includes(match2)).map(l => l.split(/"/)[7])
const picName = picUrl[0].slice(11)
const picFullUrl = `https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/${picName}/${resolution}-${picName}`
download(picFullUrl, '/tmp/wikimedia.jpg')
})() |
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
Wikimedia has a rss/atom feed of a best picture in there catalog every day. It would be nice to use it as a feed of wallpapers!
https://commons.wikimedia.org/wiki/Commons:Picture_of_the_day
The text was updated successfully, but these errors were encountered: