#! /bin/zsh clear-position-files () { rm -f position-*.txt(N) } alias poso=clear-position-files play-dwim () { local first=$1 local first_len_secs=$(movie-seconds $first) local -a files files=($@) local max_ignore_len=$(( 10*60 )) # ten minutes if (( first_len_secs > max_ignore_len )); then play-position $files else play-all $files fi } play-all () { local -a files files=($@) play-position -r $files } alias pla=play-all play-position () { # check if in X if [[ -z $DISPLAY ]]; then not-in-X-msg return fi # resume position vars local pos local pos_file_name local pos_file_path local restart=false # options if [[ $1 == "-r" ]]; then restart=true pos_file_path=/dev/null shift fi # the files local -a files files=($@) # file vars local file local file_name local file_label local file_path local file_dir local font_size=35 # play everything for f in $files; do file_path=${f:a} if [[ ! -f $file_path ]]; then no-file-msg $file_path continue fi file=$f file_name=${file:t} file_label=${file:t:r} file_path=${file:a} file_dir=${file:h} if ( ! $restart ); then # check if there a resume position for this file pos_file_name=position-${file_label}.txt pos_file_path=${file_dir}/${pos_file_name} [[ -f $pos_file_path ]] && pos=$(cat $pos_file_path) fi # if there isn't a file, # or there is but it is empty, # it means playback was either never done # or if it was, it was completed; or, # 'plo' was invoked with the -r option # to force restart - anyhow so, # (re)set the variable # to start playing from the beginning [[ -z $pos ]] && pos='00:00:00' # options local common_options common_options=$(omx-common-options) # omxplayer command eval "sudo omxplayer $common_options --pos $pos $file_path \ | \grep Stopped \ | cut -d ' ' -f 3 > $pos_file_path" done }