Updated for Ubuntu 22.04. Also fixed merge videos cmin check
[videoscripts/.git] / check_phone_videos_are_in_originals
1 #!/bin/bash
2 # Checks to make sure all videos off of phone have been copied to the Originals directory
3 # If they are missing, it means Nextcloud missed them somehow. Copy them to New Memories then.
4 # 1) First connect the phone to a computer with USB debugging turned on.
5 #    Authorize the connection
6 # 2) Execute the command "adb tcpip 5555"
7 # 3) Run the script, authorize the connection
8 # 4) Run the script again
9 # You should now be able to connect to the device wirelessly
10
11 dcim_path="/storage/emulated/0/DCIM/Camera"
12 originals="/naspool/dropbox/Originals"
13 organized_logs="/var/log/organize"
14 new_memories="/naspool/dropbox/New Memories"
15
16 adb connect 192.168.0.23
17 if [[ $? != 0 ]]; then
18   echo "#ERROR: Unable to connect to phone at 192.168.0.23"
19   exit 1
20 fi
21
22 mp4s_on_phone=$(adb -e shell ls -1 $dcim_path/*.mp4 | xargs -n 1 basename)
23 mp4s_in_originals=$(/bin/ls -1 $originals/*.mp4 | xargs -n 1 basename)
24
25 for i in $mp4s_on_phone; do
26   echo "$mp4s_in_originals" | grep -q $i
27   if [[ $? != 0 ]]; then
28     zgrep -q $i $organized_logs/organize_videos*
29     if [[ $? != 0 ]]; then
30       echo "mp4 not found in originals or organize logs: $i"
31       if [[ ! -e "$new_memories/$i" ]]; then
32         adb -e pull "$dcim_path/$i" "$new_memories"
33       else
34         echo "mp4 already copied into $new_memories"
35       fi
36     else
37       echo "mp4 found in originals or organize logs: $i"
38     fi
39   else
40      echo "mp4 found in originals or organize logs: $i"
41   fi 
42 done