torrents.csv/search.sh

28 lines
884 B
Bash
Executable File

#!/bin/bash
torrent_csv_file="`pwd`/torrents.csv"
search_string=${1// /.*} # turn multiple string regexes into i.*am.*spartacus
search=$(grep -i "$search_string" $torrent_csv_file)
# Sort results by seeders
search=$(echo -e "$search" | sort --field-separator=';' --key=5 -g)
if [ -z "$search" ]; then
echo "No results found"
else
# Read the lines of the results
while read -r line; do
infohash=$(echo -e "$line" | cut -d ';' -f1)
magnet_link="magnet:?xt=urn:btih:$infohash"
name=$(echo -e "$line" | cut -d ';' -f2)
seeders=$(echo -e "$line" | cut -d ';' -f5)
size_bytes=$(echo -e "$line" | cut -d ';' -f3)
size=$(~/.local/bin/humanfriendly -s $size_bytes) # This slows down the results a bit
# Construct the search result
result="$name\n\tseeders: $seeders\n\tsize: $size\n\tlink: $magnet_link"
echo -e "$result"
done <<< "$search"
fi