blob: c6d2e945cc079920bf1aa0c19e004a0cd507b241 (
plain)
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
|
#!/bin/sh
# Mimeapp script for adding torrent to transmission-daemon, but will also start the daemon first if not running.
# transmission-daemon sometimes fails to take remote requests in its first moments, hence the sleep.
pgrep -x transmission-daemon >/dev/null 2>&1 || (
transmission-daemon &&
osascript -e 'display notification "💡 Starting transmission daemon..." with title "transmission-daemon"'
)
directory="$HOME/Torrents"
[ "$1" = "-l" ] && {
URL=$(xclip -selection clipboard -o)
case "$URL" in
http://* | https://* | magnet:?*)
transmission-remote -a "$URL" && notify-send "🔽 Torrent added."
exit 0
;;
*)
added_torrents=$(transmission-remote -l | grep -vE '^ID|Sum' | awk '{print $NF}' | sed 's/\.torrent$//')
filtered_files=$(ls "$directory"/*.torrent 2>/dev/null | sed "s|^$directory/||" | sed 's/\.torrent$//' | grep -vF "$added_torrents")
[ -n "$filtered_files" ] && {
choice=$(echo "$filtered_files" | dmenu -i -l 20 -p "Select Torrent:")
[ -n "$choice" ] && transmission-remote -a "$directory/$choice.torrent" && notify-send "🔽 Torrent added."
} || notify-send "🤷 No new torrent found."
;;
esac
} || {
transmission-remote -a "$@" && notify-send "🔽 Torrent added." "$TR_TORRENT_NAME"
}
|