forked from debridmediamanager/debrid-media-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.sh
executable file
·175 lines (156 loc) · 6.56 KB
/
scraper.sh
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
function find_free_port() {
port=$(shuf -i 1024-65535 -n 1)
while netstat -an | grep -q LISTEN:$port; do
port=$(shuf -i 1024-65535 -n 1)
done
echo $port
}
function wait_for_healthz_ok() {
local url="$1"
local response=""
while true; do
response=$(curl -s "$url" | jq -r '.status')
if [ "$response" == "ok" ]; then
break
else
sleep 1
fi
done
sleep 1
}
function launch_scraper() {
DMM_PATH="/home/ben/debrid-media-manager"
echo "$0"
echo "$(readlink -f $0)"
echo "Launching scraper ($DMM_PATH): $1..."
if [ "$1" = "upkeep" ]; then
SESSION_NAME="upkeep"
tmux new-session -d -s upkeep
# requested
tmux new-window -t upkeep:1 -n requested
PORT=$(find_free_port)
tmux send-keys -t upkeep:1 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
wait_for_healthz_ok "http://localhost:$PORT/api/healthz"
timeout 3 curl "http://localhost:$PORT/api/upkeep/requested"
# stuck
tmux new-window -t upkeep:2 -n stuck
PORT=$(find_free_port)
tmux send-keys -t upkeep:2 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
wait_for_healthz_ok "http://localhost:$PORT/api/healthz"
timeout 3 curl "http://localhost:$PORT/api/upkeep/stuck"
# empty
tmux new-window -t upkeep:3 -n empty
PORT=$(find_free_port)
tmux send-keys -t upkeep:3 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
wait_for_healthz_ok "http://localhost:$PORT/api/healthz"
timeout 3 curl "http://localhost:$PORT/api/upkeep/empty?quantity=3"
# updateoldmovies
tmux new-window -t upkeep:4 -n updateoldmovies
PORT=$(find_free_port)
tmux send-keys -t upkeep:4 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
wait_for_healthz_ok "http://localhost:$PORT/api/healthz"
timeout 3 curl "http://localhost:$PORT/api/upkeep/updateoldmovies"
# updateoldshows
tmux new-window -t upkeep:5 -n updateoldshows
PORT=$(find_free_port)
tmux send-keys -t upkeep:5 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
wait_for_healthz_ok "http://localhost:$PORT/api/healthz"
timeout 3 curl "http://localhost:$PORT/api/upkeep/updateoldshows"
# done!
sleep 3
tmux kill-window -t upkeep:0
elif [ "$1" = "newepisodes" ]; then
PARAM="46119"
SLUG=$(curl -s "https://mdblist.com/api/lists/$PARAM/?apikey=55gg408ja72aa3f5d5p90w4zu" | jq -r '.[0].slug')
PORT=$(find_free_port)
SESSION_NAME="$SLUG-$PORT"
AGE="0"
tmux new-session -d -s $SESSION_NAME
tmux send-keys -t $SESSION_NAME:0 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
sleep 3
tmux new-window -t $SESSION_NAME:1
timeout 3 curl "http://localhost:$PORT/api/scrapers/singlelist?skipMs=1&rescrapeIfXDaysOld=$AGE&quantity=5&listId=$PARAM&lastSeason=true"
sleep 3
tmux kill-window -t $SESSION_NAME:1
elif [ "$1" = "newreleases" ]; then
PARAM="46446"
SLUG=$(curl -s "https://mdblist.com/api/lists/$PARAM/?apikey=55gg408ja72aa3f5d5p90w4zu" | jq -r '.[0].slug')
PORT=$(find_free_port)
SESSION_NAME="$SLUG-$PORT"
AGE="0"
tmux new-session -d -s $SESSION_NAME
tmux send-keys -t $SESSION_NAME:0 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
sleep 3
tmux new-window -t $SESSION_NAME:1
timeout 3 curl "http://localhost:$PORT/api/scrapers/singlelist?skipMs=1&rescrapeIfXDaysOld=$AGE&quantity=5&listId=$PARAM&lastSeason=true"
sleep 3
tmux kill-window -t $SESSION_NAME:1
# torrentio scraper
elif [ "$1" = "torrentio" ]; then
PORT=$(find_free_port)
SESSION_NAME="torrentio-$PORT"
tmux new-session -d -s $SESSION_NAME
tmux send-keys -t $SESSION_NAME:0 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
sleep 3
tmux new-window -t $SESSION_NAME:1
timeout 3 curl "http://localhost:$PORT/api/scrapers/torrentio"
sleep 3
tmux kill-window -t $SESSION_NAME:1
# for individual movies
elif [[ "$1" =~ ^tt[a-z0-9]{3,20}$ ]]; then
PARAM="$1"
PORT=$(find_free_port)
SESSION_NAME="$PARAM-$PORT"
AGE="$2"
tmux new-session -d -s $SESSION_NAME
tmux send-keys -t $SESSION_NAME:0 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
sleep 3
tmux new-window -t $SESSION_NAME:1
timeout 3 curl "http://localhost:$PORT/api/scrapers/imdb?replaceOldScrape=false&id=$PARAM"
sleep 3
tmux kill-window -t $SESSION_NAME:1
# for individual movies, but replace old scrape (useful if match algo has been updated)
elif [[ "$1" =~ ^rtt[a-z0-9]{3,20}$ ]]; then
PARAM="${1#r}"
PORT=$(find_free_port)
SESSION_NAME="$PARAM-$PORT"
AGE="$2"
tmux new-session -d -s $SESSION_NAME
tmux send-keys -t $SESSION_NAME:0 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
sleep 3
tmux new-window -t $SESSION_NAME:1
timeout 3 curl "http://localhost:$PORT/api/scrapers/imdb?replaceOldScrape=true&id=$PARAM"
sleep 3
tmux kill-window -t $SESSION_NAME:1
# it will search for multiple lists by name (e.g. series, top, etc.)
elif [[ "$1" =~ ^[a-z]{3,20}$ ]]; then
PARAM="$1"
PORT=$(find_free_port)
SESSION_NAME="$PARAM-$PORT"
AGE="$2"
tmux new-session -d -s $SESSION_NAME
tmux send-keys -t $SESSION_NAME:0 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
sleep 3
tmux new-window -t $SESSION_NAME:1
timeout 3 curl "http://localhost:$PORT/api/scrapers/listoflists?skipMs=1&rescrapeIfXDaysOld=$AGE&quantity=3&search=$PARAM"
sleep 3
tmux kill-window -t $SESSION_NAME:1
# it will search for a single list by id
else
PARAM="$1"
SLUG=$(curl -s "https://mdblist.com/api/lists/$PARAM/?apikey=55gg408ja72aa3f5d5p90w4zu" | jq -r '.[0].slug')
PORT=$(find_free_port)
SESSION_NAME="$SLUG-$PORT"
AGE="$2"
tmux new-session -d -s $SESSION_NAME
tmux send-keys -t $SESSION_NAME:0 "cd $DMM_PATH && npm start -- -p $PORT && exit" C-m
sleep 3
tmux new-window -t $SESSION_NAME:1
timeout 3 curl "http://localhost:$PORT/api/scrapers/singlelist?skipMs=1&rescrapeIfXDaysOld=$AGE&quantity=3&listId=$PARAM"
sleep 3
tmux kill-window -t $SESSION_NAME:1
fi
tmux ls | grep $SESSION_NAME
echo "Launched $SESSION_NAME"
}