freesound sourcer
This commit is contained in:
@@ -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)))
|
||||
|
7
src/hollywoo_sourcer/FreesoundMain.hx
Normal file
7
src/hollywoo_sourcer/FreesoundMain.hx
Normal file
@@ -0,0 +1,7 @@
|
||||
package hollywoo_sourcer;
|
||||
|
||||
class FreesoundMain {
|
||||
static function main() {
|
||||
FreesoundMain_.main();
|
||||
}
|
||||
}
|
20
src/hollywoo_sourcer/FreesoundMain_.kiss
Normal file
20
src/hollywoo_sourcer/FreesoundMain_.kiss
Normal 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)))
|
Reference in New Issue
Block a user