DLSystem check for youtube-dl

This commit is contained in:
2022-07-02 00:36:36 +00:00
parent 270c29b8b2
commit c3e756e634
9 changed files with 48 additions and 11 deletions

View File

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

View File

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

View File

@@ -62,10 +62,14 @@
lastChangeSet) lastChangeSet)
(defSelectCommand SelectByTags [tagsBoolExp (Text null)] (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)] (defSelectCommand SelectByComponents [componentsBoolExp (Text null)]
(filter archive.entries ->e (componentsMatch e componentsBoolExp))) (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)] (defSelectCommand SelectByName [name (Text null)]
(nameSystem.getEntries name)) (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] :EntryProcessor processor]
[] []
(super (super
(lambda [:Archive archive :Entry e] (tagsMatch archive e tagFilterString)) (lambda [:Archive archive :Entry e] (tagsMatch e tagFilterString))
processor)) processor))

View File

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

View File

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