From 3b0fa215deb8ab6c405a8d677dde669da5b252c3 Mon Sep 17 00:00:00 2001 From: coolneng Date: Tue, 30 Aug 2022 20:10:28 +0200 Subject: [PATCH] Add episode database to peerflix script --- scripts/.local/share/scripts/peerflix | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/scripts/.local/share/scripts/peerflix b/scripts/.local/share/scripts/peerflix index 5dc177c..8e4feab 100755 --- a/scripts/.local/share/scripts/peerflix +++ b/scripts/.local/share/scripts/peerflix @@ -2,7 +2,25 @@ directory=/tmp/webtorrent player=mpv +data_file=$HOME/Documents/IT/peerflix-db.csv -webtorrent download "$1" -s -o "$directory" --"$player" -read -rp "File number: " nr -webtorrent download "$@" -s "$nr" -o "$directory" --"$player" +parse_csv() { + show_name=$(echo "$1" | cut -d "=" -f 3 | cut -d "%" -f 1 | tr + " ") + 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") +} + +increment_episode() { + next_episode=$((episode + 1)) + sed -e "$line_number s/$episode/$next_episode/" -i "$data_file" +} + +parse_csv "$1" +if [ -z "$episode" ]; then + webtorrent download "$1" -s -o "$directory" --"$player" + read -rp "File number: " nr + webtorrent download "$@" -s "$nr" -o "$directory" --"$player" +else + increment_episode + webtorrent download "$@" -s "$episode" -o "$directory" --"$player" +fi