Skip to content

Commit 2081419

Browse files
committed
feat: rewrite local clips path with bb/fs commands
Much nicer than shelling out to `ls` like a heathen
1 parent 581fd46 commit 2081419

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/clips/core.clj

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77
[db.core :as db]))
88

99

10-
(defn local-file-paths []
11-
(let [base-dir (str (fs/home) "/gifs/")]
12-
(->
13-
^{:dir base-dir :out :string}
14-
(proc/$ ls)
15-
proc/check :out
16-
(string/split #"\n"))))
10+
(defn local-clip-paths
11+
([] (local-clip-paths (str (fs/home) "/Dropbox/game-assets/game-clips")))
12+
([dir]
13+
(if (not (fs/exists? dir))
14+
(println "clip dir path does not exist!" dir)
15+
(->> dir
16+
fs/list-dir
17+
(filter fs/directory?)
18+
(#(fs/list-dirs % "*.{gif,mp4}"))
19+
(map str)))))
20+
21+
(comment
22+
(local-clip-paths)
23+
)
1724

1825

1926
(defn fname->clip [f]
@@ -23,6 +30,7 @@
2330
(string/replace #"Kapture " "")
2431
(string/replace #" \d{2}%" "")
2532
(string/replace #" at " "_")
33+
(string/replace #" " "_")
2634
(string/replace #".gif" "")
2735
(string/replace #".mp4" ""))
2836
t (dates.tick/parse-time-string time-string)]
@@ -37,11 +45,14 @@
3745
:clip/time-string time-string})))
3846

3947
(defn all-clips []
40-
(->> (local-file-paths)
48+
(->> (local-clip-paths)
4149
(map fname->clip)
4250
(remove nil?)))
4351

4452
(defn ingest-clips []
4553
(->> (all-clips)
4654
(take 200)
4755
(db/transact)))
56+
57+
(comment
58+
(ingest-clips))

0 commit comments

Comments
 (0)