#!/bin/bash

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

mkdir -p $1/temp
cd $1/temp
#wget -c  --show-progress "$docker_addr/d/元数据/pikpak.mp4"
#wget -c  --show-progress "$docker_addr/d/元数据/all.mp4"
#wget -c  --show-progress "$docker_addr/d/元数据/config.mp4"
rm config.mp4
aria2c -o config.mp4 --enable-color=false  --allow-overwrite=true --auto-file-renaming=false -c -x6 "$docker_addr/d/元数据/config.mp4"
aria2c -o pikpak.mp4 --enable-color=false --allow-overwrite=true --auto-file-renaming=false -c -x6 "$docker_addr/d/元数据/pikpak.mp4"
aria2c -o all.mp4 --enable-color=false --allow-overwrite=true --auto-file-renaming=false -c -x6 "$docker_addr/d/元数据/all.mp4"

mkdir -p $1/xiaoya
chmod 777 $1/xiaoya
start_time1=`date +%s`
cd $1
7z x -aoa -mmt=16 temp/config.mp4 2>/dev/null

cd $1/xiaoya
rm -rf test
7z x -aoa -mmt=16 $1/temp/pikpak.mp4 2>/dev/null
7z x -aoa -mmt=16 $1/temp/all.mp4 2>/dev/null

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

#start_time=`date +%s`
#echo "开始替换docker地址........"
#find ./ -name "*.strm" -exec sed \-i "s#DOCKER_ADDRESS|\(http:\/\/[0-9.]\+:[0-9]\+\)#$docker_addr#g; s# #%20#g; s#|#%7C#g" {} \;
#fdfind --extension strm --exec sed \-i "s#DOCKER_ADDRESS|\(http:\/\/[0-9.]\+:[0-9]\+\)#$docker_addr#g; s# #%20#g; s#|#%7C#g" {} \;
#find ./ -name "*.strm" -exec sed \-i "s# #%20#g; s#|#%7C#g" {} \;
#end_time=`date +%s`
#total_time=$((end_time - start_time))
#total_time=$((total_time / 60))
#echo "替换执行时间：$total_time 分钟"
#chmod -R 777 *
echo "刮削数据已生成"

