Skip to content

Commit 6ec05de

Browse files
committed
Add a script for opening files in different viewers based on size.
1 parent 60b7759 commit 6ec05de

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

linux/smart-media-open

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

0 commit comments

Comments
 (0)