From d270b26aaf3543546ba96d0ae2073a6e3cf7ff1a Mon Sep 17 00:00:00 2001 From: Akater Date: Sat, 3 Feb 2018 21:30:21 +0000 Subject: [PATCH 01/16] try to recognise magnet links; insert automatically on success --- transmission.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/transmission.el b/transmission.el index ad056e7..2e8cb18 100644 --- a/transmission.el +++ b/transmission.el @@ -1098,6 +1098,11 @@ 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) + (let ((magnet-link-string-indicator "magnet:?xt=")) + (string-equal magnet-link-string-indicator + (substring string 0 (length magnet-link-string-indicator))))) + ;; Interactive @@ -1108,10 +1113,17 @@ When called with a prefix, prompt for DIRECTORY." (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 From affb2db38039045c37144e3db8d79621d28b728b Mon Sep 17 00:00:00 2001 From: Akater Date: Sat, 3 Feb 2018 21:38:52 +0000 Subject: [PATCH 02/16] type-check magnet link candidate --- transmission.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/transmission.el b/transmission.el index 2e8cb18..2d616c7 100644 --- a/transmission.el +++ b/transmission.el @@ -1099,9 +1099,10 @@ WINDOW with `window-start' and the line/column coordinates of `point'." (unless ,old-mark-active (deactivate-mark))))) (defun looks-like-a-magnet-link-p (string) - (let ((magnet-link-string-indicator "magnet:?xt=")) - (string-equal magnet-link-string-indicator - (substring string 0 (length magnet-link-string-indicator))))) + (and (stringp string) + (let ((magnet-link-string-indicator "magnet:?xt=")) + (string-equal magnet-link-string-indicator + (substring string 0 (length magnet-link-string-indicator)))))) ;; Interactive From c3e0f563766a51e2b55b22ab8616ac2e5b28ea66 Mon Sep 17 00:00:00 2001 From: Akater Date: Sat, 3 Feb 2018 21:55:19 +0000 Subject: [PATCH 03/16] looks-like-a-magnet-link-p should not fail on short strings --- transmission.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/transmission.el b/transmission.el index 2d616c7..5721147 100644 --- a/transmission.el +++ b/transmission.el @@ -1102,7 +1102,9 @@ WINDOW with `window-start' and the line/column coordinates of `point'." (and (stringp string) (let ((magnet-link-string-indicator "magnet:?xt=")) (string-equal magnet-link-string-indicator - (substring string 0 (length magnet-link-string-indicator)))))) + (substring string 0 + (min (length string) + (length magnet-link-string-indicator))))))) ;; Interactive From 5fad0af72118c8d96fa69a3d9b492297e4f72940 Mon Sep 17 00:00:00 2001 From: Akater Date: Sat, 3 Feb 2018 22:48:54 +0000 Subject: [PATCH 04/16] Clarified interactive use with magnet links in docstring. --- transmission.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/transmission.el b/transmission.el index 5721147..1c4334d 100644 --- a/transmission.el +++ b/transmission.el @@ -1112,7 +1112,9 @@ WINDOW with `window-start' and the line/column coordinates of `point'." ;;;###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, magnet link will be fetched from the top +kill ring entry." (interactive (let* ((f (transmission-collect-hook 'transmission-torrent-functions)) (def (mapcar #'file-relative-name f)) From 2c2570747c0a226c15ebed011395819bb62566f3 Mon Sep 17 00:00:00 2001 From: Akater Date: Sat, 3 Feb 2018 22:59:37 +0000 Subject: [PATCH 05/16] Corrected the description of interactive use in docstring. --- transmission.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transmission.el b/transmission.el index 1c4334d..5bfb64c 100644 --- a/transmission.el +++ b/transmission.el @@ -1113,8 +1113,8 @@ WINDOW with `window-start' and the line/column coordinates of `point'." (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 used -interactively, magnet link will be fetched from the top -kill ring entry." +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)) From 7e8c3690bb54bd8c3ff89b89092ccaa94e116652 Mon Sep 17 00:00:00 2001 From: Mark Oteiza Date: Sun, 10 Jun 2018 19:53:33 -0400 Subject: [PATCH 06/16] disable line breaking in base64-encode-string assimilated from a bug fix in elisp-json-rpc --- transmission.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transmission.el b/transmission.el index ad056e7..e886aca 100644 --- a/transmission.el +++ b/transmission.el @@ -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." @@ -1127,7 +1127,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) From ba567b12a1e953880c6e7083963c52556cdc567f Mon Sep 17 00:00:00 2001 From: Mark Oteiza Date: Sat, 28 Jul 2018 13:17:35 -0400 Subject: [PATCH 07/16] pcase-exhaustive does not exist in 24.5 it was added in emacs commit 85b3d352c for bug#16567, and so was not in a release until emacs 25. cl-ecase is ok, though not fond of its use of eql --- transmission.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/transmission.el b/transmission.el index e886aca..99b8f8a 100644 --- a/transmission.el +++ b/transmission.el @@ -1625,9 +1625,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 +1989,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 From bbe4077b89afe732d346eeed1ad0783537f33480 Mon Sep 17 00:00:00 2001 From: Mark Oteiza Date: Sat, 28 Jul 2018 13:22:27 -0400 Subject: [PATCH 08/16] change a link to https --- README.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.org b/README.org index 4d53a29..0857a73 100644 --- a/README.org +++ b/README.org @@ -15,7 +15,7 @@ commentary in =transmission.el=. * Installation -Available as the =transmission= package on MELPA +Available as the =transmission= package on MELPA and marmalade . One can install as a package with From 0b926f445df19117e83e538b50c392fe7f931b8b Mon Sep 17 00:00:00 2001 From: Mark Oteiza Date: Tue, 1 Jan 2019 04:22:56 -0500 Subject: [PATCH 09/16] happy new year --- transmission.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transmission.el b/transmission.el index 99b8f8a..a2a4757 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 From 4aae3a4b56f60a416002d7ce4282bd44e0178b54 Mon Sep 17 00:00:00 2001 From: Mark Oteiza Date: Sun, 6 Jan 2019 23:08:26 -0500 Subject: [PATCH 10/16] new (better?) predicate for sorting by ETA --- transmission.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/transmission.el b/transmission.el index a2a4757..7d97982 100644 --- a/transmission.el +++ b/transmission.el @@ -2023,11 +2023,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 +2305,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) From 7293beeb8a49cf6822abd16a9f4b9e4bef0a9296 Mon Sep 17 00:00:00 2001 From: Mark Oteiza Date: Sun, 10 Feb 2019 21:46:43 -0500 Subject: [PATCH 11/16] update some urls * transmission-remote source moved * marmalade is dead --- README.org | 8 +------- transmission.el | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/README.org b/README.org index 0857a73..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 7d97982..06c89eb 100644 --- a/transmission.el +++ b/transmission.el @@ -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: -;; +;; ;; ;; From 85a1a45d2e33eef4e359bd140fc21446ced905bc Mon Sep 17 00:00:00 2001 From: Akater Date: Sat, 3 Feb 2018 21:30:21 +0000 Subject: [PATCH 12/16] try to recognise magnet links; insert automatically on success --- transmission.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/transmission.el b/transmission.el index 06c89eb..5bb1c78 100644 --- a/transmission.el +++ b/transmission.el @@ -1098,6 +1098,11 @@ 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) + (let ((magnet-link-string-indicator "magnet:?xt=")) + (string-equal magnet-link-string-indicator + (substring string 0 (length magnet-link-string-indicator))))) + ;; Interactive @@ -1108,10 +1113,17 @@ When called with a prefix, prompt for DIRECTORY." (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 From a822a40180c93985de0037a59c0a0f643b95034f Mon Sep 17 00:00:00 2001 From: Akater Date: Sat, 3 Feb 2018 21:38:52 +0000 Subject: [PATCH 13/16] type-check magnet link candidate --- transmission.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/transmission.el b/transmission.el index 5bb1c78..ee558b7 100644 --- a/transmission.el +++ b/transmission.el @@ -1099,9 +1099,10 @@ WINDOW with `window-start' and the line/column coordinates of `point'." (unless ,old-mark-active (deactivate-mark))))) (defun looks-like-a-magnet-link-p (string) - (let ((magnet-link-string-indicator "magnet:?xt=")) - (string-equal magnet-link-string-indicator - (substring string 0 (length magnet-link-string-indicator))))) + (and (stringp string) + (let ((magnet-link-string-indicator "magnet:?xt=")) + (string-equal magnet-link-string-indicator + (substring string 0 (length magnet-link-string-indicator)))))) ;; Interactive From bc34ed41a0a7f9055e26f9a5ef921dc645a10ce6 Mon Sep 17 00:00:00 2001 From: Akater Date: Sat, 3 Feb 2018 21:55:19 +0000 Subject: [PATCH 14/16] looks-like-a-magnet-link-p should not fail on short strings --- transmission.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/transmission.el b/transmission.el index ee558b7..a0cc8dd 100644 --- a/transmission.el +++ b/transmission.el @@ -1102,7 +1102,9 @@ WINDOW with `window-start' and the line/column coordinates of `point'." (and (stringp string) (let ((magnet-link-string-indicator "magnet:?xt=")) (string-equal magnet-link-string-indicator - (substring string 0 (length magnet-link-string-indicator)))))) + (substring string 0 + (min (length string) + (length magnet-link-string-indicator))))))) ;; Interactive From 8ebda17dc82ab8a954a97700089092ab63eaacaa Mon Sep 17 00:00:00 2001 From: Akater Date: Sat, 3 Feb 2018 22:48:54 +0000 Subject: [PATCH 15/16] Clarified interactive use with magnet links in docstring. --- transmission.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/transmission.el b/transmission.el index a0cc8dd..86be8fd 100644 --- a/transmission.el +++ b/transmission.el @@ -1112,7 +1112,9 @@ WINDOW with `window-start' and the line/column coordinates of `point'." ;;;###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, magnet link will be fetched from the top +kill ring entry." (interactive (let* ((f (transmission-collect-hook 'transmission-torrent-functions)) (def (mapcar #'file-relative-name f)) From eae16683499e489bd6b79efb5ccbf9c9320b9841 Mon Sep 17 00:00:00 2001 From: Akater Date: Sat, 3 Feb 2018 22:59:37 +0000 Subject: [PATCH 16/16] Corrected the description of interactive use in docstring. --- transmission.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transmission.el b/transmission.el index 86be8fd..33bba59 100644 --- a/transmission.el +++ b/transmission.el @@ -1113,8 +1113,8 @@ WINDOW with `window-start' and the line/column coordinates of `point'." (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 used -interactively, magnet link will be fetched from the top -kill ring entry." +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))