#!/bin/bash

if  [ $3 ]; then
        docker_addr=$3
elif [ -s /etc/xiaoya/docker_address.txt ]; then
	docker_addr=$(head -n1 /etc/xiaoya/docker_address.txt)
else
	echo "请先配置 /etc/xiaoya/docker_address.txt，以便获取docker 地址"
	exit
fi

max_size=42327932100

if [ "$2" == "all" ]; then
	cd $1/temp
	rm config.mp4
	aria2c -o config.mp4 --enable-color=false --auto-file-renaming=false --allow-overwrite=true -c -x6 "$docker_addr/d/元数据/config.mp4"
	aria2c -o pikpak.mp4 --enable-color=false --auto-file-renaming=false --allow-overwrite=true -c -x6 "$docker_addr/d/元数据/pikpak.mp4"
	aria2c -o all.mp4 --enable-color=false --auto-file-renaming=false --allow-overwrite=true -c -x6 "$docker_addr/d/元数据/all.mp4"
fi

cd $1
echo "执行解压............"
start_time1=`date +%s`
config_size=$(du -k temp/config.mp4 |cut -f1)
if [[ "$config_size" -le 3200000 ]]; then
	echo "config.mp4 下载不完整，文件大小(in KB):$config_size 小于预期"
	exit 1
fi
7z x -bb1 -aoa -mmt=16 temp/config.mp4 2>/dev/null

cd $1/xiaoya
rm -rf test
all_size=$(du -k $1/temp/all.mp4 |cut -f1)
if [[ "$all_size" -le 30000000 ]]; then
        echo "all.mp4 下载不完整，文件大小(in KB):$all_size 小于预期"
        exit 1
fi
7z x -bb1 -aoa -mmt=16 $1/temp/all.mp4 2>/dev/null

pikpak_size=$(du -k $1/temp/pikpak.mp4 |cut -f1)
if [[ "$pikpak_size" -le 14000000 ]]; then
        echo "pikpak.mp4 下载不完整，文件大小(in KB):$pikpak_size 小于预期"
        exit 1
fi
7z x -bb1 -aoa -mmt=16 $1/temp/pikpak.mp4 2>/dev/null

end_time1=`date +%s`
total_time1=$((end_time1 - start_time1))
total_time1=$((total_time1 / 60))
echo "解压执行时间：$total_time1 分钟"

host=$(echo $docker_addr|cut -f1,2 -d:)
echo -e "\033[33m"
echo "刮削数据已经解压完成，请登入$host:2345，用户名:xiaoya   密码:1234"
echo -e "\033[0m"
