commit 67b14e5dcbe973ff3bbc6a801585e980335d4e59 Author: Paco Hope Date: Mon Nov 1 22:51:42 2021 -0400 initial commit diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..554d251 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,17 @@ +# License + +Copyright ©2018 Paco Hope + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---- + +This is the "BSD 3-Clause" license from *https://opensource.org/licenses/BSD-3-Clause* diff --git a/README.md b/README.md new file mode 100644 index 0000000..d19b800 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Video Utility scripts + +For now there's just the one script, `handbrake-batch.sh`. + +## `handbrake-batch.sh` + +It recursively decends from a starting point, finding all files of a certain name pattern. It handles names that have spaces in them. I suspect it might not handle files that have lots of dots. (e.g., `party.1.mov` and `party.2.mov`) + +When you run it, it will find every video file that matches the name, and run a standard `HandBrakeCLI` command to convert it. It creates a mirror of the directory hierarchy in a new place, and puts the new video file there. It makes whatever directories are necessary. It will also set the creation and modification times to be the same as the original source file. + +I've tested it on MacOS. Probably runs with minimal modification on Linux. + diff --git a/handbrake-batch.sh b/handbrake-batch.sh new file mode 100755 index 0000000..945d284 --- /dev/null +++ b/handbrake-batch.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# Copyright ©2018 Paco Hope +# See attached LICENSE.md file +# +# Config Variables +SRCDIR="/Volumes/Movies/Library/Home Movies" +DESTBASE="/Volumes/Shared/Movies/converted" +HANDBRAKE_CLI="/Users/paco/bin/HandBrakeCLI" +# The name of the preset, as you see it in the HandBrake window +PRESET="Fast 720p30" +FILEEXT="mp4" + +### --- You shouldn't need to configure stuff below here. --- ### + +export IFS=" +" + +# cd to the starting point +cd "${SRCDIR}" + +# I'm searching for anything named .AVI, .avi, .MOV, or .mov +for FILE in $(find * -type f \( -iname '*avi' -o -iname '*mov' \)) +do + filename="$(basename "${FILE}")" + dirname="$(dirname "${FILE}")" + DESTDIR="${DESTBASE}/${dirname}" + + # If we need to make the destination directory,k do it. + if [ ! -d "${DESTDIR}" ] + then + echo "making \"${DESTDIR}\"" + mkdir -p "${DESTDIR}" + fi + + extension="${filename##*.}" + filename="${filename%.*}" + DESTFILE="${DESTDIR}/${filename}.${FILEEXT}" + + # If the file doesn't already exist, let's run a conversion + if [ ! -r "${DESTFILE}" ] + then + $HANDBRAKE_CLI --verbose=0 \ + -2 -i "${FILE}" \ + -o "${DESTFILE}" \ + --preset="${PRESET}" + # If the command was successful, set the file modification and creation + # times to be the same as the source file. + if [ -r "${DESTFILE}" ] + then + touch -a -m -r "${FILE}" "${DESTFILE}" + fi + else + # Already exists. Just warn and move on. + echo "\"${DESTFILE}\" exists. Skipping." + fi +done