-
Notifications
You must be signed in to change notification settings - Fork 0
/
aikatsu_story
executable file
·139 lines (127 loc) · 3.47 KB
/
aikatsu_story
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
#!/bin/bash
usage_exit() {
cat <<EOS 1>&2
Usage: $0 [-0] [-s] [-f] [-o] [-w] [-p] [--url] [--title] episode-id
-0: Aikatsu!
-s: Aikatsu Stars!
-f: Aikatsu Friends!
-o: Aikatsu on parade!
-w: Aikatsu on parade! (web anime)
-p: Aikatsu planet! (current default)
--url: Show story url instead of story
--title: Show story title instead of story
EOS
exit 1
}
while getopts h0sfowp-: OPT
do
case $OPT in
-)
case "${OPTARG}" in
url)
URL=1
;;
title)
TITLE=1
;;
help)
usage_exit
;;
esac
;;
0) MUJIRUSHI=1
;;
s) STARS=1
;;
f) FRIENDS=1
;;
o) ONPARADE=1
;;
w) ONPARADE_WEB=1
;;
p) PLANET=1
;;
h) usage_exit
;;
\?) usage_exit
;;
esac
done
shift $((OPTIND - 1))
if [[ -z $MUJIRUSHI && -z $STARS && -z $FRIENDS && -z $ONPARADE && -z $ONPARADE_WEB ]]; then
# default to PLANET
PLANET=1
fi
STORY_ID=$1
if [[ -z $STORY_ID ]]; then
usage_exit
fi
episode_id=`printf %03d $STORY_ID`
series_id=`printf %02d $(( ($STORY_ID - 1)/ 50 + 1))`
if [[ -n $PLANET ]]; then
# episode_id is formed of 2 digits in planet
episode_id=`printf %02d $STORY_ID`
url="https://www.aikatsu.net/aikatsuplanet/story/story-${episode_id}.html"
# FIXME: Planet has no image alt (???).
# Get title from <title> (workaround)
title_pup_command='title text{}'
pup_command='.story-text > json{}'
elif [[ -n $ONPARADE_WEB ]]; then
# episode_id is formed of 2 digits in onparade_web
episode_id=`printf %02d $STORY_ID`
url="https://www.aikatsu.net/aikatsuonparade/webanime/story-${episode_id}.html"
title_pup_command='.story-main > :nth-child(1) img attr{alt}'
pup_command='.story-main-frame > :nth-child(2) json{}'
elif [[ -n $ONPARADE ]]; then
url="https://www.aikatsu.net/aikatsuonparade/story/story-${episode_id}.html"
title_pup_command='.story-main > :nth-child(1) img attr{alt}'
pup_command='.story-main-frame > :nth-child(2) json{}'
elif [[ -n $FRIENDS ]]; then
url="https://www.aikatsu.net/aikatsufriends_${series_id}/story/story-${episode_id}.html"
title_pup_command='.story-main > :nth-child(1) img attr{alt}'
if [ $1 -ge 51 ] ; then
pup_command='.story-main-frame > :nth-child(2) json{}'
else
pup_command='.story-waku-menu > :nth-child(2) json{}'
fi
elif [[ -n $STARS ]]; then
url="https://www.aikatsu.net/aikatsustars_${series_id}/story/${episode_id}.html"
title_pup_command='.story-main > :nth-child(1) img attr{alt}'
if [ $1 -ge 51 ] ; then
pup_command='.story-text json{}'
else
pup_command='.text json{}'
fi
elif [[ -n $MUJIRUSHI ]]; then
# MUJIRUSHI series does not organized as groups of 50 episodes
if [[ $STORY_ID -le 50 ]]; then
series_id='01'
elif [[ $STORY_ID -le 101 ]]; then
series_id='02'
else
series_id='03'
fi
# URL of MUJIRUSHI series have 2 digit of 0 padding before ep.99
if [[ $STORY_ID -le 99 ]]; then
episode_id=`printf %02d $STORY_ID`
fi
url="https://www.aikatsu.net/${series_id}/story/${episode_id}.html"
pup_command='.story-text json{}'
title_pup_command='#story-main p img attr{alt}'
# ???????????
if [[ $STORY_ID -eq 31 ]];then
pup_command='.story-text3 json{}'
fi
fi
if [[ -n $URL ]]; then
echo $url
exit
fi
if [[ -n $TITLE ]]; then
curl -s $url | \
pup "$title_pup_command"
exit
fi
curl -s $url | \
pup "$pup_command" | \
jq --raw-output '.[].text'