/vlc
Created
October 12, 2017 21:41
Wrapper for viewing movies using vlc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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