-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkm3u
executable file
·74 lines (65 loc) · 1.41 KB
/
mkm3u
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
#!/bin/bash
# set -x
#
# -f = force writing m3u even if it means overwriting existing
#
skipIfExists=true
if [[ $1 == "-f" ]]; then
skipIfExists=false
shift
fi
#
# -h - help
#
if [[ $1 == "-h" ]]; then
cat <<-EOF
Usage: $0 [-f] [nn1] [nn2] file.ext [file.ext ...]
Build playlists for the argument files, saving them to "file.m3u". Existing m3u files
are skpped and not overwritten by default.
-f - force overwriting of existing m3u files
nn1 - decimal # of seconds to crop off the start of all files
nn2 - decomal # of seconds to crop off the end of all files
EOF
exit 0
fi
#
# ARG 1: n - number of seconds to chop off the start
#
startChop=0
if [[ $1 =~ ^[0-9]*[0-9]$ ]]; then
startChop=$1
shift
fi
#
# ARG 2: n - number of seconds to chop off the end
#
endChop=0
if [[ $1 =~ ^[0-9]*[0-9]$ ]]; then
endChop=$1
shift
fi
safe() {
for i; do
echo -n "$i" \
| curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" \
| sed -e 's/%20/ /g' \
| cut -c 3-
done
}
for i; do
dur=$(vinfo -e "$i" | awk '{ print $1; }')
durLessChop="$((dur - endChop))"
m3u="${i%.???}".m3u
if $skipIfExists && [ -r "$m3u" ]; then
echo "Skipping existing $m3u"
continue
fi
safeName="$(echo "$i" | sed -e 's/\[/%5B/g' -e 's/\]/%5D/g')"
(
echo "#EXTM3U";
echo "#EXTVLCOPT:start-time=${startChop}";
echo "#EXTVLCOPT:stop-time=${durLessChop}";
echo "${safeName}"
) > "${m3u}"
echo "$i -> $m3u"
done