Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://melpa.org/>
and marmalade <https://marmalade-repo.org/>.
Available as the =transmission= package on MELPA <https://melpa.org/>.

One can install as a package with

Expand Down
51 changes: 36 additions & 15 deletions transmission.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;; transmission.el --- Interface to a Transmission session -*- lexical-binding: t -*-

;; Copyright (C) 2014-2018 Mark Oteiza <mvoteiza@udel.edu>
;; Copyright (C) 2014-2019 Mark Oteiza <mvoteiza@udel.edu>

;; Author: Mark Oteiza <mvoteiza@udel.edu>
;; Version: 0.12.1
Expand Down Expand Up @@ -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:
;; <https://github.com/transmission/transmission/blob/master/daemon/remote.c>
;; <https://github.com/transmission/transmission/blob/master/utils/remote.c>
;; <https://github.com/fagga/transmission-remote-cli>
;; <https://rakshasa.github.io/rtorrent/>

Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down