]> git.plutz.net Git - serve0/blob - helpers/genmeta.sh
ca0fe7f8c1a54f1e0b7ee18d3821e80a1879ffa5
[serve0] / helpers / genmeta.sh
1 #!/bin/zsh
2 # Copyright 2014 - 2016 Paul Hänsch
3 #
4 # This file is part of Serve0
5 #
6 # Serve0 is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Serve0 is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Affero General Public License for more details.
15 #
16 # You should have received a copy of the GNU Affero General Public License
17 # along with Serve0  If not, see <http://www.gnu.org/licenses/>.
18
19 video="$1"
20 meta="$2"
21
22 if [ -r "$meta" ]; then
23   tags="$(sed -n 2p "$meta")"
24   description="$(sed -n '3,$p' "$meta")"
25 fi
26
27 printf '' |mplayer -input nodefault-bindings -nosound -vo null -identify -frames 0 "$video" \
28 | sort \
29 | sed -rn 's:ID_LENGTH=(.*)(\..*)$:\1:p;
30            s:ID_VIDEO_HEIGHT=(.*):\1:p;
31            s:ID_VIDEO_WIDTH=(.*):\1:p;' \
32 | tr '\n' ' ' \
33 | read length height width 2>/dev/null
34
35 cat <<EOF >"$meta"
36 ${length:-0}    ${width:-0}     ${height:-0}    ${video##*/}
37 ${tags:-|}
38 ${description}
39 EOF