@ECHO OFF

::检查输入
echo.%1>tmp.txt
find ".lanzou" "tmp.txt" | find ".com/" 1>nul 2>nul || goto USAGE
for /f "tokens=1 delims=/ " %%i in ('find ".lanzou" "tmp.txt"') do set part1=%%i
for /f "tokens=2 delims=/ " %%i in ('find ".lanzou" "tmp.txt"') do set part2=%%i
for /f "tokens=3 delims=/ " %%i in ('find ".lanzou" "tmp.txt"') do set part3=%%i
for /f "tokens=4 delims=/ " %%i in ('find ".lanzou" "tmp.txt"') do set part4=%%i
for /f "tokens=5 delims=/ " %%i in ('find ".lanzou" "tmp.txt"') do set part5=%%i
if "%part2%"=="" goto USAGE
if not "%part5%"=="" goto USAGE
::为原始链接增加/tp
if "%part1%"=="https:" (set domain=%part2%) else (set domain=%part1%)
if not "%part2%"=="" set fileid=%part2%
if not "%part3%"=="" set fileid=%part3%
if not "%part4%"=="" set fileid=%part4%
set link_orig=https://%domain%/tp/%fileid%
ECHO.【原始链接】%link_orig%
::获得developer链接
curl -k -A "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25" %link_orig% 1>tmp.txt 2>nul || ECHO.curl解析出错！ && goto :eof
for /f "tokens=4 delims='; " %%i in ('find "var tedomain " "tmp.txt"') do set part1=%%i
for /f "tokens=4 delims='; " %%i in ('find "var domianload " "tmp.txt"') do set part2=%%i
set link_developer=%part1%%part2%
ECHO.【developer链接】%link_developer%
::获得直链
curl -i -k -A "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25" %link_developer% --header "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8" --header "Accept-Encoding: gzip, deflate" --header "Accept-Language: zh-CN,zh;q=0.9" --header "Cache-Control: no-cache" --header "Connection: keep-alive" --header "Pragma: no-cache" --header "Upgrade-Insecure-Requests: 1" 1>tmp.txt 2>nul || ECHO.curl解析出错！ && goto :eof
for /f "tokens=2 delims= " %%i in ('find "location: " "tmp.txt"') do set link_direct="%%i"
ECHO.【直链】%link_direct%
::下载
ECHO.下载中...
aria2c --max-concurrent-downloads=16 --max-connection-per-server=16 --split=16 --file-allocation=none %link_direct% || ECHO.aria2下载出错！ && goto :eof
ECHO.完成！
goto :eof


:USAGE
ECHO.
ECHO. 蓝奏云直链解析 吾爱破解@某贼 2022.12.13
ECHO.
ECHO. 用法：call lzdl.bat 蓝奏文件分享链接（仅支持无密码文件）
ECHO.
ECHO. 示例：call lzdl.bat https://syxz.lanzoub.com/in6nwv6wp4d
ECHO.       call lzdl.bat syxz.lanzoub.com/in6nwv6wp4d
ECHO.       call lzdl.bat https://syxz.lanzoub.com/tp/in6nwv6wp4d
ECHO.
goto :eof
