rearrange media-process module
This commit is contained in:
parent
e7bd38a8d4
commit
b855d75b8a
5 changed files with 138 additions and 121 deletions
|
|
@ -33,70 +33,6 @@
|
|||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function camera-copy() {
|
||||
if [[ $# -ne 2 ]]; then
|
||||
echo "Usage: camera-copy <source_dir> <destination>"
|
||||
echo ""
|
||||
echo "Copy video files organized by date (YYYY-MM-DD/filename)"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " camera-copy /media/sdcard/DCIM ~/Videos/imports"
|
||||
echo " camera-copy /Volumes/CAMERA/DCIM user@nas:/backup/camera"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local SOURCE="$1"
|
||||
local DEST="$2"
|
||||
|
||||
if [[ ! -d "$SOURCE" ]]; then
|
||||
echo "Error: Source directory does not exist: $SOURCE"
|
||||
return 1
|
||||
fi
|
||||
|
||||
_get_video_date() {
|
||||
local file="$1"
|
||||
local raw_date
|
||||
|
||||
raw_date=$(${pkgs.exiftool}/bin/exiftool -s3 -d '%Y-%m-%d' \
|
||||
-DateTimeOriginal -CreateDate -MediaCreateDate "$file" 2>/dev/null | head -1)
|
||||
|
||||
if [[ -n "$raw_date" && "$raw_date" != "0000-00-00" ]]; then
|
||||
echo "$raw_date"
|
||||
else
|
||||
local mtime
|
||||
mtime=$(${pkgs.coreutils}/bin/stat -c '%Y' "$file" 2>/dev/null)
|
||||
${pkgs.coreutils}/bin/date -d "@$mtime" +%Y-%m-%d
|
||||
fi
|
||||
}
|
||||
|
||||
local copied=0
|
||||
local failed=0
|
||||
|
||||
while IFS= read -r -d "" file; do
|
||||
local filename=$(basename "$file")
|
||||
|
||||
[[ "$filename" == .* ]] && continue
|
||||
|
||||
local date_dir=$(_get_video_date "$file")
|
||||
local year=''${date_dir:0:4}
|
||||
|
||||
echo "[$date_dir] $filename"
|
||||
|
||||
if ${pkgs.rsync}/bin/rsync -a --mkpath --progress --partial --ignore-existing \
|
||||
"$file" "$DEST/$year/$date_dir/$filename"; then
|
||||
((copied++)) || true
|
||||
else
|
||||
echo " Failed to copy: $file"
|
||||
((failed++)) || true
|
||||
fi
|
||||
done < <(find "$SOURCE" -type f \( -iname "*.mp4" -o -iname "*.mov" -o -iname "*.mts" -o -iname "*.m2ts" -o -iname "*.avi" \) -print0)
|
||||
|
||||
echo ""
|
||||
echo "=== Summary ==="
|
||||
echo "Copied: $copied"
|
||||
echo "Failed: $failed"
|
||||
}
|
||||
'';
|
||||
|
||||
programs.zsh.shellAliases = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue