-
Notifications
You must be signed in to change notification settings - Fork 13
/
elfeed-tube-contrib.el
45 lines (43 loc) · 1.93 KB
/
elfeed-tube-contrib.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;; -*- lexical-binding: t; -*-
(require 'rx)
(require 'aio)
(require 'url)
(defvar elfeed-tube-captions-puntcuate-p nil)
(aio-defun elfeed-tube--punctuate-captions (xmlcaps)
"Accept libxml transcript representation,
return punctuated version"
;; (pp-display-expression xmlcaps (get-buffer-create "xmlcaps-buf"))
(let* ((all-words)
(word-lengths
(cl-loop for (_ (st dt) tx) in (cddr xmlcaps)
do (push (string-trim tx) all-words)
sum (length (split-string (string-trim tx) " " t))
into cumlen
collect cumlen))
(response (aio-await (elfeed-tube-curl-enqueue
"http://bark.phon.ioc.ee/punctuator"
:headers '(("Content-Type" . "application/x-www-form-urlencoded"))
:method "POST"
:data (concat "text="
(-> all-words
(nreverse)
(string-join " ")
(url-hexify-string))))))
(status-code (plist-get response :status-code))
(punctuated (plist-get response :content)))
(if (= status-code 200)
(progn
(cl-loop for num in word-lengths
for (type (st dt) tx) in (cddr xmlcaps)
with high = (car (last word-lengths))
with captions
with tokens = (split-string (elfeed-tube--preprocess-captions punctuated) " " t)
for prev = 0 then len
for len = num
collect `(,type
(,st ,dt)
,(string-join (cl-subseq tokens prev (unless (= len high) len)) " "))
into captions
finally return (nconc '(transcript nil) captions)))
(message (plist-get response :error-messsage))
nil)))