DLSystem handle music

This commit is contained in:
2022-07-02 01:29:18 +00:00
parent ec92fe80ce
commit f62b42f06b
5 changed files with 32 additions and 15 deletions

View File

@@ -131,6 +131,7 @@ class Kiss {
"fEighth" => Symbol("Prelude.fEighth"), "fEighth" => Symbol("Prelude.fEighth"),
"fNinth" => Symbol("Prelude.fNinth"), "fNinth" => Symbol("Prelude.fNinth"),
"fTenth" => Symbol("Prelude.fTenth"), "fTenth" => Symbol("Prelude.fTenth"),
"uuid" => Symbol("Prelude.uuid"),
], ],
identAliases: [ identAliases: [
// These ones won't conflict with variables and might commonly be used with (apply) // These ones won't conflict with variables and might commonly be used with (apply)

View File

@@ -461,6 +461,10 @@ class Prelude {
}; };
} }
public static function uuid() {
return Uuid.v4().toShort();
}
// ReaderExp helpers for macros: // ReaderExp helpers for macros:
public static function symbol(?name:String):ReaderExpDef { public static function symbol(?name:String):ReaderExpDef {
if (name == null) if (name == null)

View File

@@ -219,6 +219,9 @@
(defCommand AddKeyShortcut [e SelectedEntry description (Text null)] (defCommand AddKeyShortcut [e SelectedEntry description (Text null)]
(addComponent archive e KeyShortcut description)) (addComponent archive e KeyShortcut description))
(defCommand AddDLURL [e SelectedEntry url (Text null)]
(addComponent archive e DLURL url))
(defCommand AddNATCommand [e (SelectedEntries null null) command (Text null)] (defCommand AddNATCommand [e (SelectedEntries null null) command (Text null)]
(doFor e e (addComponent archive e NATCommand command))) (doFor e e (addComponent archive e NATCommand command)))

View File

@@ -13,11 +13,11 @@
(controller.tryRunCommand command)))) (controller.tryRunCommand command))))
(prop &mut :ArchiveController controller) (prop &mut :ArchiveController controller)
(prop :KeyShortcutHandler<Entry> shortcutHandler null) (prop :kiss_tools.KeyShortcutHandler<Entry> shortcutHandler null)
(defNew []) (defNew [])
(method :Void enterText [prompt resolve maxLength] (method :Void enterText [prompt :String->Void resolve maxLength]
(Sys.print "$prompt ") (Sys.print "$prompt ")
(loop (loop
(let [entered (.toString (.readLine (Sys.stdin)))] (let [entered (.toString (.readLine (Sys.stdin)))]
@@ -26,7 +26,7 @@
{(resolve entered) {(resolve entered)
(break)})))) (break)}))))
(method :Void enterNumber [prompt resolve min max &opt inStepsOf] (method :Void enterNumber [prompt :Float->Void resolve min max &opt inStepsOf]
(Sys.print "$prompt ") (Sys.print "$prompt ")
(loop (loop
(let [entered (Std.parseFloat (.toString (.readLine (Sys.stdin))))] (let [entered (Std.parseFloat (.toString (.readLine (Sys.stdin))))]
@@ -38,13 +38,13 @@
{(resolve entered) {(resolve entered)
(break)})))) (break)}))))
(method :Void chooseEntry [prompt :Archive archive resolve] (method :Void chooseEntry [prompt :Archive archive :Entry->Void resolve]
(_chooseEntry prompt archive resolve ->(chooseEntry "empty name doesn't match any entries. Try again?" archive resolve))) (_chooseEntry prompt archive resolve ->(chooseEntry "empty name doesn't match any entries. Try again?" archive resolve)))
(method :Void _chooseEntry [prompt :Archive archive resolve onEmptyString] (method :Void _chooseEntry [prompt :Archive archive :Entry->Void resolve :Void->Void onEmptyString]
// TODO allow narrowing down with a tag string // TODO allow narrowing down with a tag string
(enterText "entry name for $prompt" (enterText "entry name for $prompt"
->name { ->:Void name {
(if !name (if !name
(onEmptyString) (onEmptyString)
(let [matchingEntries (controller.nameSystem.getEntries name)] (let [matchingEntries (controller.nameSystem.getEntries name)]
@@ -52,15 +52,16 @@
([e] (resolve e)) ([e] (resolve e))
([] (chooseEntry "name $name doesn't match any entries. Try again?" archive resolve)) ([] (chooseEntry "name $name doesn't match any entries. Try again?" archive resolve))
// TODO disambiguate entries with the same names by listing stringified versions of them and using enterNumber // TODO disambiguate entries with the same names by listing stringified versions of them and using enterNumber
(multipleEntries (throw "ambiguous between multiple entries")))))} (multipleEntries (throw "ambiguous between multiple entries"))
(otherwise))))}
Math.POSITIVE_INFINITY)) Math.POSITIVE_INFINITY))
(method :Void chooseEntries [prompt archive resolve min max] (method :Void chooseEntries [prompt archive :Array<nat.Entry>->Void resolve min max]
(_chooseEntries prompt archive resolve min max [])) (_chooseEntries prompt archive resolve min max []))
(method :Void _chooseEntries [prompt archive resolve min max :Array<Entry> collectedEntries] (method :Void _chooseEntries [prompt archive :Array<nat.Entry>->Void resolve min max :Array<Entry> collectedEntries]
(let [onEmptyString (let [onEmptyString
->(if (<= min collectedEntries.length) ->:Void (if (<= min collectedEntries.length)
(resolve collectedEntries) (resolve collectedEntries)
(throw "not enough entries chosen")) (throw "not enough entries chosen"))
&mut :Void->Void chooseNextEntry &mut :Void->Void chooseNextEntry

View File

@@ -7,10 +7,18 @@
(super (super
->[archive e] ->[archive e]
(and ~hasYTDL (catsMatch e "(unless dlProcessed DLURL)")) (and hasYTDL (catsMatch e "(unless dlProcessed DLURL)"))
->[archive e &opt ui] ->[archive e &opt ui]
{ (let [basename (uuid)
url (readComponent e DLURL)]
(cond
((tagsMatch e "music")
```
youtube-dl -x --audio-format mp3 -o ${basename}.mp3 $url
```
(addFiles archive e ["${basename}.mp3"]))
(true
(log ui "DLSystem doesn't know what to do with $(readComponent e Tags)")
(return null)))
// (addFiles ) (addTags archive e ["dlProcessed"])))))
// (addTags archive e ["dlProcessed"])
})))