Get videos from DR900-2CH dashcam

This script does the following:

1 – Checks to see if the dashcam is on the network (and won’t proceed unless it is)
2 – Gets list of files available
3 – Sort list into alphanumeric order (so it starts with the oldest files first)
4 – Checks if directory exists for the date of the file it’s processing, and if not then creates it
5 – Downloads file into the corresponding directory with the same date (if doesn’t already exist)

#!/bin/bash

# Check to see if the dashcam is on the network
if ping -c 1 192.168.50.3
then
 CAR=1;
 echo "Car is on the network";
else
 CAR=0;
 echo "Car is not on the network";
fi


if [ $CAR -eq 1 ];
then



# Get the list of  video files on the dashcam

curl http://192.168.50.3/blackvue_vod.cgi | grep mp4 | cut -d/ -f3 | cut -d, -f1  > filelistunsorted



# Sort the list by alphanumeric order (and therefore time order starting with 
oldest files first)

sort -t= filelistunsorted -o filelist



# Read each line in the list, and grab the date from the file name. Check to see if a directory exists for the date of the current file, and if not then create it

while read -r line; do
 currentfile="$line";
 echo "Current file is $line";
 currentdate="$(echo $currentfile | cut -d_ -f1)"
 echo "Current date is $currentdate";
 if [ -d $currentdate ]; then
        echo "dir exists"
 else
  mkdir "$currentdate"
 fi



# See if the current file exists in its directory, and if not then grab it from the dashcam

 cd $currentdate
 if [ -f $currentfile ]; then
  echo "File $currentfile exists. Skipping download."
 else
  echo "File $currentfile does not exist. Downloading $currentfile"
  curl "http://192.168.50.3/Record/$currentfile" > $currentfile.part 
  mv $currentfile.part $currentfile 
 fi
 cd ..
done < filelist

fi