File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash -eu
2+
3+ # This is a script for KDE which looks at metadata for files and uses the
4+ # metadata to determine the most appropriate program to open a file with,
5+ # beyond just the file type.
6+
7+ if [ $# -ne 1 ] || [ -z " $1 " ]; then
8+ echo ' Usage: smart-media-open <filename>' 1>&2
9+ exit 1
10+ fi
11+
12+ filename=" $1 "
13+ mimetype=" $( file -b --mime-type " $filename " ) "
14+ is_video=0
15+
16+ if [[ " $mimetype " =~ ^video/ ]]; then
17+ is_video=1
18+ fi
19+
20+ if (( $is_video )) ; then
21+ duration=" $( \
22+ printf " %.0f\n" \
23+ " $( \
24+ ffprobe -i " $filename " \
25+ -show_entries format=duration \
26+ -v quiet -of csv=" p=0" \
27+ ) " \
28+ ) "
29+
30+ if [ " $duration " -gt 240 ]; then
31+ # This video file is longer than four minutes, so use the Dragon player.
32+ exec dragon " $filename "
33+ else
34+ # Otherwise, use gthumb.
35+ exec gthumb " $filename "
36+ fi
37+ fi
38+
39+ # Nothing suitable handler is known of!
40+ echo " Unable to handle file: $filename " 1>&2
41+ exit 1
You can’t perform that action at this time.
0 commit comments