minor changes
This commit is contained in:
parent
909015faca
commit
310641ec25
|
@ -40,7 +40,7 @@ music_lib_aac
|
||||||
|
|
||||||
Just run:
|
Just run:
|
||||||
```
|
```
|
||||||
diriterator --base-dir "./music_lib_aac" --target-dir "./music_lib_aac" --filter ".*\.(mp3$)" --cmd "mkdir -p \"\$ITERATOR_TARGET_DIR\" && ffmpeg -i \"\$ITERATOR_FULL_PATH\" -c:a libfdk_aac -vbr 4 \"\$ITERATOR_TARGET_DIR/\$ITERATOR_FILE_NAME_WITHOUT_EXTENSION.m4a\"
|
diriterator --base-dir "./music_lib_aac" --target-dir "./music_lib_aac" --filter ".*\.(mp3$)" --cmd "mkdir -p \"\$ITERATOR_TARGET_DIR\" && ffmpeg -i \"\$ITERATOR_FULL_PATH\" -c:a libfdk_aac -vbr 4 \"\$ITERATOR_TARGET_DIR/\$ITERATOR_FILE_NAME_WITHOUT_EXTENSION.m4a"
|
||||||
```
|
```
|
||||||
|
|
||||||
The repository PKGBUILDs (also on my GitHub page) contains files for building an Arch Linux package.
|
The repository PKGBUILDs (also on my GitHub page) contains files for building an Arch Linux package.
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
shopt -s nullglob # from doc: If set, Bash allows filename patterns which match no files to expand to a null string, rather than themselves.
|
||||||
|
shopt -s dotglob
|
||||||
# define queue
|
# define queue
|
||||||
queue=()
|
queue=()
|
||||||
function queueecho {
|
function queueecho {
|
||||||
for item in "${queue[@]}"
|
for item in "${queue[@]}"; do
|
||||||
do
|
|
||||||
echo $item
|
echo $item
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -11,14 +12,12 @@ function queueexec {
|
||||||
queueecho | parallel "-j$parallelcount" --eta "eval {}"
|
queueecho | parallel "-j$parallelcount" --eta "eval {}"
|
||||||
}
|
}
|
||||||
function iteratedirs {
|
function iteratedirs {
|
||||||
shopt -s nullglob # from doc: If set, Bash allows filename patterns which match no files to expand to a null string, rather than themselves.
|
for item in "$1"/*; do
|
||||||
for item in "$1/"*
|
if [[ -d $item ]]; then
|
||||||
do
|
if [[ $dept == none ]] || [[ $currentlevel -lt $dept ]]; then
|
||||||
if [ -d "$item" ]; then
|
|
||||||
if [[ $dept == none ]] || [ $currentlevel -lt $dept ]; then
|
|
||||||
iteratedirs "${item}" $(($2 + 1)) "${3}${item##*/}/"
|
iteratedirs "${item}" $(($2 + 1)) "${3}${item##*/}/"
|
||||||
fi
|
fi
|
||||||
elif [ -f "$item" ]; then
|
elif [[ -f $item ]]; then
|
||||||
if [[ $filter == "" ]] || [[ "$item" =~ $filter ]]; then
|
if [[ $filter == "" ]] || [[ "$item" =~ $filter ]]; then
|
||||||
name=${item##*/}
|
name=${item##*/}
|
||||||
namewithoutextension=${name%.*}
|
namewithoutextension=${name%.*}
|
||||||
|
@ -68,13 +67,13 @@ do
|
||||||
read=target
|
read=target
|
||||||
elif [[ "--no-confirm" == $arg ]]; then
|
elif [[ "--no-confirm" == $arg ]]; then
|
||||||
noconfirm=true
|
noconfirm=true
|
||||||
elif [[ "--help" == $arg ]]; then
|
elif [[ "--help" == $arg ]] || [[ "-h" == $arg ]]; then
|
||||||
echo "${bold}Runs a script for each file in a directory hierarchy using GNU parallel.${normal}
|
echo "${bold}Runs a script for each file in a directory hierarchy using GNU parallel.${normal}
|
||||||
--base-dir the base directory (./ by default)
|
--base-dir the base directory (./ by default)
|
||||||
--target-dir the target directory (base directory by default)
|
--target-dir the target directory (base directory by default)
|
||||||
--dept the maximal recursion dept (unlimited by default)
|
--dept the maximal recursion dept (unlimited by default)
|
||||||
--cmd the command to be executed
|
--cmd the command to be executed
|
||||||
--filter a regular expression to filter files, eg. ${bold}.*\.(mp4$)${normal}
|
--filter a regular expression to filter files, eg. ${bold}.*\.((mp4$)|(mp3$))${normal}
|
||||||
--args the arguments to be passed to cmd
|
--args the arguments to be passed to cmd
|
||||||
--no-confirm generated commands will be executed without prompt for confirmation
|
--no-confirm generated commands will be executed without prompt for confirmation
|
||||||
--parallel-count the maximal number of commands to be executed parallel
|
--parallel-count the maximal number of commands to be executed parallel
|
||||||
|
@ -118,10 +117,10 @@ ITERATOR_TARGET_DIR Path of the target directory for the curre
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# validate specified arguments, use base directory as target directory if not specified
|
# validate specified arguments, use base directory as target directory if not specified
|
||||||
if [[ $targetdir == "" ]]; then
|
if [[ ! $targetdir ]]; then
|
||||||
targetdir=$basedir
|
targetdir=$basedir
|
||||||
fi
|
fi
|
||||||
if [[ $cmd == "" ]]; then
|
if [[ ! $cmd ]]; then
|
||||||
echo "${bold}${red}Error:${normal} ${bold}No command specified.${normal}"
|
echo "${bold}${red}Error:${normal} ${bold}No command specified.${normal}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -134,11 +133,11 @@ if [[ ${#queue[@]} -ge 1 ]]; then
|
||||||
queueexec
|
queueexec
|
||||||
else
|
else
|
||||||
while true; do
|
while true; do
|
||||||
read -p "${bold}Do you want to execute the commands [y/n]?${normal} " yn
|
read -p "${bold}Do you want to execute ${#queue[@]} commands [y/n]?${normal} " yn
|
||||||
case $yn in
|
case $yn in
|
||||||
[Yy]* ) queueexec; break;;
|
[Yy]*) queueexec; break;;
|
||||||
[Nn]* ) exit;;
|
[Nn]*) exit;;
|
||||||
* ) echo "${bold}Please answer yes or no.${normal}";;
|
*) echo "${bold}Please answer yes or no.${normal}";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue