Use curl over url-retrieve when possible

I have no idea why, but url-retrieve-synchronously seems to be a bit
flaky in some situations while curl does not.

While we're att it, switch from dash.el to cl-lib. We're going to
gradually stop needing dash.el to load config.el.
This commit is contained in:
TEC 2024-03-08 17:17:54 +08:00
parent 7af198eb87
commit 9ed12652b8
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 20 additions and 14 deletions

View File

@ -10823,20 +10823,26 @@ Now we just need to actually implement that metadata extraction function.
(cons
url
(let* ((head-data
(-filter #'listp
(cdaddr
(with-current-buffer (progn (message "Fetching metadata from %s" url)
(url-retrieve-synchronously url t t 5))
(goto-char (point-min))
(delete-region (point-min) (- (search-forward "<head") 6))
(delete-region (search-forward "</head>") (point-max))
(goto-char (point-min))
(while (re-search-forward "<script[^\u2800]+?</script>" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "<style[^\u2800]+?</style>" nil t)
(replace-match ""))
(libxml-parse-html-region (point-min) (point-max))))))
(cl-remove-if-not
#'listp
(cdaddr
(with-current-buffer
(progn (message "Fetching metadata from %s" url)
(if (executable-find "curl")
(with-current-buffer (generate-new-buffer " *curl*")
(call-process "curl" nil t nil "--max-time" "5" "-sSL" url)
(current-buffer))
(url-retrieve-synchronously url t t 5)))
(goto-char (point-min))
(delete-region (point-min) (- (search-forward "<head") 6))
(delete-region (search-forward "</head>") (point-max))
(goto-char (point-min))
(while (re-search-forward "<script[^\u2800]+?</script>" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "<style[^\u2800]+?</style>" nil t)
(replace-match ""))
(libxml-parse-html-region (point-min) (point-max))))))
(meta (delq nil
(mapcar
(lambda (tag)