]> Git — Sourcephile - julm/camera.git/blob - julm/pull.sh
index: support JPG and MOV formats
[julm/camera.git] / julm / pull.sh
1 #!/usr/bin/env bash
2 host=Xiaomi_SDM439-QRD__SN%3AB0796589_c7565cf60006
3 cd "${0%/*}"
4 set -eux
5
6 uid=$(id -u)
7 year=${year:-$(date +%Y)}
8 # FIXME: handle previous year on new year
9
10 if gio mount -l | grep file:///run/media/"$USER"/disk ||
11 gio mount file:///run/media/"$USER"/disk
12 then
13 find /run/media/julm/disk/DCIM/ -type f -not -name "IMG_*" -not -name "VID_*" |
14 while read -r file; do
15 #--remove-source-files
16 ext=${file##*.}
17 case $(file --mime-type "$file") in
18 *:\ video/*) prefix=VID;;
19 *:\ image/*) prefix=IMG;;
20 esac
21 # rsync -ai --no-inc-recursive --info=progress2 --inplace --partial
22 out=$(date -r "$file" +"$(dirname "$file")/${prefix}_%Y%m%d_%H%M%S")
23 test "$file" = "$out.$ext" ||
24 mv -n "$file" "$out.$ext" ||
25 { i=1; while ! mv -n "$file" "${out}_$i.$ext"; do i=$((i+1)); done; }
26 done
27 fi
28
29 if gio mount -l | grep mtp://"$host" ||
30 gio mount mtp://"$host"/"Carte SD SanDisk"/
31 then
32 mkdir -p "$year"/audio/src
33 test ! -d /run/user/"$uid"/gvfs/mtp:host="$host"/"Espace de stockage interne partagé"/MIUI/sound_recorder ||
34 rsync -ai --no-inc-recursive --info=progress2 --inplace --partial \
35 --remove-source-files \
36 /run/user/"$uid"/gvfs/mtp:host="$host"/"Espace de stockage interne partagé"/MIUI/sound_recorder \
37 "$year"/audio/src/
38
39 fi
40
41 mkdir -p "$year"/src
42 for month in {01..12}; do
43 for src in \
44 /run/media/julm/disk/DCIM/ \
45 /run/user/"$uid"/gvfs/mtp:host="$host"/"Espace de stockage interne partagé"/DCIM/Camera/ \
46 /run/user/"$uid"/gvfs/mtp:host="$host"/"Carte SD SanDisk"/DCIM/Camera/
47 do
48 test ! -e "$src" ||
49 find "$src" -type f -name "???_$year$month*" -print0 |
50 rsync -ai0 --no-inc-recursive --info=progress2 --inplace --partial \
51 --remove-source-files \
52 --files-from - --no-relative \
53 / "$year"/src/"$month"
54 done
55 done