37 lines
996 B
Bash
Executable File
37 lines
996 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
directory=/tmp/webtorrent
|
|
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 "[: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")
|
|
}
|
|
|
|
increment_episode() {
|
|
next_episode=$((episode + 1))
|
|
sed -e "$line_number s/$episode/$next_episode/" -i "$data_file"
|
|
}
|
|
|
|
usage() {
|
|
echo "Usage: peerflix <magnet link>"
|
|
exit 1
|
|
}
|
|
|
|
if [ $# -ne 1 ]; then
|
|
usage
|
|
fi
|
|
|
|
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
|