diff --git a/README.org b/README.org index 4d53a29..9b5ae68 100644 --- a/README.org +++ b/README.org @@ -8,15 +8,9 @@ commentary in =transmission.el=. #+NAME: fig:example [[./example.png]] -# * About -# https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt -# https://github.com/fagga/transmission-remote-cli -# https://trac.transmissionbt.com/browser/trunk/daemon/remote.c - * Installation -Available as the =transmission= package on MELPA -and marmalade . +Available as the =transmission= package on MELPA . One can install as a package with diff --git a/transmission.el b/transmission.el index ad056e7..33bba59 100644 --- a/transmission.el +++ b/transmission.el @@ -1,6 +1,6 @@ ;;; transmission.el --- Interface to a Transmission session -*- lexical-binding: t -*- -;; Copyright (C) 2014-2018 Mark Oteiza +;; Copyright (C) 2014-2019 Mark Oteiza ;; Author: Mark Oteiza ;; Version: 0.12.1 @@ -50,7 +50,7 @@ ;; line utility transmission-remote(1), the ncurses interface ;; transmission-remote-cli(1), and the rtorrent(1) client. These can ;; be found respectively at the following: -;; +;; ;; ;; @@ -395,7 +395,7 @@ and port default to `transmission-host' and (let* ((user (plist-get transmission-rpc-auth :username)) (pass (and user (or (plist-get transmission-rpc-auth :password) (transmission--auth-source-secret user))))) - (concat "Basic " (base64-encode-string (concat user ":" pass)))))) + (concat "Basic " (base64-encode-string (concat user ":" pass) t))))) (defun transmission-http-post (process content) "Send to PROCESS an HTTP POST request containing CONTENT." @@ -1098,20 +1098,37 @@ WINDOW with `window-start' and the line/column coordinates of `point'." (and ,old-mark (set-mark ,old-mark)) (unless ,old-mark-active (deactivate-mark))))) +(defun looks-like-a-magnet-link-p (string) + (and (stringp string) + (let ((magnet-link-string-indicator "magnet:?xt=")) + (string-equal magnet-link-string-indicator + (substring string 0 + (min (length string) + (length magnet-link-string-indicator))))))) + ;; Interactive ;;;###autoload (defun transmission-add (torrent &optional directory) "Add TORRENT by filename, URL, magnet link, or info hash. -When called with a prefix, prompt for DIRECTORY." +When called with a prefix, prompt for DIRECTORY. When used +interactively, will try to fetch magnet link +from `transmission-torrent-functions'." (interactive (let* ((f (transmission-collect-hook 'transmission-torrent-functions)) (def (mapcar #'file-relative-name f)) - (prompt (concat "Add torrent" (if def (format " [%s]" (car def))) ": ")) + (car-def (car def)) + (magnet-link-is-recognised (looks-like-a-magnet-link-p car-def)) + (prompt (concat "Add torrent" + (if (and def (not magnet-link-is-recognised)) + (format " [%s]" car-def)) + ": ")) (history-add-new-input nil) (file-name-history (symbol-value transmission-add-history-variable)) - (input (read-file-name prompt nil def))) + (input (if magnet-link-is-recognised + car-def + (read-file-name prompt nil def)))) (add-to-history transmission-add-history-variable input) (list input (if current-prefix-arg @@ -1127,7 +1144,7 @@ When called with a prefix, prompt for DIRECTORY." (append (if (and (file-readable-p torrent) (not (file-directory-p torrent))) `(:metainfo ,(with-temp-buffer (insert-file-contents-literally torrent) - (base64-encode-string (buffer-string)))) + (base64-encode-string (buffer-string) t))) (setq torrent (string-trim torrent)) `(:filename ,(if (transmission-btih-p torrent) (concat "magnet:?xt=urn:btih:" torrent) @@ -1625,9 +1642,9 @@ Otherwise, with a prefix arg, mark files on the next ARG lines." "Toggle mark on all items." (interactive) (let ((inhibit-read-only t) ids tag key) - (when (setq key (pcase-exhaustive major-mode - (`transmission-mode 'id) - (`transmission-files-mode 'index))) + (when (setq key (cl-ecase major-mode + (transmission-mode 'id) + (transmission-files-mode 'index))) (save-excursion (save-restriction (widen) @@ -1989,9 +2006,9 @@ torrent is marked. ID is a Lisp object identifying the entry to print, and COLS is a vector of column descriptors." (tabulated-list-print-entry id cols) - (let* ((key (pcase-exhaustive major-mode - (`transmission-mode 'id) - (`transmission-files-mode 'index))) + (let* ((key (cl-ecase major-mode + (transmission-mode 'id) + (transmission-files-mode 'index))) (item-id (cdr (assq key id)))) (when (memq item-id transmission-marked-ids) (save-excursion @@ -2023,11 +2040,15 @@ is constructed from TEST, BODY and the `tabulated-list-id' tagged as `<>'." (define-transmission-predicate download>? > (cdr (assq 'rateToClient <>))) (define-transmission-predicate upload>? > (cdr (assq 'rateToPeer <>))) (define-transmission-predicate size>? > (cdr (assq 'length <>))) -(define-transmission-predicate eta>? > (cdr (assq 'eta <>))) (define-transmission-predicate size-when-done>? > (cdr (assq 'sizeWhenDone <>))) (define-transmission-predicate percent-done>? > (cdr (assq 'percentDone <>))) (define-transmission-predicate ratio>? > (cdr (assq 'uploadRatio <>))) +(define-transmission-predicate eta>=? >= + (let-alist <> + (if (>= .eta 0) .eta + (- 1.0 .percentDone)))) + (defvar transmission-peers-mode-map (let ((map (make-sparse-keymap))) (define-key map "i" 'transmission-info) @@ -2301,7 +2322,7 @@ Transmission." :group 'transmission (setq-local line-move-visual nil) (setq tabulated-list-format - [("ETA" 4 transmission-eta>? :right-align t) + [("ETA" 4 transmission-eta>=? :right-align t) ("Size" 9 transmission-size-when-done>? :right-align t :transmission-size t) ("Have" 4 transmission-percent-done>? :right-align t)