DLSystem check for youtube-dl

This commit is contained in:
2022-07-02 00:36:36 +00:00
parent 4b52ccdd9f
commit ec92fe80ce
11 changed files with 50 additions and 12 deletions

View File

@@ -161,6 +161,7 @@
(archive.addSystem (new WikipediaImageSystem))
(archive.addSystem (new ImageAttachmentSystem))
(archive.addSystem (new KeyShortcutSystem this))
(archive.addSystem (new DLSystem))
// Just for testing:
// (archive.addSystem (new AttachmentSystem ["jpg" "jpeg" "png"] ->[archive e files] ~files))

View File

@@ -70,23 +70,28 @@
(= ,value (readComponent e ,componentType))))
,process))
(function :Array<String> tagList [archive :nat.Entry e]
(function :Array<String> tagList [:nat.Entry e]
(if (hasComponent e Tags)
(let [t (readComponent e Tags)]
(collect (t.keys)))
[]))
(function tagsMatch [archive e tagsBoolExp]
(BoolExpInterp.eval tagsBoolExp (tagList archive e)))
(function tagsMatch [e tagsBoolExp]
(BoolExpInterp.eval tagsBoolExp (tagList e)))
(function componentsMatch [:nat.Entry e componentsBoolExp]
(BoolExpInterp.eval componentsBoolExp (for =>cType cId e.components cType)))
(function componentsAndTagsMatch [:nat.Entry e componentsAndTagsBoolExp]
(BoolExpInterp.eval componentsAndTagsBoolExp (cast (concat (tagList e) (for =>cType cId e.components cType)))))
(defAlias &call catsMatch componentsAndTagsMatch)
(function addFiles [:nat.Archive archive :nat.Entry e :Array<String> files &opt leaveOriginalCopy]
(withWritableEntry archive e
(doFor file files
(let [pathWithoutDir (haxe.io.Path.withoutDirectory file)]
(unless !(= -1 (e.files.indexOf pathWithoutDir))
(unless (contains e.files pathWithoutDir)
(let [pathInArchive (joinPath archive.archiveDir "files" pathWithoutDir)]
(unless (sys.FileSystem.exists pathInArchive)
((if leaveOriginalCopy sys.io.File.copy sys.FileSystem.rename)

View File

@@ -62,10 +62,14 @@
lastChangeSet)
(defSelectCommand SelectByTags [tagsBoolExp (Text null)]
(filter archive.entries ->e (tagsMatch archive e tagsBoolExp)))
(filter archive.entries ->e (tagsMatch e tagsBoolExp)))
(defSelectCommand SelectByComponents [componentsBoolExp (Text null)]
(filter archive.entries ->e (componentsMatch e componentsBoolExp)))
// TODO selectByCats
// there is currently no easy way to defAlias for every variation of a selection command,
// so Cats may be the canonical name
(defSelectCommand SelectByName [name (Text null)]
(nameSystem.getEntries name))

View File

@@ -0,0 +1,3 @@
package nat.components;
typedef DLURL = String;

View File

@@ -0,0 +1,8 @@
package nat.systems;
import kiss.Prelude;
import kiss.List;
import nat.System;
@:build(kiss.Kiss.build())
class DLSystem extends System {}

View File

@@ -0,0 +1,16 @@
(load "../Lib.kiss")
(defNew []
// Check if youtube-dl is installed before doing anything
(let [&mut hasYTDL false]
(tryProcess "youtube-dl" [] ->error (when (contains error "You must provide at least one URL") (set hasYTDL true)))
(super
->[archive e]
(and ~hasYTDL (catsMatch e "(unless dlProcessed DLURL)"))
->[archive e &opt ui]
{
// (addFiles )
// (addTags archive e ["dlProcessed"])
})))

View File

@@ -5,5 +5,5 @@
:EntryProcessor processor]
[]
(super
(lambda [:Archive archive :Entry e] (tagsMatch archive e tagFilterString))
(lambda [:Archive archive :Entry e] (tagsMatch e tagFilterString))
processor))

View File

@@ -3,7 +3,7 @@
(defNew []
(super
"https://en.wikipedia.org/w/api.php"
->[archive e] (tagsMatch archive e "(and media !wikipediaProcessed)")
->[archive e] (tagsMatch e "(and media !wikipediaProcessed)")
scrapeForImages
1))

View File

@@ -19,10 +19,10 @@
(assert (hasComponent song2 Tags))
(assert (componentsMatch song1 "(and Name Author)"))
(assert (componentsMatch song2 "(and Name Author)"))
(assert (tagsMatch archive song1 "(and song western)"))
(assert !(tagsMatch archive song1 "(and song religious)"))
(assert (tagsMatch archive song2 "(and song religious)"))
(assert !(tagsMatch archive song2 "(and song western)"))
(assert (tagsMatch song1 "(and song western)"))
(assert !(tagsMatch song1 "(and song religious)"))
(assert (tagsMatch song2 "(and song religious)"))
(assert !(tagsMatch song2 "(and song western)"))
(withWritableComponents archive song1
[author Author

View File

@@ -8,7 +8,7 @@
&prop :ArchiveController controller]
(super
->[archive e]
?(and (tagsMatch archive e tagFilterString) (hasComponent e Images))
?(and (tagsMatch e tagFilterString) (hasComponent e Images))
->[archive e &opt ui]
(unless (sprites.exists e.id)
(when !(hasComponent e Positions)