-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovie
executable file
·172 lines (135 loc) · 5.83 KB
/
movie
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
#!/usr/bin/env bash
## By Davoud Arsalani
## https://github.com/davoudarsalani/scripts
## https://github.com/davoudarsalani/scripts/blob/master/movie
## https://raw.githubusercontent.com/davoudarsalani/scripts/master/movie
## https://davoudarsalani.ir
source "$HOME"/main/scripts/gb
source "$HOME"/main/scripts/gb-audacious
source "$HOME"/main/scripts/gb-duration
function no_such_file {
msgc 'ERROR' "no such file as <span color=\"${orange}\">${movie_full_path/$HOME/\~}</span>" "$HOME"/main/linux/themes/alert-w.png
exit
}
function success_moving {
local text
text="$(printf "moved to <span color=\"%s\">WATCHED</span>\n<span color=\"%s\">%s</span>\n" "$blue" "$orange" "$no_suffix")"
msgn "$text" '' "$HOME"/main/linux/themes/delete-w.png
}
function error_moving {
msgc 'ERROR' "moving <span color=\"${orange}\">${no_suffix}</span> to <span color=\"${blue}\">WATCHED</span>" "$HOME"/main/linux/themes/alert-w.png
# exit ## exceptionally commented
}
function success_removing {
msgn 'removed' "<span color=\"${red}\"><b>${no_suffix}</b></span>" "$HOME"/main/linux/themes/delete-w.png
}
function error_removing {
msgc 'ERROR' "removing <span color=\"${orange}\">${no_suffix}</span>" "$HOME"/main/linux/themes/alert-w.png
}
function if_empty { ## JUMP_1 the same used in "$HOME"/main/scripts/speech
local count
read count directory <<< "$directory" ## 8 pargar
## check if count is an int
[ "$count" -eq "$count" ] || {
msgc 'ERROR' "<span color=\"${orange}\">${count}</span> is invalid count" "$HOME"/main/linux/themes/alert-w.png
exit
}
(( count > 0 )) || {
msgn 'nothing here'
exit
}
}
function if_no_dir { ## JUMP_1
[ -d "$HOME"/main/movie/"$directory" ] || {
msgc 'ERROR' "no such directory as <span color=\"${orange}\">\$HOME/main/movie/${directory}</span>" "$HOME"/main/linux/themes/alert-w.png
exit
}
}
declare -i total_duration_second=0
declare -a directories_plus_count movies_array
[ "$play_status" == 'playing' ] && continue_playing='true' || continue_playing='false'
[ "$1" ] || exit
[ "$1" == 'random' ] && title='random movie' || title='select movie'
readarray -t directories < <(find "$HOME"/main/movie -mindepth 1 -maxdepth 1 -type d | sort)
## get movie count in each directory and prepend it to the directory name
for tmp_directory in "${directories[@]}"; {
movies_count="$(wc -l < <(find "$tmp_directory" -mindepth 1 -maxdepth 1 -type f ! -iname '*.srt'))"
## decide how many spaces to add
if (( movies_count < 10 )); then
spaces=' '
elif (( movies_count < 100 )); then
spaces=' '
elif (( movies_count < 1000 )); then
spaces=' '
else
spaces=' '
fi
directories_plus_count+=( "${movies_count}${spaces}${tmp_directory##*/}" )
}
directory="$(pipe_to_rofi "${directories_plus_count[@]}" "header=${title}")" || exit 37
if_empty ## NOTE if_empty must precede if_no_dir (i.e. JUMP_2)
if_no_dir ## JUMP_2
find_movies_cmd='find "$HOME"/main/movie/"$directory" -mindepth 1 -maxdepth 1 -type f ! -iname "*.srt"'
case "$1" in
random )
movie="$(shuf -n 1 < <(eval "$find_movies_cmd"))"
movie="${movie##*/}" ;;
select )
readarray -t movies < <(eval "$find_movies_cmd" | sort)
for m in "${movies[@]}"; {
duration_second="$(get_duration "$m" "seconds")"
duration="$(get_duration "$m")"
short_duration="$(shorten_duration "$duration")"
short_duration_and_movie="$(printf '%-11s%s\n' "$short_duration" "${m##*/}")"
movies_array+=( "$short_duration_and_movie" )
total_duration_second+="$duration_second"
}
total_duration_conv="$(convert_second "$total_duration_second")"
movie="$(pipe_to_rofi "${movies_array[@]}" "header=${directory} (total: "$total_duration_conv")")" || exit 37
## remove duration from beginning
movie="$(printf '%s\n' "$movie" | sed 's/^.\+ \+//')" ;;
* )
exit ;; ## NOTE do NOT remove
esac
## play
no_suffix="${movie%.*}"
movie_full_path="$HOME"/main/movie/"$directory"/"$movie"
movie_kaddy_full_path="$(get_kaddy_counterpart "$movie_full_path")"
srt_full_path="${movie_full_path%.*}.srt"
srt_kaddy_full_path="${movie_kaddy_full_path%.*}.srt"
[ -f "$movie_full_path" ] || no_such_file
msgn 'playing' "<span color=\"${orange}\">${no_suffix}</span>" "$HOME"/main/linux/themes/filmroll-w.png
vlc -f --play-and-exit -- "$movie_full_path" 2>/dev/null
## move to WATCHED or remove
what_to_dos=( '' 'mv to WATCHED' 'remove' )
what_to_do="$(pipe_to_rofi "${what_to_dos[@]}" "header=${movie}" 'bg=red')" # || exit 37 ## the exit is exceptionally commented
case "$what_to_do" in
'mv to WATCHED' )
watched_dir="$HOME"/main/movie/"$directory"/WATCHED
watched_dir_kaddy="$(get_kaddy_counterpart "$watched_dir")"
[ -d "$watched_dir" ] || mkdir "$watched_dir"
[ -d "$watched_dir_kaddy" ] || mkdir "$watched_dir_kaddy"
{
mv "$movie_full_path" "$watched_dir"
mv "$movie_kaddy_full_path" "$watched_dir_kaddy"
## mv srt
if [ -f "$srt_full_path" ]; then
mv "$srt_full_path" "$watched_dir"
mv "$srt_kaddy_full_path" "$watched_dir_kaddy"
fi
} && success_moving || error_moving ;;
remove )
{
rm "$movie_full_path"
rm "$movie_kaddy_full_path"
## rm srt
if [ -f "$srt_full_path" ]; then
rm "$srt_full_path"
rm "$srt_kaddy_full_path"
fi
} && success_removing || error_removing ;;
# * ) ## NOTE keep commented
# exit ;;
esac
## play audacious if it was playing before the video was played
[ "$continue_playing" == 'true' ] && "$HOME"/main/scripts/awesome-widgets audacious play_pause