From faae5f57edd6cdee64c185164011cb4b789c7ee6 Mon Sep 17 00:00:00 2001
From: sinanmohd <pcmsinan@gmail.com>
Date: Wed, 8 Mar 2023 15:02:53 +0530
Subject: pirowatch: wayland support, make notify-send an optional dependency

---
 pirowatch | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

(limited to 'pirowatch')

diff --git a/pirowatch b/pirowatch
index f75949a..8cbe346 100755
--- a/pirowatch
+++ b/pirowatch
@@ -4,17 +4,18 @@
 cache_dir="${XDG_CACHE_HOME:-${HOME}/.cache}/pirowatch"
 # dir where torrent files are stored
 torrent_dir="${DOWNLOADS:-$HOME/Downloads}"
-# torrent port
 torrent_port=49110
-# dht port
 dht_port=49130
+menu="dmenu"
 
 die()
 {
 	# usage: die "reason" [exit_status]
 	: "${1:?}"
 
-	notify-send "  pirowatch" "$1"
+	command -v "notify-send" 1>/dev/null &&
+		notify-send "  pirowatch" "$1"
+
 	printf "\033[31;1merr: %b\033[0m\n" "$1"
 	exit "${2:-1}"
 }
@@ -36,7 +37,10 @@ stream() {
 	# usage: stream "torrent"
 	: "${1:?}"
 
-	notify-send " connecting to peers" "wait for few seconds"
+	dep_check "webtorrent" "mpv"
+
+	command -v "notify-send" 1>/dev/null &&
+		notify-send " connecting to peers" "wait for few seconds"
 
 	if [ -n "$2" ]
 	then
@@ -53,11 +57,13 @@ set_index() {
 	# usage: get_index "torrent"
 	: "${1:?}"
 
-        fetch=$(webtorrent --mpv -o "$cache_dir" --torrent-port "$torrent_port" --dht-port "$dht_port" "$1" --select |
+	dep_check "webtorrent" "$menu"
+
+	fetch=$(webtorrent -o "$cache_dir" --torrent-port "$torrent_port" --dht-port "$dht_port" "$1" --select |
 		grep -Ei "\.(mkv|mp4|webm|avi|mov|flv|flac|opus|ogg|mp3|wav) (.*)$")
-        if [ "$(echo "$fetch" | wc -l)" -gt 1 ]
+	if [ "$(echo "$fetch" | wc -l)" -gt 1 ]
 	then
-		fetch="$(printf "%s" "$fetch" | dmenu -p "  " -l 25)" ||
+		fetch="$(printf "%s" "$fetch" | "$menu" -p "  " -l 25)" ||
 			die "empty selection" 66
 	fi
 
@@ -68,15 +74,20 @@ set_index() {
 
 main()
 {
+	torrent=
 	index="tobeset"
+
 	if [ "$1" = "-s" ]
 	then
 		index=
 		shift
 	fi
-	torrent="${1:-$torrent_dir/$(find "$torrent_dir" -type f -name "*.torrent" | sed 's/.*\///g' | dmenu -p "  " -l 25)}"
+	[ -z "$DISPLAY" ] &&
+		menu="bemenu"
+
+	dep_check "$menu"
 
-	dep_check "webtorrent" "mpv" "notify-send"
+	torrent="${1:-$torrent_dir/$(find "$torrent_dir" -type f -name "*.torrent" | sed 's/.*\///g' | "$menu" -p "  " -l 25)}"
 	[ -z "${torrent##"${torrent_dir}"/}" ] &&
 		die "magnet or torrent file not entered" 66
 	[ -d "$cache_dir" ] ||
-- 
cgit v1.2.3