-
Notifications
You must be signed in to change notification settings - Fork 1
/
my-transmission.el
81 lines (69 loc) · 2.37 KB
/
my-transmission.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;;; my-transmission --- Tweaks for Transmission
;;
;; Copyright (C) 2014 Alex Bennée
;;
;; Author: Alex Bennée <[email protected]>
;;
;; This file is not part of GNU Emacs.
;;
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;;; Commentary:
;;
;; A couple of simple customisations to feed stuff into transmission.
;; Either I select torrent files from dired or I can enque an
;; enclosure directly from elfeed.
;;
;;; Code:
; Require prerequisites
(require 'use-package)
(require 's)
;; Variables
;; Code
(defun my-narrow-to-pure-magnet ()
"From point remove any extraneous information from the magnet link.
Returns the line as a string."
(interactive)
(when (thing-at-point 'url)
(save-excursion
(move-beginning-of-line nil)
(when (re-search-forward "&tr" nil t)
(forward-line 1)
(delete-region (match-beginning 0) (point)))
(move-beginning-of-line nil)
(substring-no-properties (thing-at-point 'line)))))
(defun my-snarf-magnet ()
"Snarf a link into transmission."
(interactive)
(when (thing-at-point 'url)
(transmission-add (my-narrow-to-pure-magnet))))
(defun my-enable-torrent-snarfing ()
"Bind torrent snarfing to action key."
(interactive)
(local-set-key (kbd "C-c C-c") 'my-snarf-magnet))
(defun my-dired-add-to-transmission ()
"Add all marked files to transmission."
(interactive)
(-map 'transmission-add (dired-get-marked-files)))
(defun my-add-first-elfeed-enclosure-to-transmission ()
"Queue the first enclosure (if it is a torrent)."
(interactive)
(let ((enclosures (elfeed-entry-enclosures elfeed-show-entry)))
(when (and enclosures
(string-match-p
"application/x-bittorrent"
(nth 1 (-first-item enclosures))))
(transmission-add (-first-item (-first-item enclosures))))))
(use-package transmission
:ensure t
:commands transmission-add
:bind (:map elfeed-show-mode-map
("C-c C-c" . my-add-first-elfeed-enclosure-to-transmission))
:config (setq transmission-rpc-auth
'(:username "transmission" :password "transmission")
elfeed-enclosure-default-dir "~/torrent/"))
(provide 'my-transmission)
;;; my-transmission.el ends here