2022-06-10 01:10:06 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
directory=/tmp/webtorrent
|
|
|
|
player=mpv
|
2022-08-30 20:10:28 +02:00
|
|
|
data_file=$HOME/Documents/IT/peerflix-db.csv
|
2022-06-10 01:10:06 +02:00
|
|
|
|
2022-08-30 20:10:28 +02:00
|
|
|
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
|