Last active
March 25, 2022 13:36
-
-
Save 4ft35t/8024c8815a115ec134dd15965ed47fc5 to your computer and use it in GitHub Desktop.
Upload Synology photos to FTP. eg: FTP server on Pixel one(2016) to get unlimited Google Photos backup.
This file contains 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
auto(); | |
console.show() | |
var utils = require('utils.js'); | |
pkgName='com.google.android.apps.photos' | |
// 直接启动 | |
app.startActivity({ | |
packageName: pkgName, | |
className: "com.google.android.apps.photos.home.entrypoint.deeplink.HomeDeepLinkActivity", | |
data: "https://photos.google.com/link/freeupspace" | |
}) | |
waitForPackage(pkgName) | |
toastLog('检测到' + pkgName + ',等待 Activity') | |
waitForActivity("com.google.android.apps.photos.devicemanagement.activity.FreeUpSpaceActivity") | |
toastLog('找到释放页 Activity') | |
// 点击释放按钮 | |
if (id("free_up_button").exists()) { | |
utils.click(id("free_up_button")) | |
} | |
toastLog('任务完成') | |
// 返回 app 主界面 | |
back() | |
// 2 次返回退出 app | |
back(); back(); | |
console.hide() |
This file contains 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 | |
SRC=$(dirname $(readlink -f $0)) | |
log_file=$SRC/logs.txt | |
ftp_server='ftp://1.2.3.4:9999' | |
last_time='0000-01-01 00:00:00' | |
# 程序运行一次上传照片数量 | |
limit_size=100 | |
# 记录最后一次上传成功的文件路径, 自动赋值,不要修改 | |
last_ok_file='' | |
# curl 完整路径 | |
# https://github.com/moparisthebest/static-curl/releases | |
curl_bin=$SRC/curl-amd64 | |
# NAS 上图片目录 | |
PHOTO_DIRS="/volume1/photo | |
$(find /volume1/homes/ -maxdepth 2 -type d -name "Photos") | |
" | |
PHOTO_DIRS=$(echo "$PHOTO_DIRS" | tr '\n' ' ') | |
count=0 | |
upload(){ | |
$curl_bin "$ftp_server" -T "$1" || return $? | |
log "$photo" | |
count=$((count + 1)) | |
[ $count -ge $limit_size ] && return 255 | |
# 上面比较失败时,返回值为 1, 修正返回值 | |
return 0 | |
} | |
cleanup(){ | |
exit_code=$1 | |
# 文件不存在,直接退出 | |
[ -f "$last_ok_file" ] || exit $exit_code | |
last_ok_time=$(stat -c %z "$last_ok_file") | |
# 更新 last_time | |
sed -i "7s/=.*/='$last_ok_time'/" $0 | |
# 255 实际已完成 limit_size 任务,修正返回值 | |
[ $exit_code -eq 255 ] && exit_code=0 | |
exit $exit_code | |
} | |
log(){ | |
echo "$(date +%FT%H:%M:%S) $@ done" | tee -a $log_file | |
} | |
while read -r photo | |
do | |
upload "$photo" || cleanup $? | |
last_ok_file="$photo" | |
done < <(find $PHOTO_DIRS -newerct "$last_time" -type f | fgrep -v '@eaDir' | head -n $limit_size) | |
cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment