Fork me on GitHub
#clojurescript
<
2023-10-31
>
James Amberger03:10:00

Any guesses why I get an error in the repl when I eval js/alert or (js/alert "hello")? I’m using vim-fireplace and shadow-cljs and not doing anything especially exotic… I’ve also tried same expressions in the repl you get from npx shadow-cljs cljs-repl :app. (js/console.log "asdf") works fine in both cases. Edit: This probably belongs in #shadow-cljs; seems to have to do with my shadow config.

hiredman04:10:08

What error do you get?

James Amberger04:10:10

and… now I can’t reproduce. I want the last hour (ok more than that) of my life back.

stagmoose15:10:04

I am trying to parse an .srt subtitle text inside cljs, currently using instaparse. input:

1
00:00:02,290 --> 00:00:03,193
sentence 1

2
00:00:22,825 --> 00:00:24,406
sentence 2

3
00:00:24,406 --> 00:00:24,987
sentence 3
grammar:
Caption = sentence+
sentence = (index new-line
            start arrorw end new-line
            text new-line)
index = #"\d+"
new-line = #"\n*"
start = hour colon min colon sec comma minisec
end = hour colon min colon sec comma minisec
hour = #"\d{2}"
min = #"\d{2}"
sec = #"\d{2}"
minisec = #"\d{3}"
colon = ":"
comma = ","
arrorw = " --> "
text = #".*"
you can paste these to: https://instaparse-live.matt.is/ it can successfully parse the result. my question is: is there a better way to achieve this? is parsing .srt files a simple problem without introducing instaparse?

Nundrum15:10:02

It depends on what "better" means in your context, but you could certainly read that in line by line and parse the start/end timestamps with a regex.

👌 1
p-himik16:10:14

Yeah, I'd definitely just use a bunch of calls to split. It's a frozen simple format, there's no need to involve any intricate parsers.

👌 1
tomd16:10:17

Something using tick.core/time:

(->> (str/split sample-srt #"\n\n(?=\d)")
     (map str/split-lines)
     (map (fn [[i ts & s]]
            (let [[_ start end] (re-matches #"(\d\d:\d\d:\d\d,\d\d\d) --> (\d\d:\d\d:\d\d,\d\d\d)" ts)]
              {:index i
               :timestamp {:start (t/time (str/replace start #"," "."))
                           :end (t/time (str/replace end #"," "."))}
               :sentences s}))))
;; => ({:index "1",
;;      :timestamp
;;      {:start #time/time "00:00:02.290", :end #time/time "00:00:03.193"},
;;      :sentences ("sentence 1")}
;;     {:index "2",
;;      :timestamp
;;      {:start #time/time "00:00:22.825", :end #time/time "00:00:24.406"},
;;      :sentences ("sentence 2")}
;;     {:index "3",
;;      :timestamp
;;      {:start #time/time "00:00:24.406", :end #time/time "00:00:24.987"},
;;      :sentences ("sentence 3")})

🤯 1
🔥 1
stagmoose00:11:29

wow, i will have a look on tick library, thanks!

👍 1