Recently Written · git

librivox

Automated youtube uploading of audiobooks

git clone https://github.com/equwal/librivox

Log | Files | Refs


commit 5798c461c2468ae27b1c5cefe49e7c1be00cf222
Spenser Truex <struex0@gmail.com>
2018-08-02 00:04:54 -0700

Html parser works exactly as needed.

 src/html-parse.lisp | 53 +++++++++++++++++++++++++----------------------------
 1 file changed, 25 insertions(+), 28 deletions(-)
diff --git a/src/html-parse.lisp b/src/html-parse.lisp
index 8001bee..12e117e 100644
--- a/src/html-parse.lisp
+++ b/src/html-parse.lisp
@@ -2,39 +2,36 @@
 ;;; Specification:
 ;;; (("xml")("html" ("body" ("p" nil)))
 ;;; (ie. each one is a regex.
-(defun rate (specification tree)
-  (declare (ignore specification tree)))
 (defun tag-of (html-string)
   (mvbind (success? tag-array)
 	  (scan-to-strings"<(.*?\\w*).*?>" html-string)
 	  (when success? (aref tag-array 0))))
 (defun content-of (tag-name html-string &key inside after)
-  (mvbind (output parens)
-      ;; If things are slow, it is this runtime regex expansion
-	  (scan-to-strings (format nil "<~A\\w*.*?>(.*?)</~:*~A>(.*)" tag-name) html-string)
-	  (declare (ignore output))
-	  (let ((inside-val (aref parens 0))
-		(after-val (aref parens 1)))
-	    (cond ((and (not inside) after) after)
-		  ((and inside       (not after))  inside)
-		  (t (values inside-val after-val))))))
-(defun push-tree (node tree)
-  (if node (cons node tree) tree))
-(defun push-node (atom node)
-  (if node
-      (cons node atom)
-      atom))
-(defun adjoin-trees (tree1 tree2)
-  (append tree1 tree2))
-(declaim (inline get-node))
-(defun get-node (key node)
-  (assoc key node))
-(defun html->lispy (html-string &optional node)
+  (flet ((inner () (mvbind (output parens)
+			   ;; If things are slow, it is this runtime regex expansion
+			   (scan-to-strings (format nil "<~A\\w*.*?>(.*?)</~:*~A>(.*)" tag-name) html-string)
+			   (declare (ignore output))
+			   (let ((inside-val (aref parens 0))
+				 (after-val (aref parens 1)))
+			     (values inside-val after-val)))))
+    (mvbind (inside1 after1) (inner)
+	    (if (and inside after)
+		(values inside1 after1)
+		(if inside inside1 after1)))))
+(defun make-node (left right)
+  (cons left right))
+(defun make-tree (node1 node2)
+  (cons node1 node2))
+
+(defun make-datum (id text)
+  (make-node id text))
+(defun html->lispy (html-string)
   (if (string= "" html-string)
-      node
+      nil
       (let ((tag-of (tag-of html-string)))
 	(if tag-of
-	    (mvbind (inside after) (content-of tag-of html-string)
-		    (push-tree (push-node (html->lispy inside tag-of) node)
-			       (html->lispy after)))
-	    (push-node html-string node)))))
+	    (make-tree (make-datum tag-of (html->lispy (content-of tag-of
+								   html-string
+								   :inside t)))
+		       (html->lispy (content-of tag-of html-string :after t)))
+	    html-string))))