#!/bin/sh ## ## SCRIPT NAME: findMediaFiles_forCriteria.sh ## ##+####### ## PURPOSE: ## This script finds a set of user-specified 'media' files --- according to ## a fully-qualified file mask (directory and mask) and about seven other ## 'find' parameters passed to this script. ## ## This shell script is meant to be issued from the Tk GUI 'wrapper' script ## 'find_and_mediaPlayer_FrontEnd.tk'. ## That Tk script is to get parameters for the 'find' command ## ##+###### ## INPUTS: ## ## The parameters passed to this script, from the ## 'find_and_mediaPlayer_FrontEnd.tk' Tk GUI script, are: ## ## Var1: 'Base'-directory name and file mask. Examples: ## /home/fred/MOVIES/*vacation*.mp4 ## or ## /home/fred/MUSIC/*Lennon*.mp3 ## ## Var2: A 'levels' indicator - from a Tk radiobuttons var. ## (possible values: 'one' or 'all'). ## ## Var3: A 'case-sensitivity' indicator - from a Tk radiobuttons var. ## (possible values: 'case-sensitive' or 'case-INsensitive') ## ## Var4: A 'bigger/smaller' indicator from a Tk radiobuttons var ##. (possible values: 'bigger' or 'smaller') ## ## Var5: An integer file-size-cutoff value (in KiloBytes) ## (could be null, indicating no size limitation) ## ## Var6: An 'older/younger' indicator - from a Tk radiobuttons var. ##. (possible values: 'older' or 'younger') ## ## Var7: An integer file-age-cutoff value (in days) ## (could be null, indicating no age limitation) ## ## Var8: A file-type string --- such as 'MPEG v4' or 'Flash' or 'ASF' ## or 'QuickTime' or 'layer III' or 'PCM' ## ## Var9: The name of a (temporary) output file to be used to ## hold the filenames found by the 'find' command. ## ## In this script, we will put those parameters in shell script variables ## VARfilemask, VARlevels, VARsense, ## VARbigsmall, VARfilesize, ## VARoldyoung, VARfileage, ## VARfiletype, VARoutfile --- respectively. ## ##+######################################################################### ## MAINTENANCE HISTORY: ## Started by: Blaise Montandon 2014apr25 Made this 'findMediaFiles_forCriteria.sh' ## shell script by revising shell script ## 'getMediaFiles_andCountListOrPlay.sh' ## (which was started 2013dec15) to ## do the 'find' command but eliminate ## the count/list/play logic. ## Updated by: Blaise Montandon 2014 ##+######################################################################### ## FOR TESTING: (to show statements as they execute) # set -x VARfilemask="$1" VARlevels="$2" VARsense="$3" VARbigsmall="$4" VARfilesize="$5" VARoldyoung="$6" VARfileage="$7" VARfiletype="$8" VARoutfile="$9" ## FOR TESTING of this script without the Tk wrapper: ## (For stand-alone testing, change 'if test 1 = 0' to 'if test 1 = 1'.) if test 1 = 0 then # VARfilemask="$HOME/apps/tkGooies_linux_PREP/tkGUIs/.PREP_tkGooies/00_CFE_find_and_mediaplayer_FrontEnd_2013dec_PREP/*" VARfilemask="$HOME/TESTfilesMOVIES/*.flv" # VARfilemask="$HOME/TESTfilesAUDIO/*.mp3" VARlevels="one" # VARlevels="all" VARsense="case-sensitive" # VARsense="case-INsensitive" VARbigsmall="bigger" # VARbigsmall="smaller" VARfilesize="" VARoldyoung="older" # VARoldyoung="younger" VARfileage="" VARfiletype="MPEG v4" # VARfiletype="MPEG" # VARfiletype="layer III" VARoutfile="/tmp/${USER}_tkBatchMediaPlayer_filenames.lis" fi ## FOR TESTING: # echo "VARfilemask: $VARfilemask" ## Simply exit if there is no filemask passed to this script. if test "$VARfilemask" = "" then exit fi DIRNAME=`dirname "$VARfilemask"` FILEMASK=`basename "$VARfilemask"` if test "$VARlevels" = "one" then DEPTHPARM="-maxdepth 1" else DEPTHPARM="" fi if test "$VARsense" = "case-sensitive" then NAMEPARM="-name" else NAMEPARM="-iname" fi ## The FILESIZE_PARM can be a parameter like ## -size +${SIZE_MINinBYTES}c ## for the 'find' command. if test "$VARfilesize" = "" then FILESIZE_PARM="" else SIZEinBYTES=`expr $VARfilesize \* 1000` if test "$VARbigsmall" = "bigger" then # FILESIZE_PARM="-size +${SIZEinBYTES}c" FILESIZE_PARM="( -size +${SIZEinBYTES}c -o -size ${SIZEinBYTES}c )" ## Note that we do not need to 'escape' the parentheses like we ## do in a 'find' command entered at a shell command prompt, because ## the parentheses are 'protected' by being within a variable, ## rather than being 'exposed' in a command string. else FILESIZE_PARM="-size -${SIZEinBYTES}c" fi fi ## The FILEAGE_PARM can be a parameter like ## -mtime +$NDAYS ## for the 'find' command. if test "$VARfileage" = "" then FILEAGE_PARM="" else if test "$VARoldyoung" = "older" then FILEAGE_PARM="-mtime +$VARfileage" else FILEAGE_PARM="-mtime -$VARfileage" fi fi ############################################################# ## Prepare to use the temp filename to hold the filenames. ## Make sure we start with a new (empty) output file. ############################################################# rm -f "$VARoutfile" ############################################################# ## Get the directory name of this script, to call ## on another script in the same directory as this script. ############################################################# thisDIR=`dirname $0` ##+##################################################### ## Call on the 'find' command, which puts the ## 'found' filenames, SORTED, in file "$VARoutfile". ## ## We use a '-type d -fprint /dev/stderr' clause in the ## 'find' command to show directories being searched, ## in the 'xterm' that runs this script. ## This gives a kind of 'progress indicator' to let the ## user know how far/fast the 'find' command is progressing. ## ## We also use the 'tee' command to output 'found' filenames ## to 'stdout', as a means of providing a 'progress ## indicator' in the 'xterm' that runs this script. ## However, if not many filenames are found and then the ## 'xterm' closes quickly, the user may not get much ## of a progress indicator by this. ## ## The directory-name output is probably going to be ## the better progress indicator in most cases. ##+#################################################### ## NOTE: Do not escape the quotes around $FILEMASK. ## If you do, no filenames are returned. ##+###################################################### ## FOR TESTING: (to show the 'find' commands as they execute) ## (When called from within the Tk wrapper script, ## this output may interfere with proper processing.) # set -x if test "$VARfiletype" = "" then find "$DIRNAME" \ \( -type d -fprint /dev/stderr \) , \ \( $DEPTHPARM -type f $NAMEPARM "$FILEMASK" \ $FILESIZE_PARM $FILEAGE_PARM -print \) | sort | \ tee "$VARoutfile" # $thisDIR/tee_substitute.sh "$VARoutfile" else find "$DIRNAME" \ \( -type d -fprint /dev/stderr \) , \ \( $DEPTHPARM -type f $NAMEPARM "$FILEMASK" \ $FILESIZE_PARM $FILEAGE_PARM -exec file {} \; \) | \ grep ":.*$VARfiletype" | cut -d: -f1 | sort | \ tee "$VARoutfile" # $thisDIR/tee_substitute.sh "$VARoutfile" fi