Skip to content

Instantly share code, notes, and snippets.

@brucewoodward
Created October 12, 2017 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brucewoodward/4cef53928f4592452b032ac227580196 to your computer and use it in GitHub Desktop.
Save brucewoodward/4cef53928f4592452b032ac227580196 to your computer and use it in GitHub Desktop.
Wrapper for viewing movies using vlc
#!/bin/bash
VLCTMP=/tmp/vlc.out
QUIET=false
log_vlc() {
echo $(date +%s) "$@" >> ~/.vlc
}
run_vlc() {
open -a vlc "$@"
}
not_valid_file_name() {
test -e "$1" && return 1 || return 0
}
size_check() {
local count=$(tee "$VLCTMP" | wc -l)
if ((count==0))
then
echo "Nothing found" 1>&2
perl -e "kill -15, $$" # why is Perl being used for this?
else
cat "$VLCTMP"
fi
}
run_selecta() {
local wanted_file_extensions='\.(mkv|avi|mp4|mov|m4v|wmv)$'
echo "`find . | grep -i "$1" | egrep -i "${wanted_file_extensions}" | size_check | selecta -a`"
}
die() {
echo $1
exit 1
}
rm -f "$VLCTMP"
# -q as first arg to stop the logging of the file being watched.
if [[ $# -gt 0 && "$1" = -q ]]
then
QUIET=true
shift
fi
test $# -eq 0 && die "Missing arg(s)"
# arg isn't a file so use selecta to get the user to pick a file
# to display with vlc.
if not_valid_file_name "$1"; then
# Use find and grep to come up with a list of files for selecta.
files_for_vlc="$( run_selecta "$1" )"
test -z "$files_for_vlc" && exit 0 # no files selected.
else # full filename has been given.
files_for_vlc="$@"
fi
test "$QUIET" = false && log_vlc "$files_for_vlc"
run_vlc "$files_for_vlc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment