1 ;;; org-tag-eldoc-pixiv-encyclopedia.el --- Web Scraping on Pixiv Encyclopedia -*- lexical-binding: t; -*-
2 ;; -*- coding: utf-8 -*-
4 ;; Copyright (C) 2024-2025 Christopher M. Miles, all rights reserved.
8 ;; search API: https://dic.pixiv.net/en/search?query=[query]
9 ;; tag URL: https://dic.pixiv.net/en/a/Mating%20Press
14 (require 'url-http
) ; for `url-http-end-of-headers'
17 (require 'elquery nil t
) ; optionally use elquery.el to replace dom.el.
18 (require 'org-tag-eldoc-common
)
21 (defun org-tag-eldoc-pixiv-encyclopedia--request (tag)
22 "Send HTTP GET request to get TAG explanation data."
23 (let ((request-backend 'url-retrieve
) ; use `url-retrieve' backend for proxy.
24 (url-proxy-services org-tag-eldoc-request-proxy
)
25 (url (format "https://dic.pixiv.net/en/a/%s"
27 (string-replace "_" " " (capitalize tag
))))))
32 ((fboundp 'libxml-parse-html-region
) ; convert HTML -> Elisp alist structure
33 (libxml-parse-html-region (point-min) (point-max)))
34 ((featurep 'elquery
) ; convert HTML -> elquery object structure
35 (elquery-read-buffer (current-buffer)))))
37 (lambda (&key data
&allow-other-keys
)
38 ;; DEBUG: (setq request-result data)
41 ;; for `libxml' parser
42 (setq org-tag-eldoc--explanation
43 (org-tag-eldoc-common--format-explanation
44 (dom-text (car (dom-by-class data
"summary"))))))
46 ;; for `elquery' parser
47 (setq org-tag-eldoc--explanation
48 (org-tag-eldoc-common--format-explanation
49 (elquery-text (car (elquery-$
".summary" data
)))))))))
51 (lambda (&rest args
&key error-thrown
&allow-other-keys
)
52 (error "[org-tag-eldoc] (Pixiv Encyclopedia) request error %s!" error-thrown
)
54 :status-code
'((404 .
(lambda (&rest _
) nil
))
55 (500 .
(lambda (&rest _
) nil
))))))
57 ;;; TEST: https://dic.pixiv.net/en/a/Mating%20Press
58 ;; (org-tag-eldoc-pixiv-encyclopedia--request "mating_press")
60 (defun org-tag-eldoc-pixiv-encyclopedia-query (tag)
61 "Query TAG on Pixiv Encyclopedia then return a cons cell of tag and explanation."
62 ;; search: https://dic.pixiv.net/en/search?query=<tag>
63 ;; tag page: https://dic.pixiv.net/en/a/<url%20hex%20coded%20tag>
64 (if (stringp org-tag-eldoc--explanation
)
65 org-tag-eldoc--explanation
66 (org-tag-eldoc-pixiv-encyclopedia--request tag
)
68 (org-tag-eldoc-database-save tag org-tag-eldoc--explanation
)))
72 (provide 'org-tag-eldoc-pixiv-encyclopedia
)
74 ;;; org-tag-eldoc-pixiv-encyclopedia.el ends here