diff options
author | sinanmohd <sinan@firemail.cc> | 2023-05-31 23:36:37 +0530 |
---|---|---|
committer | sinanmohd <sinan@firemail.cc> | 2023-06-01 00:28:42 +0530 |
commit | 280a2de146ecec36cdec32908b79781412eb691f (patch) | |
tree | 2c59ad16d849a1cc7ea9b35d527f17c404bdf4bd /tcsv | |
parent | bb2360868fcdba4ac7bd46ada5ed97170a58f4ee (diff) |
tcsv: better error handling
Diffstat (limited to 'tcsv')
-rwxr-xr-x | tcsv | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -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" |