-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrofianime
executable file
·171 lines (146 loc) · 3.78 KB
/
rofianime
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
#!/usr/bin/env bash
# Written by Japorized <johnson5756 (at) live (dot) com>
# Required Dependencies:
# rofi, bc
# Optional Dependencies:
# mpv, thunar
#
# Make sure that your video files are renamed in the following format:
# *- [x].ext
# where x is the episode number, which can be of any length.
# The only caveat with the naming of files is that the episode number
# must be enclosed in square brackets, and place at the very end of the
# filename right before the extension.
# configs
rofiprompt="ア rofianime"
animedir="$HOME/Videos/Anime"
vidplayer="/usr/bin/mpv"
filemanager="/usr/bin/thunar"
fileext="(.mkv|.mp4|.webm)" # use regex (PCRE)
renamers="HorribleSubs|Teasing Anon|Judas|Anon" # |-separated
rofiopts=""
dmenuopts=""
if [ ! -e $vidplayer ]; then
rofi -e "$vidplayer does not exist. Please manually configure rofianime".
exit 1
fi
# keybindings
goback="Alt+c"
useRenamer="Alt+r"
openInFM="Alt+t"
# color(s)
highlightcolor='Aqua'
# load configs
. "$HOME/.config/rofi/script-configs/rofianime.conf"
_rofi() {
rofi ${rofiopts} -sep '|' -dmenu -i -p "${rofiprompt}" ${dmenuopts} "$@"
}
_renamer() {
case "$1" in
"HorribleSubs" | "Teasing Anon" | "Judas" | "Anon")
for f in *"$1"* ; do
filename=$(echo $f \
| sed "s/\[$1\] //g" \
| sed 's/ \[[0-9]*p\]//g' \
| sed -E "s/ - ([0-9]+\.?[0-9]+)/ - [\1]/g")
mv "$f" "$filename"
done && rofi -e "Success"
;;
esac
}
getAnime() {
IFS=$'\n'
animearr=($(ls | sed 's/:.*//'))
unset IFS
animelist=""
for idx in "${!animearr[@]}"
do
if [ -z "$animelist" ]; then
animelist="${animearr[$idx]}"
else
animelist="$animelist|${animearr[$idx]}"
fi
done
anime=$(echo $animelist | _rofi)
echo "$anime"
}
getEpisode() {
IFS=$'\n'
# we shall grab only the files with the provided extensions
episodearr=($(ls | grep -E $fileext | sed 's/:.*//'))
unset IFS
lastWatchedEp=$(getBookmark .bookmark)
if [ -n $lastWatchedEp ]; then
nextEp=$(echo $lastWatchedEp + 1 | bc)
else
nextEp=""
fi
episodelist=""
for idx in "${!episodearr[@]}"
do
if [ -z "$episodelist" ]; then
episodelist="${episodearr[$idx]}"
else
if [ -n $nextEp ]; then
# try to put next episode as the first choice
curEp=$(echo $(getEpNum "${episodearr[$idx]}") | bc)
if [ "$curEp" != "$nextEp" ]; then
episodelist="$episodelist|${episodearr[$idx]}"
else
episodelist="${episodearr[$idx]}|$episodelist"
fi
else
episodelist="$episodelist|${episodearr[$idx]}"
fi
fi
done
rofimsg="<i><b>Last Episode:</b> $lastWatchedEp</i>
<span color='${highlightcolor}'>${goback}</span> to go back | <span color='${highlightcolor}'>${useRenamer}</span> to automagically rename certain files
<span color='${highlightcolor}'>${openInFM}</span> open in file manager"
episode=$(echo $episodelist \
| _rofi -mesg "$rofimsg" ${dmenuopts} \
-kb-custom-1 "${goback}" -kb-custom-2 "${useRenamer}" \
-kb-custom-3 "${openInFM}" )
val=$?
case "$val" in
10) main ;;
11) renameFiles && getEpisode ;;
12) ${filemanager} . ;;
1) exit 0 ;;
*) echo "$episode"
esac
}
renameFiles() {
renameChoice=$(echo "$renamers" | _rofi -mesg "Pick an option")
_renamer "$renameChoice"
}
getEpNum() {
epnum=$(echo "$1" | sed -E "s/.+ - \[(.+)\]$fileext/\1/g")
echo $epnum
}
setBookmark() {
echo $(getEpNum "$1") > .bookmark
}
getBookmark() {
if [ -e .bookmark ]; then
cat .bookmark
else
echo "" > .bookmark
fi
}
main() {
cd "$animedir"
animeRes=$(getAnime)
if [ -z "$animeRes" ]; then
exit 0
fi
cd "$animeRes"
epiRes=$(getEpisode)
echo $epiRes
if [ -z "$epiRes" ]; then
exit 0
fi
setBookmark "$epiRes"
${vidplayer} "${epiRes}"
}
main