Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dmenu soft lock; shellcheck; minor enhancements #34

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions notflix
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,71 @@

# 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')"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is best not to put quotes around this query variable. Without quotes, if the user entered something like " Suicide Squad " with a bunch of leading and trailing whitespaces, echoing it would automatically remove the leading and trailing spaces and only the space between the words would get replaced by plus sign in the following sed command. So, the output query would be "Suicide+Squad".

Whereas, if you put quotes around the query variable while echoing, it wouldn't remove the extra spaces and all those extra spaces would get converted to plus signs in the following sed command. In this case the output query would be something like "++++++Suicide+Squad++++"


#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 '<a href="/torrent/.*</a>' $cachedir/tmp.html |
sed 's/<[^>]*>//g' > $cachedir/titles.bw
grep -o '<a href="/torrent/.*</a>' "$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 '<td class="coll-2 seeds.*</td>\|<td class="coll-3 leeches.*</td>' $cachedir/tmp.html |
sed 's/<[^>]*>//g' | sed 'N;s/\n/ /' > $cachedir/seedleech.bw
grep -o '<td class="coll-2 seeds.*</td>\|<td class="coll-3 leeches.*</td>' "$cachedir"/tmp.html |
sed 's/<[^>]*>//g' | sed 'N;s/\n/ /' > "$cachedir"/seedleech.bw

# Size
grep -o '<td class="coll-4 size.*</td>' $cachedir/tmp.html |
grep -o '<td class="coll-4 size.*</td>' "$cachedir"/tmp.html |
sed 's/<span class="seeds">.*<\/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
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)
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

Expand Down