Files
kiss-vscode/projects/nat-archive-tool/src/nat/systems/WikipediaImageSystem.kiss

31 lines
1.3 KiB
Plaintext

(load "../Lib.kiss")
(defNew []
(super
"https://en.wikipedia.org/w/api.php"
->[archive e] (tagsMatch e "(and media !wikipediaProcessed)")
scrapeForImages
1))
// named method in case a user will want to run it on selectedEntries instead of on media entries
(method scrapeForImages [archive e &opt ui]
(let [:String title
(readComponent e Name)
:Array<String> wikipediaImageUrls
(queryImageUrls (queryImageTitles [title]))]
(addFiles archive e
(for url wikipediaImageUrls
(let [filePath
(joinPath archive.archiveDir
~(.replace
(.urlDecode (url.withoutDirectory))
// Some symbols shouldn't be decoded because they're invalid in file systems!
"\"" "%22"))]
(log ui "Downloading $title image: $url")
(assertProcess "curl" ["--output" filePath url])
filePath)))
// Trigger the creation of a new Images component including the wikipedia images
(removeComponent archive e Images)
(removeComponent archive e Images2)
(addTags archive e ["wikipediaProcessed"])))