diff --git a/notflix b/notflix index c30a7cd..318a9dd 100755 --- a/notflix +++ b/notflix @@ -2,73 +2,80 @@ # 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=$(dmenu -p "Search Torrent: " <&-) +if [ -z "$1" ]; then + query=$(echo "" | dmenu -p "Search Torrent: ") else query=$1 fi -query="$(echo $query | sed 's/ /+/g')" +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 -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 | + column -s' ' -t | $menu | - cut -d\- -f1 | + cut -d'-' -f1 | awk '{$1=$1; print}') 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) +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) - -webtorrent "$magnet" --mpv +curl -s "$fullURL" > "$cachedir"/tmp.html +magnet=$(grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]*" "$cachedir"/tmp.html | head -n 1) # Simple notification notify-send "πŸŽ₯ Enjoy Watching ☺️ " -i "NONE" + +webtorrent "$magnet" --mpv