1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
|
output="/storage/emulated/0/Download/缓存转移"
log="$output/log.log"
GR="\033[1;32m" YE="\033[1;33m" CY="\033[1;34m" BL="\033[1;36m" RE="\033[1;31m" WH="\033[1;37m" BO="\033[1m" RES="\033[0m"
yule() { echo -e " $1" } yulen() { echo -en " $1" } sepa() { echo "-------------------------------" } blank() { local n=${1:-1} if ! [[ "$n" =~ ^[0-9]+$ ]]; then echo "注意: 'blank'函数的参数不能为0或负数" >&2 return 1 fi for ((i=1; i<=n; i++)); do echo done }
jsonread() { local file_path="$1" local json_key="$2" if [ ! -f "$file_path" ]; then echo -n "错误:文件 $file_path 不存在。" return 1 fi local value=$(grep -o "\"$json_key\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" "$file_path" | sed -n "s/.*: *\"\(.*\)\".*/\1/p") if [ -z "$value" ]; then echo -n "错误:未找到键 $json_key。" return 1 else echo -n "$value" fi }
dlog() { local datetime=$(date +"%Y-%m-%d %H:%M:%S") local exit_status=$1 echo "[$datetime] 操作: $exit_status" >> $log } errlog() { local datetime=$(date +"%Y-%m-%d %H:%M:%S") local exit_status=$1 echo "[$datetime] 错误: $exit_status" >> $log } finlog() { local datetime=$(date +"%Y-%m-%d %H:%M:%S") local exit_status=$1 echo "[$datetime] 完成: $exit_status" >> $log }
jam() { local i local err_num_yule=$1 if [[ $err_num_yule -lt "10" ]]; then for i in {0..4}; do printf "\033[1G" printf "\033[K" printf "\033[A" done else for n in {0..1}; do printf "\033[1G" printf "\033[K" printf "\033[A" done fi printf "\033[B\033[1G" yule "${RE}输入错误,请输入[1]/[2]/[3]${RES},你的输入:$2" yule "再错误$err_num_yule次会退出脚本" }
wechatdo() { sepa cd /data/data/com.tencent.mm/MicroMsg/${1}/attachment wechat_file_num=$(ls -C | wc -l) wechatfilecopy=$1 ls -C sepa yule "共有:${YE}${wechat_file_num}个文件${RES}" yule "输入${YE}[y]${RES}进行确认,[n]取消" blank yulen "请输入: " read wechat_choice if [[ $wechat_choice == "y" ]]; then sepa yule "${CY}- 复制文件...${RES}" yulen "· 创建./微信/" mkdir "${output}/微信" 2>/dev/null yule "${GR} [完成]${RES}" yulen "· 移动文件到./微信/" cp /data/data/com.tencent.mm/MicroMsg/${wechatfilecopy}/attachment/* ${output}/微信 2>/${output}/error err=$? yule "${GR} [完成]${RES}" if [[ $err == "0" ]]; then yule "${GR}· 复制完成${RES}" sepa if [[ $delete == "yes" ]]; then rm -rf $dir/* yule "${GR}删除源文件成功${RES}" fi finlog "[$name]转移成功" yule "${GR}已完成转移${RES}" yule "路径${output}/$name" else blank sepa blank 2 errtext=$(cat ${output}/error) yule "ERR: $errtext" errlog "[$name]复制文件失败: $errtext" blank 2 yule "${RE}· 复制出错,请检查:${RES}" yule " 1.存储空间是否足够" yule " 2.是否未下载文件" yule " 3.软件是否为旧版" yule " 4.是否未授权Root" fi elif [[ $wechat_choice == "n" ]]; then exit 0 else blank yule "${RE}输入错误${RES}" exit 0 fi }
bilido() { clear blank 2 find "$dir" -maxdepth 10 -type f -name 'entry.json' | while read -r filedir; do prev=$(dirname ${filedir}) foldersize=$(du -sh $prev 2>/dev/null | cut -f1 2>/dev/null) echo "$filedir" >> ${output}/bili nowwechatnum=$(cat ${output}/bili | wc -l) yulen "$nowwechatnum" yule "${CY}$(jsonread $filedir "title")${RES} | ${YE}$foldersize${RES}" done sepa yule "找到 ${YE}$(cat ${output}/bili | wc -l)${RES} 个视频" yule "${GR}[y]确定开始${RES} ${RE}[n]取消并退出${RES}" read bili_choice rm -f ${output}/bili if [[ $bili_choice == "y" ]]; then sepa mkdir ${output}/哔哩哔哩 find "$dir" -maxdepth 10 -type f -name 'entry.json' | while read -r filedir; do folder_name=$(jsonread $filedir "title") mkdir ${output}/哔哩哔哩/${folder_name} 2>/dev/null prev=$(dirname ${filedir}) audio=$(find "$prev" -maxdepth 10 -type f -name 'audio.m4s') cp $audio ${output}/哔哩哔哩/${folder_name} 2>/dev/null video=$(find "$prev" -maxdepth 10 -type f -name 'video.m4s') cp $video ${output}/哔哩哔哩/${folder_name} 2>/dev/null danmaku=$(find "$prev" -maxdepth 10 -type f -name 'danmaku.xml') cp $danmaku ${output}/哔哩哔哩/${folder_name} 2>/dev/null info=$(find "$prev" -maxdepth 10 -type f -name 'entry.json') cp $info ${output}/哔哩哔哩/${folder_name} 2>/dev/null done if [[ $delete == "yes" ]]; then rm -rf $dir/* fi finlog "[哔哩哔哩]转移成功" else exit 0 fi }
main() { if [[ $menu == "1" ]]; then name="哔哩哔哩" dir="/storage/emulated/0/Android/data/tv.danmaku.bili/download/" type="1" suf=".m4s|.json" elif [[ $menu == "2" ]]; then name="微信" dir="/data/data/com.tencent.mm/MicroMsg/" type="1" suf="wechat file" elif [[ $menu == "3" ]]; then name="QQ" dir="/storage/emulated/0/Android/data/com.tencent.mobileqq/Tencent/QQfile_recv/" type="0" suf="all" elif [[ $menu == "4" ]]; then name="Nekogram" dir="/storage/emulated/0/Android/data/tw.nekomimi.nekogram/files/Telegram/" type="1" suf="all" fi main2 } main2() { blank 2 yule "${YE}你选择了${RES} [${BL} $name ${RES}]" if [[ $menu != "2" ]]; then size=$(du -sh "$dir" | cut -f1) yule "${BL}目录大小:${size}${RES}" fi blank yulen "是否${RE}删除原文件${RES} (yes / no): " read delete blank case $delete in yes) yule "操作完成后会删除源文件哦" ;; no) yule "操作完成后不会删除源文件哦" ;; *|\n) yule "输入错误,奖励退出脚本哦" exit 1 ;; esac main3 }
main3() { if [[ $type == "0" && $suf == "all" ]]; then sepa yule "${CY}- 复制文件...${RES}" yulen "· 创建./$name/" mkdir "${output}/$name" 2>/dev/null yule "${GR} [完成]${RES}" yulen "· 移动文件到./$name/" find $dir -maxdepth 1 -type f -exec cp {} ${output}/$name \; 2>/${output}/error err=$? yule "${GR} [完成]${RES}" if [[ $err == "0" ]]; then yule "${GR}· 复制完成${RES}" sepa if [[ $delete == "yes" ]]; then rm -rf $dir/* yule "${GR}删除源文件成功${RES}" fi finlog "[$name]转移成功" yule "${GR}已完成转移${RES}" yule "路径${output}/$name" else blank sepa blank 2 errtext=$(cat ${output}/error) yule "ERR: $errtext" errlog "[$name]复制文件失败: $errtext" blank 2 yule "${RE}· 复制出错,请检查:${RES}" yule " 1.存储空间是否足够" yule " 2.是否未下载文件" yule " 3.软件是否为旧版" yule " 4.是否未授权Root" exit 1 fi elif [[ $type == "1" && $suf == "all" ]]; then sepa yule "${CY}- 复制文件...${RES}" yulen "· 创建./$name/" mkdir "${output}/$name" 2>/dev/null yule "${GR} [完成]${RES}" yulen "· 移动文件到./$name/" cp -r ${dir}* ${output}/${name} 2>/${output}/error err=$? yule "${GR} [完成]${RES}" if [[ $err == "0" ]]; then yule "${GR}· 复制完成${RES}" sepa if [[ $delete == "yes" ]]; then rm -rf $dir/* yule "${GR}删除源文件成功${RES}" fi finlog "[$name]转移成功" yule "${GR}已完成转移${RES}" yule "路径${output}/$name" else blank sepa blank 2 errtext=$(cat ${output}/error) yule "ERR: $errtext" errlog "[$name]复制文件失败: $errtext" blank 2 yule "${RE}· 复制出错,请检查:${RES}" yule " 1.存储空间是否足够" yule " 2.是否未下载文件" yule " 3.软件是否为旧版" yule " 4.是否未授权Root" exit 1 fi
elif [[ $name == "微信" ]]; then clear blank 2 cd $dir 2>/dev/null foldernum=$(find "$dir" -maxdepth 1 -type d -name "????????????????????????????????" | wc -l) if [[ $foldernum -gt "1" ]]; then yule "${BL}您登录过 $foldernum 个微信号,产生了多个目录${RES}" sepa yule "请选择一个目录进行查看:" find "$dir" -maxdepth 1 -type d -name "????????????????????????????????" | while read -r folderdir; do foldername=$(basename $folderdir) foldersize=$(du -sh ${folderdir}/attachment 2>/dev/null | cut -f1 2>/dev/null) if [[ $foldersize == "" ]]; then foldersize="0KB" fi echo "$foldername" >> ${output}/wechat nowwechatnum=$(cat ${output}/wechat | wc -l) yulen "${BL}[$nowwechatnum]" yule "账号:${CY}$foldername${RES} | ${YE}$foldersize${RES}" done yule "- 当前脚本版本最多可支持6个微信号" sepa yulen "请输入[序号]: " read wechat_account case $wechat_account in 1) account_c=$(sed -n "1p" "${output}/wechat") yule "你选择了 ${BL}${account_c}${RES}" wechatdo ${account_c} ;; 2) account_c=$(sed -n "2p" "${output}/wechat") yule "你选择了 ${BL}${account_c}${RES}" wechatdo ${account_c} ;; 3) account_c=$(sed -n "3p" "${output}/wechat") yule "你选择了 ${BL}${account_c}${RES}" wechatdo ${account_c} ;; 4) account_c=$(sed -n "4p" "${output}/wechat") yule "你选择了 ${BL}${account_c}${RES}" wechatdo ${account_c} ;; 5) account_c=$(sed -n "5p" "${output}/wechat") yule "你选择了 ${BL}${account_c}${RES}" wechatdo ${account_c} ;; 6) account_c=$(sed -n "6p" "${output}/wechat") yule "你选择了 ${BL}${account_c}${RES}" wechatdo ${account_c} ;; *) yule "${RE}选择错误或超出最大账号限制${RES}" exit 1 ;; esac rm -f ${output}/wechat else exit 0 fi
elif [[ $name == "哔哩哔哩" ]]; then bilido fi touch ${output}/last.json echo "{\"name\":\"$name\",\"type\":\"$type\",\"suf\":\"$suf\",\"dir\":\"$dir\",\"del\":\"$delete\",\"data\":\"$(date +"%Y-%m-%d %H:%M:%S")\"}" > ${output}/last.json rm -f ${output}/error exit 0 }
menu() { yule "${YE}欢迎使用《缓存转移》${RES}" sepa yule "${BL}- 哔哩哔哩 [1]${RES}" yule "${BL}- 微信 [2]${RES}" yule "${BL}- QQ [3]" yule "${BL}- Nekogram [4]${RES}" for err_num_2 in {10..0}; do sepa yulen "请输入[1]/[2]/[3]/[4]:" read menu_2 case $menu_2 in 1) menu=1 main ;; 2) menu=2 main ;; 3) menu=3 main ;; 4) menu=4 main ;; *|\n) jam $err_num_2 $menu_2 ;; esac done }
mkdir "${output}" echo "$log" touch /storage/emulated/0/Download/缓存转移/log.log if [ -e "$log" ]; then echo "日志文件存在" else touch "$log" fi rm -f ${output}/wechat rm -f ${output}/bili rm -f ${output}/error clear
if [[ -e "${output}/last.json" ]]; then blank 2 yule "上次配置:" yulen "" jsonread ${output}/last.json "data" blank 2 yule "${YE}应用名:${RES}" yulen "" jsonread ${output}/last.json "name" blank 2 yule "${YE}路径:${RES}" yulen "" jsonread ${output}/last.json "dir" blank 2 yule "${YE}是否已分类:${RES}" yulen "" jsonread ${output}/last.json "type" blank 2 yule "${YE}移动的文件后缀:${RES}" yulen "" jsonread ${output}/last.json "suf" blank 2 yule "${YE}完成后删除源文件:${RES}" yulen "" jsonread ${output}/last.json "del" blank 2 sepa yulen "要用上一次的配置吗(yes / no): " read last if [[ $last == "yes" ]]; then name=$(jsonread ${output}/last.json "name") dir=$(jsonread ${output}/last.json "dir") type=$(jsonread ${output}/last.json "type") yule "$type" sleep 5 delete=$(jsonread ${output}/last.json "del") suf=$(jsonread ${output}/last.json "suf") yule "跳转到main3..." main3 fi fi
clear blank 2 yule "${YE}本脚本可以将应用所下载的文件转移到你设定的目录${RES}" blank yule "${BL}已支持应用:${RES}" yule "- 哔哩哔哩" yule "- 微信" yule "- QQ" yule "- Nekogram" blank sepa yulen "${GR}开始[1]${RES}" yulen "${RE} 退出[2]${RES}" yule "${CY} 配置路径[3]${RES}" yule "${BL} 我要学习自己适配应用[4]${RES}"
for err_num in {10..0}; do sepa yulen "请输入[1]/[2]/[3]/[4]:" read menu_1 case $menu_1 in 1) clear blank 2 menu exit 0 ;; 2) blank yule "${GR}脚本已退出,欢迎下次使用${RES}" exit 0 ;; 3) clear blank 2 yulen "功能研发中,请编辑脚本顶部的 output= 进行配置" exit 0 ;; 4) am start -a android.intent.action.VIEW -d "https://baidu.com/" exit 0 ;; *|\n) jam $err_num $menu_1 ;; esac done
blank yule "${RE}你已连续输入错误10次,被系统判定为卡死,已退出脚本"
|