-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck-integrity
More file actions
executable file
·70 lines (60 loc) · 1.45 KB
/
check-integrity
File metadata and controls
executable file
·70 lines (60 loc) · 1.45 KB
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
#!/usr/bin/env bash
clear_line() {
printf "\r\033[2K"
}
print_status() {
printf "\e[3;4m%s\e[0m\r" "$1"
}
print_status_report() {
clear_line
print_status "$1"
echo
}
prog() {
local w=80 p=$1
shift
# create a string of spaces, then change them to dots
printf -v dots "%*s" "$((p * w / 100))" ""
dots=${dots// /.}
# print those dots on a fixed-width space plus the percentage etc.
printf "\r\e[K|%-*s| %3d %% " "$w" "$dots" "$p"
print_status "$*"
}
FILES=()
if [ $# -eq 0 ]; then
print_status "Scanning..."
while IFS= read -r -d $'\0'; do
FILES+=("$REPLY")
done < <(find ./*.mp4 -maxdepth 1 -type f -print0 2>/dev/null)
print_status_report "Scanned"
else
FILES=("$@")
fi
MAX_FILE_LEN=-1
FILES_LEN=${#FILES[@]}
ITER=1
for str in "${FILES[@]}"; do
filename=$(basename -- "$str")
filename="${filename%.*}"
prog "$((100 * ITER / FILES_LEN))" "Processing..."
if [[ ${#filename} -gt ${MAX_FILE_LEN} ]]; then
MAX_FILE_LEN=${#filename}
fi
ITER=$((ITER + 1))
done
print_status_report "Processed"
ERRORED=()
ITER=1
for FILEPATH in "${FILES[@]}"; do
prog "$((100 * ITER / FILES_LEN))" "Checking \`$FILEPATH\`"
SUCC=$(ffmpeg -v error -i "$FILEPATH" -f null - 2>&1)
if [ -n "$SUCC" ]; then
ERRORED+=("$FILEPATH")
fi
ITER=$((ITER + 1))
done
print_status_report "Checked"
if [ ! ${#ERRORED[@]} -eq 0 ]; then
echo "${ERRORED[@]}"
exit 1
fi