blob: ffd8dedf2e62662364a6b64c33cbb35eda2ebfa4 (
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
|
#!/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.
pidof transmission-daemon >/dev/null || (transmission-daemon && notify-send "💡 Starting transmission daemon..." && sleep 3 && pkill -RTMIN+22 "${STATUSBAR:-dwmblocks}")
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"
}
|