;;; iarc.el -- internet archive client -*- lexical-binding: t -*- ;; Copyright (C) 2025 Free Software Foundation, Inc. ;; Author: Yuchen Pei ;; 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 . ;;; 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