DLSystem handle music

This commit is contained in:
2022-07-02 01:29:18 +00:00
parent c3e756e634
commit 54799d8450
3 changed files with 27 additions and 15 deletions

View File

@@ -219,6 +219,9 @@
(defCommand AddKeyShortcut [e SelectedEntry description (Text null)]
(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)]
(doFor e e (addComponent archive e NATCommand command)))

View File

@@ -13,11 +13,11 @@
(controller.tryRunCommand command))))
(prop &mut :ArchiveController controller)
(prop :KeyShortcutHandler<Entry> shortcutHandler null)
(prop :kiss_tools.KeyShortcutHandler<Entry> shortcutHandler null)
(defNew [])
(method :Void enterText [prompt resolve maxLength]
(method :Void enterText [prompt :String->Void resolve maxLength]
(Sys.print "$prompt ")
(loop
(let [entered (.toString (.readLine (Sys.stdin)))]
@@ -26,7 +26,7 @@
{(resolve entered)
(break)}))))
(method :Void enterNumber [prompt resolve min max &opt inStepsOf]
(method :Void enterNumber [prompt :Float->Void resolve min max &opt inStepsOf]
(Sys.print "$prompt ")
(loop
(let [entered (Std.parseFloat (.toString (.readLine (Sys.stdin))))]
@@ -38,13 +38,13 @@
{(resolve entered)
(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)))
(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
(enterText "entry name for $prompt"
->name {
->:Void name {
(if !name
(onEmptyString)
(let [matchingEntries (controller.nameSystem.getEntries name)]
@@ -52,15 +52,16 @@
([e] (resolve e))
([] (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
(multipleEntries (throw "ambiguous between multiple entries")))))}
(multipleEntries (throw "ambiguous between multiple entries"))
(otherwise))))}
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 []))
(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
->(if (<= min collectedEntries.length)
->:Void (if (<= min collectedEntries.length)
(resolve collectedEntries)
(throw "not enough entries chosen"))
&mut :Void->Void chooseNextEntry

View File

@@ -7,10 +7,18 @@
(super
->[archive e]
(and ~hasYTDL (catsMatch e "(unless dlProcessed DLURL)"))
(and hasYTDL (catsMatch e "(unless dlProcessed DLURL)"))
->[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"])))))