blob: a412aa31c31088013e77c86d99971c65e1da8812 (
plain) (
blame)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
;;; iarc.el -- internet archive client -*- lexical-binding: t -*-
;; Copyright (C) 2025 Free Software Foundation, Inc.
;; Author: Yuchen Pei <id@ypei.org>
;; Package-Requires: ((emacs "30.1"))
;; This file is part of dotted.
;; dotted is free software: you can redistribute it and/or modify it under
;; the terms of the GNU Affero General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; dotted is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
;; Public License for more details.
;; You should have received a copy of the GNU Affero General Public
;; License along with dotted. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; internet archive client.
;;; Code:
(define-derived-mode iarc-mode tabulated-list-mode "IArc"
(hl-line-mode 1)
(setq tabulated-list-format
[("★ " 3 iarc-compare-favourites :right-align t)
("Title" 60 t)])
(setq tabulated-list-padding 2)
(tabulated-list-init-header)
(setq revert-buffer-function #'iarc-list-refresh))
(defvar iarc-search-dataset nil)
(defun iarc-compare-favourites (x y)
(> (let-alist (car x) (or .fields.num_favorites 0))
(let-alist (car y) (or .fields.num_favorites 0))))
(defun iarc-list-print-entry (info)
(let-alist (alist-get 'fields info)
(list info (vector (format "%d" (or .num_favorites 0))
.title))))
(defun iarc-list-refresh (&rest _)
(interactive)
(setq tabulated-list-entries
(seq-map 'iarc-list-print-entry iarc-search-dataset))
(tabulated-list-print))
(defun iarc ()
(let ((buf (get-buffer-create "*IArc*")))
(with-current-buffer buf
(iarc-mode)
(iarc-list-refresh))
(pop-to-buffer-same-window buf)))
(defvar iarc-host "https://archive.org")
(defun iarc-api-search (query)
(my-url-fetch-json
(format "%s/services/search/beta/page_production/?user_query=title:(%s)&hits_per_page=100&page=1&aggregations=false"
iarc-host query)))
(defun iarc-search (query)
(setq iarc-search-dataset (let-alist (iarc-api-search query)
.response.body.hits.hits))
(iarc))
(provide 'iarc)
;;; iarc.el ends here
|