-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-segment-metafile.sh
57 lines (46 loc) · 1.11 KB
/
build-segment-metafile.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
#!/bin/bash
# This script is for creating segment files for mpv-segment-linking
# Available at: https://github.com/CogentRedTester/mpv-segment-linking
# Segment File version: v0.1
output_file=".segment-linking"
declare -a files=()
while (( "$#" > 0 ))
do
if [[ "$1" == "-o" ]]
then
shift
output_file=$1
shift
break
fi
files+=("$1")
shift
done
echo "# mpv-segment-linking v0.1" > $output_file
echo "" >> $output_file
for file in "${files[@]}"
do
out=$(mkvinfo "$file")
# if mkvinfo could not scan the file then skip
if [ $? -ne 0 ]
then
continue
fi
echo "$file" >> $output_file
regex="Segment UID: ([0-9a-zA-Z ]+)"
if [[ $out =~ $regex ]]
then
echo "UID=${BASH_REMATCH[1]}" >> $output_file
fi
regex="Previous segment UID: ([0-9a-zA-Z ]+)"
if [[ $out =~ $regex ]]
then
echo "PREV=${BASH_REMATCH[1]}" >> $output_file
fi
regex="Next segment UID: ([0-9a-zA-Z ]+)"
if [[ $out =~ $regex ]]
then
echo "NEXT=${BASH_REMATCH[1]}" >> $output_file
fi
echo "" >> $output_file
done