Last active
July 26, 2018 19:40
-
-
Save tdtgit/0ab83d581028472399eabb1de9edcece to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Your DDNS hostname or static IP | |
HOSTNAME="xxx.xxx.xxx.xxx" | |
# Username on source server | |
USER="root" | |
# Your camera MAC address | |
CAMERA_MAC="7811DCCCXXXX" | |
DATE=`/bin/date +%Y%m%d%H` | |
HOUR=`/bin/date +%H` | |
SRC_BACKUP_DIR="/media/Main/MICAM/xiaomi_camera_videos/$CAMERA_MAC/$DATE" | |
WORKING_DIR="/home/xiaomi_video_backup" | |
DES_BACKUP_DIR="$WORKING_DIR/videos/" | |
# init | |
cd $WORKING_DIR/ | |
# Clean up | |
rm -rf $DES_BACKUP_DIR* | |
rm -rf $DATE.txt | |
# Init | |
mkdir -p $DES_BACKUP_DIR$DATE | |
# Get video from router | |
/usr/bin/sshpass -p 'YourSSHPasswordHere' rsync -avr --rsync-path=/opt/bin/rsync $USER@$HOSTNAME:$SRC_BACKUP_DIR $DES_BACKUP_DIR | |
touch $DATE.txt | |
# Upload to Youtube | |
for filename in $DES_BACKUP_DIR$DATE/*.mp4; do | |
# TITLE=(${filename//\// }) | |
# Video title: "${TITLE[2]:8:9}h${TITLE[3]:0:2}m" | |
# Video category "${TITLE[2]:6:2}-${TITLE[2]:4:2}-${TITLE[2]:0:4}" | |
# echo "Uploading $filename" | |
# /usr/local/bin/youtube-upload --title="${TITLE[2]:8:9}h ${TITLE[3]:0:2}m" --privacy private --client-secrets=/root/.secret/client_secret.json --playlist "${TITLE[2]:6:2}-${TITLE[2]:4:2}-${TITLE[2]:0:4}" $filename | |
echo "file $filename" >> $DATE.txt | |
done | |
# Concat to one file | |
ffmpeg -f concat -safe 0 -i $DATE.txt -preset ultrafast -strict -2 $DES_BACKUP_DIR$DATE.mp4 | |
# Upload to Youtube | |
/usr/local/bin/youtube-upload --title="$HOUR" --description="$(cat $DATE.txt)" --privacy private --playlist "${DATE:6:2}-${DATE:4:2}-${DATE:0:4}" --client-secrets=$WORKING_DIR/cs.json $DES_BACKUP_DIR$DATE.mp4 | |
# Clean up | |
rm -rf $DES_BACKUP_DIR | |
rm -rf $DATE.txt | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment