From 280a2de146ecec36cdec32908b79781412eb691f Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Wed, 31 May 2023 23:36:37 +0530 Subject: tcsv: better error handling --- tcsv | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'tcsv') diff --git a/tcsv b/tcsv index 86ee8e5..66e7a6d 100755 --- a/tcsv +++ b/tcsv @@ -33,8 +33,8 @@ search_tcsv() curl "${url_csv}/service/search?q=$(echo "$1" | tr ' ' '+')" \ --silent \ - --compressed | - grep -o '"[^,}]*' + --compressed \ + --write-out "%{http_code}" } byttounit() @@ -119,6 +119,7 @@ wheremag() query= fetch= +data= name= magnet= @@ -133,13 +134,23 @@ dep_check "$menu" query="${*:-$(printf "" | "$menu" -p "󱇒 ")}" [ -z "$query" ] && exit 1 + fetch="$(search_tcsv "$query")" -[ -z "$fetch" ] && +case "$fetch" in +*200) + [ "$fetch" = '[]200' ] && + die "no results found" + data="$(echo "$fetch" | grep -o '"[^,}]*')" + ;; +*) die "search failed, check your internet connection" -name="$(echo "$fetch" | parse_table)" + ;; +esac + +name="$(echo "$data" | parse_table)" [ -z "$name" ] && exit 1 -magnet="$(echo "$fetch" | wheremag "$name")" +magnet="$(echo "$data" | wheremag "$name")" if [ "$out" = true ]; then echo "$magnet" -- cgit v1.2.3