aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rwxr-xr-xtcsv149
2 files changed, 154 insertions, 0 deletions
diff --git a/README.md b/README.md
index c42b3ea..6eb9896 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,11 @@ as command line argument or input from dmenu and consoom the media using [mpv](h
if you pass "-s" as the first argument it'll skip index selection to speed up
the launching
+## tcsv
+posix client for torrents-csv.ml, has an optional dependency on pirowatch.
+if you pass "-o" as the first argument it'll print the magnet hash to stdout
+otherwise it will pass the magnet link to pirowatch
+
## 1337x
scraper for 1337x.to, has an optional dependency on pirowatch. if you pass "-o"
as the first argument it'll print the scraped magnet link to stdout otherwise
diff --git a/tcsv b/tcsv
new file mode 100755
index 0000000..86ee8e5
--- /dev/null
+++ b/tcsv
@@ -0,0 +1,149 @@
+#!/bin/sh
+
+url_csv="https://torrents-csv.ml"
+menu="wmenu"
+
+die()
+{
+ : "${1:?}"
+
+ command -v notify-send > /dev/null &&
+ notify-send "󰎁 torrents-csv" "$1"
+
+ printf "\033[31;1merr: %b\033[0m\n" "$1"
+ exit "${2:-1}"
+}
+
+dep_check()
+{
+ : "${1:?}"
+
+ for dep; do
+ command -v "$dep" 1>/dev/null ||
+ die "${dep} not found, please install it" 127
+ done
+
+ unset dep
+}
+
+search_tcsv()
+{
+ : "${1:?}"
+ dep_check curl
+
+ curl "${url_csv}/service/search?q=$(echo "$1" | tr ' ' '+')" \
+ --silent \
+ --compressed |
+ grep -o '"[^,}]*'
+}
+
+byttounit()
+{
+ # usage: bytounuit bytes
+ : "${1:?}"
+
+ if [ "$1" -lt 1024 ]; then
+ printf "%d B" "$1"
+ elif [ "$1" -lt 1048576 ]; then
+ printf "%.1f KB" "$(echo "$1 / 1024" | bc -l)"
+ elif [ "$1" -lt 1073741824 ]; then
+ printf "%.1f MB" "$(echo "$1 / 1048576" | bc -l)"
+ elif [ "$1" -lt 1099511627776 ]; then
+ printf "%.1f GB" "$(echo "$1 / 1073741824" | bc -l)"
+ else
+ printf "BIG B"
+ fi
+}
+
+parse_table()
+{
+ # usage: echo "$fetch" | parse_table
+ name=
+ sneed=
+ leech=
+ size=
+
+ while read -r line; do
+ case "$line" in
+ \"name\":\"*)
+ name="${line#*:\"}"
+ name="${name%\"}"
+ ;;
+ \"size_bytes\":*)
+ size="$(byttounit "${line#*:}")"
+ ;;
+ \"seeders\":*)
+ sneed="${line#*:}"
+ ;;
+ \"leechers\":*)
+ leech="${line#*:}"
+ ;;
+ \"scraped_date\":*)
+ printf "%4d  %4d  %8s %s\n" \
+ "$sneed" "$leech" "$size" "$name"
+ ;;
+ esac
+ done | "$menu" -p "󰎁 " -il 25 | sed 's/.* //g'
+
+ unset name sneed leech size
+}
+
+wheremag()
+{
+ # usage: echo "$fetch" | wheremag name
+ : "${1:?}"
+
+ name=
+ magnet=
+
+ while read -r line; do
+ case "$line" in
+ \"infohash\":\"*)
+ magnet="${line#*:\"}"
+ magnet="${magnet%\"}"
+ ;;
+ \"name\":\"*)
+ name="${line#*:\"}"
+ name="${name%\"}"
+
+ if [ "$name" = "$1" ]; then
+ echo "$magnet"
+ return
+ fi
+ ;;
+ esac
+ done
+
+ unset name magnet
+}
+
+query=
+fetch=
+name=
+magnet=
+
+[ -z "$WAYLAND_DISPLAY" ] &&
+ menu="dmenu"
+if [ "$#" -gt 0 ] && [ "$1" = "-o" ]; then
+ out=true
+ shift
+fi
+dep_check "$menu"
+
+query="${*:-$(printf "" | "$menu" -p "󱇒 ")}"
+[ -z "$query" ] &&
+ exit 1
+fetch="$(search_tcsv "$query")"
+[ -z "$fetch" ] &&
+ die "search failed, check your internet connection"
+name="$(echo "$fetch" | parse_table)"
+[ -z "$name" ] &&
+ exit 1
+magnet="$(echo "$fetch" | wheremag "$name")"
+
+if [ "$out" = true ]; then
+ echo "$magnet"
+else
+ dep_check "pirowatch"
+ pirowatch "$magnet"
+fi