freesound sourcer
This commit is contained in:
10
build.hxml
10
build.hxml
@@ -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/\*
|
@@ -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/*/"
|
||||
]
|
||||
},
|
||||
|
||||
|
@@ -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