freesound sourcer

This commit is contained in:
2023-06-13 09:19:04 -06:00
parent 76285c1633
commit b22ac29b97
5 changed files with 58 additions and 2 deletions

View File

@@ -4,12 +4,20 @@
-cp src
-dce full
--each
--main hollywoo_sourcer.PixabayMain
--js bin/pixabay.js
--next
--main hollywoo_sourcer.WikipediaMain
--js bin/wikipedia.js
--next
--main hollywoo_sourcer.FreesoundMain
--js bin/freesound.js
--next
--main hollywoo_sourcer.Background
--js bin/background.js
-cmd cp node_modules/webextension-polyfill/dist/browser-polyfill.js* bin/ && zip -r hollywoo-sourcer.zip . -x *.git* -x *.hxml -x *.zip -x src/\* -x node_modules/\* -x libs/\* -x test.sh
-cmd cp node_modules/webextension-polyfill/dist/browser-polyfill.js* bin/ && zip -r hollywoo-sourcer.zip . -x *.git* -x *.hxml -x *.zip -x src/\* -x node_modules/\* -x libs/\* -x test.sh -x externs/\*

View File

@@ -20,6 +20,12 @@
"https://*.wikipedia.org/wiki/*"
],
"js": ["bin/browser-polyfill.js", "bin/wikipedia.js"]
},
{
"matches": [
"https://freesound.org/people/*/sounds/*/"
],
"js": ["bin/browser-polyfill.js", "bin/freesound.js"]
}
],
"background": {
@@ -43,7 +49,8 @@
"show_matches": [
"https://pixabay.com/*/*/",
"https://*.wikipedia.org/wiki/File:*",
"https://*.wikipedia.org/wiki/*"
"https://*.wikipedia.org/wiki/*",
"https://freesound.org/people/*/sounds/*/"
]
},

View File

@@ -35,5 +35,19 @@
(catch [e] (sendResponse e))
(API.browser.downloads.show txtDownloadId)
(sendResponse "done")))))
((object type "downloadFreesound" data [filename creator fileUrl sourceUrl])
// awaitLet the DownloadItem and make an object url with the source info
(awaitLet [dlItemId (API.browser.downloads.download (object saveAs true url fileUrl))
dlItems (API.browser.downloads.search (object id dlItemId))]
(let [dlItem (first dlItems)
fileName dlItem.filename
txtFileName "$(Path.withoutDirectory (Path.withoutExtension fileName)).tsv"
txtContent "freesound.org\t${creator}\t${sourceUrl} by https://freesound.org/people/${creator}"
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 FreesoundMain {
static function main() {
FreesoundMain_.main();
}
}

View File

@@ -0,0 +1,20 @@
(import kiss_firefox.API)
(import js.lib.Promise)
(importAs js.html.XMLHttpRequest XHR)
(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 [:String url window.location.href
:kiss.List<String> parts (url.split "/")
creator (nth parts -4)
downloadLink (document.getElementById "download_button")
dlUrl .href downloadLink
filename (.pop (url.split "/"))]
(awaitLet [response (API.browser.runtime.sendMessage (object type "downloadFreesound" data [filename creator dlUrl url]))]
(print response))))
(otherwise)))