From abcbdcd550a53007fff7af482d5046d1e499793a Mon Sep 17 00:00:00 2001 From: Robert Morrison Date: Fri, 16 Aug 2024 02:14:43 +0100 Subject: [PATCH] feat(PullPix): Add PullPix Introducing PullPix a script I wrote to take images off of a Mavica Floppy disk cameras floppy disk. Although technically it will pull all the images from any directory tree. --- PullPix | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Readme.md | 8 ++++++ 2 files changed, 90 insertions(+) create mode 100755 PullPix diff --git a/PullPix b/PullPix new file mode 100755 index 0000000..6d4aff3 --- /dev/null +++ b/PullPix @@ -0,0 +1,82 @@ +#!/bin/bash +# +SPDX:MIT + +## WE NEED SOME DEPENDENCIES +depcheck() { + if ! command -v "$1" &> /dev/null ; then + echo "Missing dependency $1" + exit 1 + fi +} +depcheck file +depcheck find +depcheck fzf + +## Find the users Pictures Directory +# The order of precedence is as follows +# 1. GSCRIPTS_PICTURES +# 2. XDG_PICTURES_DIR +# 3. HOME/Pictures +if command -v "xdg-user-dir" &> /dev/null; then + XDG_PICTURES_DIR="$(xdg-user-dir PICTURES)" + # this is the proper way of getting this directory + # according to the xdg specs +fi +PICTURESDIR=${GSCRIPTS_PICTURES:-${XDG_PICTURES_DIR:-${HOME}/Pictures}} + +# This would be a rare occurance but we must be safe +if [[ ! -e ${PICTURESDIR} ]] ; then + echo "Could not find ${PICTURESDIR}" >&2 + echo "Ensure it exists and or check your environment" +fi + +# TODO: Make this nice e.g Read the existing folders and present a choice.. +# or at least store the last used name as a variable +read -e -p"Camera Name>" CAMERA_NAME + +# In the event the user is an idiot we just do this. +if [[ -z ${CAMERA_NAME} ]]; then + CAMERA_NAME="Unknown" +fi +CAMERA_NAME=$(tr "[:space:]" "_" <<< "$CAMERA_NAME") + +## After this we need to find all the image files in the current directory +declare -a ALL_FILES +declare -a IMAGES +# To avoid using xargs later we read all the files into an array +readarray -d '' ALL_FILES < <(find . -type f -print0) + +for FILE in "${ALL_FILES[@]}" +do + # Then manually check via this loop if its an image + if [[ "$(file --mime-type "$FILE")" =~ .*image/.* ]]; then + # Before constructing our actual images array + IMAGES+=("$FILE") + fi +done + +echo "Found the Following images" +printf '%s\n' "${IMAGES[@]}" + +# Make sure everything is cool +echo "Do you want to import them to your computer" +# TODO: make this a little better UX +read -r -p"y/N" -n1 CONFIRM +if [[ "$CONFIRM" != "y" ]]; then + exit 0 +fi +echo "" + + +## Using the Information from before create our import folder +CAMERA_ROOT="${PICTURESDIR}/${CAMERA_NAME}" +IMPORT_FOLDER="${CAMERA_ROOT}/$(date -I | tr '-' '/')" +mkdir -p "$IMPORT_FOLDER" + +## Then we safely copy the images into the folder. +# TODO: Perhaps this can now be made more parallel safely? +for FILE in "${IMAGES[@]}" +do + echo "$FILE" + cp -iv -t "$IMPORT_FOLDER" "$FILE" +done diff --git a/Readme.md b/Readme.md index bb19e89..e9ed665 100644 --- a/Readme.md +++ b/Readme.md @@ -69,3 +69,11 @@ split-log " - `fzf` - `xargs` - `bat` + +### PullPix +A simple CLI way to get images from a mounted camera to your computer. +Functionality is still not set in stone. But it works as is. + +## Requirements +- `file` +- `fzf`