aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <pcmsinan@gmail.com>2023-03-08 15:02:53 +0530
committersinanmohd <pcmsinan@gmail.com>2023-03-11 19:05:05 +0530
commitfaae5f57edd6cdee64c185164011cb4b789c7ee6 (patch)
treef9b1240cdda7915ffcd6f0c40f18f5fba03a1f55
parenta63bb259b71f3470093cf19d46aa8b7cf17cfd0d (diff)
pirowatch: wayland support, make notify-send an optional dependency
-rwxr-xr-xpirowatch29
1 files changed, 20 insertions, 9 deletions
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" ] ||