-
Notifications
You must be signed in to change notification settings - Fork 0
/
animeplay
executable file
·60 lines (51 loc) · 1.58 KB
/
animeplay
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
#
# User options
mediadir="/home/mitch/Downloads/torrent/_anime"
destdir="/mnt/zed/media/anime/0 In Progress"
function deleteTorrent {
SERVER="https://ginger.ipha.pw:8080"
INFO="$(curl -s ${SERVER}/api/v2/torrents/info | sed 's|},|},\n|g' | grep -F "$1")"
if [[ "${INFO}" =~ \"hash\":\"([^\"]*?)\", ]]; then
HASH="${BASH_REMATCH[1]}"
curl -s -X POST -d "hashes=${HASH}&deleteFiles=false" ${SERVER}/api/v2/torrents/delete
fi
}
function postprocess {
if [ "$(pwd)" != "$mediadir" ]; then
# Not in root media dir don't move anything
return
fi
deleteTorrent "$1"
# regex in bash is hard... lets just not
# Strip group
name1=$(echo "$1" | sed 's|\[\S*\] ||')
# Strip episode
name2=$(echo "$name1" | sed 's| - S\?[[:digit:]]\+.*\..*$||')
if [ "$name1" = "$name2" ]; then
# No episode number found. Movie or OVA?
name=""
else
# Title extracted
name="$name2"
fi
if [ -d "${destdir}"/"${name}" ]; then
# echo "dest found"
mv "$1" "${destdir}"/"${name}"
# Reset last to account for moved file
((last--))
else
echo -ne "Target ${destdir}/${name} not found. Make it? (y/N) "
read -r selection
case $selection in
y|Y)
mkdir "${destdir}"/"${name}"
mv "$1" "${destdir}"/"${name}"
# Reset last to account for moved file
((last--))
;;
esac
fi
}
# shellcheck source=mediatree
source "$(dirname "$0")/mediatree" "${mediadir}"