OpenClipArt sourcer

This commit is contained in:
2024-02-03 16:19:18 -07:00
parent f8f968243b
commit a52fceddc2
5 changed files with 53 additions and 2 deletions

View File

@@ -5,6 +5,10 @@
-dce full
--each
--main hollywoo_sourcer.OpenClipArtMain
--js bin/openclipart.js
--next
--main hollywoo_sourcer.PixabayMain
--js bin/pixabay.js
--next

View File

@@ -10,6 +10,10 @@
"48": "icons/icon-48.png"
},
"content_scripts": [
{
"matches": ["https://openclipart.org/detail/*/*"],
"js": ["bin/browser-polyfill.js", "bin/openclipart.js"]
},
{
"matches": ["https://pixabay.com/*/*/"],
"js": ["bin/browser-polyfill.js", "bin/pixabay.js"]
@@ -57,7 +61,8 @@
"https://*.wikipedia.org/wiki/File:*",
"https://*.wikipedia.org/wiki/*",
"https://freesound.org/people/*/sounds/*/",
"https://opengameart.org/content/*"
"https://opengameart.org/content/*",
"https://openclipart.org/detail/*/*"
]
},

View File

@@ -4,7 +4,7 @@
(API.browser.tabs.sendMessage
tab.id (object type "requestSource" data [])))
(API.browser.runtime.onMessage.addListener ->[:Message message sender sendResponse]
(API.browser.runtime.onMessage.addListener ->[:Message message sender sendResponse]
(let [:Function sendResponse sendResponse]
(case message
((object type "downloadPixabay" data [imageInfo])
@@ -65,5 +65,19 @@
(catch [e] (sendResponse e))
(API.browser.downloads.show txtDownloadId)
(sendResponse "done"))))))
((object type "downloadOpenClipArt" data [sourceUrl filename creator fileUrl])
// awaitLet the DownloadItem and make an object url with the source info
(awaitLet [dlItemId (API.browser.downloads.download (object saveAs true url fileUrl filename "${filename}.png"))
dlItems (API.browser.downloads.search (object id dlItemId))]
(let [dlItem (first dlItems)
fileName dlItem.filename
txtFileName "$(Path.withoutDirectory (Path.withoutExtension fileName)).tsv"
txtContent "openclipart.org\t${creator}\t${sourceUrl}"
file (new File [txtContent] txtFileName)
txtUrl (URL.createObjectURL file)]
(awaitLet [txtDownloadId (API.browser.downloads.download (object url txtUrl filename txtFileName))]
(catch [e] (sendResponse e))
(API.browser.downloads.show txtDownloadId)
(sendResponse "done")))))
(never otherwise))
true)))

View File

@@ -0,0 +1,7 @@
package hollywoo_sourcer;
class OpenClipArtMain {
static function main() {
OpenClipArtMain_.main();
}
}

View File

@@ -0,0 +1,21 @@
(import kiss_firefox.API)
(import js.lib.Promise)
(importAs js.html.XMLHttpRequest XHR)
(import js.html.HTMLCollection)
(import hollywoo_sourcer.Message)
(var :Dynamic document js.Lib.global.document)
(var :Dynamic window js.Lib.global.window)
(API.browser.runtime.onMessage.addListener
->[:Message message sender sendResponse]
(case message
((object type "requestSource")
(let [url window.location.href
title .innerHTML (.item (document.getElementsByTagName "h2") 0)
links (document.getElementsByTagName "a")
links (for idx (range links.length) (links.item idx))
artist .innerHTML (first (filter links ->[:Dynamic link] (StringTools.contains link.href "/artist/")))
fileUrl .href (first (filter links ->[:Dynamic link] (= link.innerHTML "Large")))]
(awaitLet [response (API.browser.runtime.sendMessage (object type "downloadOpenClipArt" data [url title artist fileUrl]))]
(print response))))
(otherwise)))