From 8987f5494977c5912dd912a660edbd0595d1a5bc Mon Sep 17 00:00:00 2001 From: Roland Seitz Date: Sun, 2 Jan 2022 17:38:34 +0100 Subject: [PATCH 1/5] Fix shellcheck warnings --- notflix | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/notflix b/notflix index c30a7cd..64a6758 100755 --- a/notflix +++ b/notflix @@ -2,58 +2,58 @@ # Dependencies - webtorrent, mpv -mkdir -p $HOME/.cache/notflix +mkdir -p "$HOME"/.cache/notflix menu="dmenu -i -l 25" baseurl="https://1337x.wtf" cachedir="$HOME/.cache/notflix" -if [ -z $1 ]; then +if [ -z "$1" ]; then query=$(dmenu -p "Search Torrent: " <&-) else query=$1 fi -query="$(echo $query | sed 's/ /+/g')" +query="$(echo "$query" | sed 's/ /+/g')" -#curl -s https://1337x.to/category-search/$query/Movies/1/ > $cachedir/tmp.html -curl -s $baseurl/search/$query/1/ > $cachedir/tmp.html +#curl -s https://1337x.to/category-search/"$query"/Movies/1/ > "$cachedir"/tmp.html +curl -s "$baseurl"/search/"$query"/1/ > "$cachedir"/tmp.html # Get Titles -grep -o '' "$cachedir"/tmp.html | + sed 's/<[^>]*>//g' > "$cachedir"/titles.bw -result_count=$(wc -l $cachedir/titles.bw | awk '{print $1}') +result_count=$(wc -l "$cachedir"/titles.bw | awk '{print $1}') if [ "$result_count" -lt 1 ]; then notify-send "πŸ˜” No Result found. Try again πŸ”΄" -i "NONE" exit 0 fi # Seeders and Leechers -grep -o '' $cachedir/tmp.html | - sed 's/<[^>]*>//g' | sed 'N;s/\n/ /' > $cachedir/seedleech.bw +grep -o '' "$cachedir"/tmp.html | + sed 's/<[^>]*>//g' | sed 'N;s/\n/ /' > "$cachedir"/seedleech.bw # Size -grep -o '' "$cachedir"/tmp.html | sed 's/.*<\/span>//g' | - sed -e 's/<[^>]*>//g' > $cachedir/size.bw + sed -e 's/<[^>]*>//g' > "$cachedir"/size.bw # Links -grep -E '/torrent/' $cachedir/tmp.html | +grep -E '/torrent/' "$cachedir"/tmp.html | sed -E 's#.*(/torrent/.*)/">.*/#\1#' | - sed 's/td>//g' > $cachedir/links.bw + sed 's/td>//g' > "$cachedir"/links.bw # Clearning up some data to display -sed 's/\./ /g; s/\-/ /g' $cachedir/titles.bw | - sed 's/[^A-Za-z0-9 ]//g' | tr -s " " > $cachedir/tmp && mv $cachedir/tmp $cachedir/titles.bw +sed 's/\./ /g; s/\-/ /g' "$cachedir"/titles.bw | + sed 's/[^A-Za-z0-9 ]//g' | tr -s " " > "$cachedir"/tmp && mv "$cachedir"/tmp "$cachedir"/titles.bw -awk '{print NR " - ["$0"]"}' $cachedir/size.bw > $cachedir/tmp && mv $cachedir/tmp $cachedir/size.bw -awk '{print "[S:"$1 ", L:"$2"]" }' $cachedir/seedleech.bw > $cachedir/tmp && mv $cachedir/tmp $cachedir/seedleech.bw +awk '{print NR " - ["$0"]"}' "$cachedir"/size.bw > "$cachedir"/tmp && mv "$cachedir"/tmp "$cachedir"/size.bw +awk '{print "[S:"$1 ", L:"$2"]" }' "$cachedir"/seedleech.bw > "$cachedir"/tmp && mv "$cachedir"/tmp "$cachedir"/seedleech.bw # Getting the line number -LINE=$(paste -d\ $cachedir/size.bw $cachedir/seedleech.bw $cachedir/titles.bw | +LINE=$(paste -d\ "$cachedir"/size.bw "$cachedir"/seedleech.bw "$cachedir"/titles.bw | $menu | - cut -d\- -f1 | + cut -d'-' -f1 | awk '{$1=$1; print}') if [ -z "$LINE" ]; then @@ -61,12 +61,12 @@ if [ -z "$LINE" ]; then exit 0 fi notify-send "πŸ” Searching Magnet seeds 🧲" -i "NONE" -url=$(head -n $LINE $cachedir/links.bw | tail -n +$LINE) +url=$(head -n "$LINE" "$cachedir"/links.bw | tail -n +"$LINE") fullURL="${baseurl}${url}/" # Requesting page for magnet link -curl -s $fullURL > $cachedir/tmp.html -magnet=$(grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]*" $cachedir/tmp.html | head -n 1) +curl -s "$fullURL" > "$cachedir"/tmp.html +magnet=$(grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]*" "$cachedir"/tmp.html | head -n 1) webtorrent "$magnet" --mpv From c54c4b0f009fa95dd72764819e8d7d38ab7943d6 Mon Sep 17 00:00:00 2001 From: Roland Seitz Date: Sun, 2 Jan 2022 17:39:10 +0100 Subject: [PATCH 2/5] Fix dmenu soft lock occurring on some system --- notflix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notflix b/notflix index 64a6758..ea34d31 100755 --- a/notflix +++ b/notflix @@ -9,7 +9,7 @@ baseurl="https://1337x.wtf" cachedir="$HOME/.cache/notflix" if [ -z "$1" ]; then - query=$(dmenu -p "Search Torrent: " <&-) + query=$(echo "" | dmenu -p "Search Torrent: ") else query=$1 fi From cfe36701974311e604e01d7ff4d31752b9b9b627 Mon Sep 17 00:00:00 2001 From: Roland Seitz Date: Sun, 2 Jan 2022 17:41:34 +0100 Subject: [PATCH 3/5] Align search results with column --- notflix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notflix b/notflix index ea34d31..b75770b 100755 --- a/notflix +++ b/notflix @@ -51,7 +51,8 @@ awk '{print NR " - ["$0"]"}' "$cachedir"/size.bw > "$cachedir"/tmp && mv "$cache awk '{print "[S:"$1 ", L:"$2"]" }' "$cachedir"/seedleech.bw > "$cachedir"/tmp && mv "$cachedir"/tmp "$cachedir"/seedleech.bw # Getting the line number -LINE=$(paste -d\ "$cachedir"/size.bw "$cachedir"/seedleech.bw "$cachedir"/titles.bw | +LINE=$(paste -d' ' "$cachedir"/size.bw "$cachedir"/seedleech.bw "$cachedir"/titles.bw | + column -s' ' -t | $menu | cut -d'-' -f1 | awk '{$1=$1; print}') From 4938d7b224062bf7b53ac1db4ea1ae209368e0dc Mon Sep 17 00:00:00 2001 From: Roland Seitz Date: Sun, 2 Jan 2022 17:43:07 +0100 Subject: [PATCH 4/5] Exit if no query is given --- notflix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/notflix b/notflix index b75770b..e1438ca 100755 --- a/notflix +++ b/notflix @@ -14,6 +14,11 @@ else query=$1 fi +if [ -z "$query" ]; then + notify-send "πŸ˜” No query given. Exiting... πŸ”΄" -i "NONE" + exit 0 +fi + query="$(echo "$query" | sed 's/ /+/g')" #curl -s https://1337x.to/category-search/"$query"/Movies/1/ > "$cachedir"/tmp.html @@ -61,6 +66,7 @@ if [ -z "$LINE" ]; then notify-send "πŸ˜” No Result selected. Exiting... πŸ”΄" -i "NONE" exit 0 fi + notify-send "πŸ” Searching Magnet seeds 🧲" -i "NONE" url=$(head -n "$LINE" "$cachedir"/links.bw | tail -n +"$LINE") fullURL="${baseurl}${url}/" From ff24f38efa218b3cea568e434004675f89648eaf Mon Sep 17 00:00:00 2001 From: Roland Seitz Date: Sun, 2 Jan 2022 17:52:24 +0100 Subject: [PATCH 5/5] Send "Enjoy Watching" before movie starts otherwise it will be sent only after mpv exits --- notflix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/notflix b/notflix index e1438ca..318a9dd 100755 --- a/notflix +++ b/notflix @@ -2,11 +2,11 @@ # Dependencies - webtorrent, mpv -mkdir -p "$HOME"/.cache/notflix - menu="dmenu -i -l 25" baseurl="https://1337x.wtf" -cachedir="$HOME/.cache/notflix" +cachedir=${XDG_CACHE_HOME:-$HOME/.cache/notflix} + +[ -d "$cachedir" ] && mkdir -p "$cachedir" if [ -z "$1" ]; then query=$(echo "" | dmenu -p "Search Torrent: ") @@ -75,7 +75,7 @@ fullURL="${baseurl}${url}/" curl -s "$fullURL" > "$cachedir"/tmp.html magnet=$(grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]*" "$cachedir"/tmp.html | head -n 1) -webtorrent "$magnet" --mpv - # Simple notification notify-send "πŸŽ₯ Enjoy Watching ☺️ " -i "NONE" + +webtorrent "$magnet" --mpv