aboutsummaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/my/my-calibre.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/lisp/my/my-calibre.el')
-rw-r--r--.emacs.d/lisp/my/my-calibre.el83
1 files changed, 0 insertions, 83 deletions
diff --git a/.emacs.d/lisp/my/my-calibre.el b/.emacs.d/lisp/my/my-calibre.el
deleted file mode 100644
index e12028b..0000000
--- a/.emacs.d/lisp/my/my-calibre.el
+++ /dev/null
@@ -1,83 +0,0 @@
-;;; my-calibre.el -- Calibre client -*- lexical-binding: t -*-
-
-;; Copyright (C) 2023 Free Software Foundation.
-
-;; Author: Yuchen Pei <id@ypei.org>
-;; Package-Requires: ((emacs "28.2"))
-
-;; This file is part of dotfiles.
-
-;; dotfiles 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.
-
-;; dotfiles 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 dotfiles. If not, see
-;; <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Calibre client.
-
-;;; Code:
-
-
-(defun org-attach-calibre-book (id)
- "Attach a calibre book with ID to the current org entry."
- (interactive "sCalibre book id: ")
- (let ((export-dir (org-attach-dir t)
- ))
- (call-process-shell-command
- (format "mkdir -p %s && calibredb export --dont-asciiize \\
- --replace-whitespace --single-dir --to-dir %s %s" export-dir export-dir id)
- nil "*calibredb*")
- (org-attach-sync)))
-
-;; the following should be adapted to a capture so that one can fix anything
-;; erroneous before refiling and attaching
-;; fixme: the following should be decoupled from org maybe
-(defun create-calibre-book-node (id)
- (interactive "sCalibre book ID: ")
- ;; 1. get book metadata from calibredb
- ;; 1.1. run calibredb to get metadata
- (ignore-errors (kill-buffer "*calibredb*"))
- (if (= 0
- (call-process-shell-command
- (concat "calibredb show_metadata " id) nil "*calibredb*"))
- ;; 1.2. parse the metadata to get author, title and year
- (let ((book-info (my-parse-colon-separated-output "*calibredb*")))
- ;; 2. create the node and attach it under books and papers
- ;; 2.1 create a new node
- (kill-buffer "*calibredb*")
- (org-capture nil "book")
- (insert (format
- "%s - %s - [%s]"
- (let ((full-author (alist-get "Authors" book-info nil nil 'string=)))
- ;; (pp book-info)
- (substring full-author
- (1+ (string-match "\\[.*\\]" full-author))
- (1- (match-end 0))))
- (alist-get "Title" book-info nil nil 'string=)
- (substring (alist-get "Published" book-info nil nil 'string=) 0 10)))
- ;; 2.2 use org-entry-put to add all the properties
- (dolist (pair book-info)
- (org-entry-put (point-min) (car pair) (cdr pair)))
- (attach-calibre-book id))
- (error (format "Cannot find book %s!" id))))
-
-(defun my-calibredb-search (query)
- (interactive "scalibredb search query: ")
- (ignore-errors (kill-buffer "*calibredb*"))
- (call-process-shell-command
- (format "calibredb search %s | xargs -d, -i sh -c 'echo ID: {} && calibredb show_metadata {}'" query)
- nil "*calibredb*")
- (switch-to-buffer "*calibredb*"))
-
-(provide 'my-calibre)
-;;; my-calibre.el ends here