From 554b794ad2487c34b5e9f59850d426d13b8f69fa Mon Sep 17 00:00:00 2001 From: coolneng Date: Mon, 15 May 2023 16:47:27 +0200 Subject: [PATCH] Improve csv parsing and error handling in peerflix --- scripts/.local/share/scripts/peerflix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/.local/share/scripts/peerflix b/scripts/.local/share/scripts/peerflix index f016ede..5711598 100755 --- a/scripts/.local/share/scripts/peerflix +++ b/scripts/.local/share/scripts/peerflix @@ -5,7 +5,8 @@ player=mpv data_file=$HOME/Documents/Misc/peerflix-db.csv parse_csv() { - show_name=$(echo "$1" | cut -d "=" -f 3 | awk -F "S[0-9]|[S|s]eason|[C|c]omplete" '{print $1}' | tr -d "[:digit:]%" | tr +. " " | sed -e 's/[[:space:]]*$//') + show_name=$(echo "$1" | cut -d "=" -f 3 | awk -F "S[0-9]|[S|s]eason|[C|c]omplete" '{print $1}' | + tr -d "[:digit:]" | tr "[:punct:]" " " | sed -e 's/[[:space:]]*$//') episode=$(awk -F ',' -v var="$show_name" '$1 ~ var {print $2}' "$data_file") line_number=$(awk -F ',' -v var="$show_name" '$1 ~ var {print NR}' "$data_file") } @@ -15,6 +16,15 @@ increment_episode() { sed -e "$line_number s/$episode/$next_episode/" -i "$data_file" } +usage() { + echo "Usage: peerflix " + exit 1 +} + +if [ $# -ne 1 ]; then + usage +fi + parse_csv "$1" if [ -z "$episode" ]; then webtorrent download "$1" -s -o "$directory" --"$player"