From 41ca87ad7c16bbff61f1cafc4db103c6417f07ed Mon Sep 17 00:00:00 2001 From: xrgzs Date: Sun, 27 Oct 2024 19:53:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BA=20=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E7=BD=91=E7=9B=98=E7=9B=B4=E9=93=BE=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E8=A7=A3=E6=9E=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.ps1 | 66 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/build.ps1 b/build.ps1 index f457294..e2b02c0 100644 --- a/build.ps1 +++ b/build.ps1 @@ -4,6 +4,50 @@ $ErrorActionPreference = 'Stop' Set-Location $PSScriptRoot # 下载文件 +function Get-LanzouLink { + param( + [Parameter(Mandatory = $true, Position = 0)] + [string] + $Uri + ) + $sharekey = $Uri -split '/' | Select-Object -Last 1 + if ((Invoke-RestMethod -Uri "https://lanzoui.com/$sharekey") -match 'src="(\/fn\?.\w+)') { + $fn = Invoke-RestMethod -Uri ('https://lanzoui.com/' + $Matches[1]) + } + else { + throw "Failed to get fn. Please check whether the URL is correct." + } + if ($fn -match '\/ajaxm\.php\?file=\d+') { + $ajaxm = $Matches[0] + } + else { + throw "Failed to get ajaxm.php." + } + if ($fn -match "'sign':'(\w+)'") { + $sign = $Matches[1] + } + else { + throw "Failed to get sign." + } + $ajax = Invoke-RestMethod -Uri ('https://lanzoui.com/' + $ajaxm) -Method Post ` + -Headers @{ referer = "https://lanzoui.com/" } ` + -Body @{ 'action' = 'downprocess'; 'signs' = '?ctdf'; 'sign' = $sign } + $directlink = $ajax.dom + '/file/' + $ajax.url + try { + Invoke-WebRequest -Uri $directlink -Method Head -MaximumRedirection 0 -ErrorAction SilentlyContinue ` + -Headers @{ "Accept-Language" = "zh-CN,zh;q=0.9" } + } + catch { + $directlink = $_.Exception.Response.Headers.Location.OriginalString + } + Write-Host -ForegroundColor Yellow "Direct Link of $sharekey is: $directlink" + if ($directlink) { + return $directlink + } + else { + throw "Failed to get direct link." + } +} function Get-LanzouFile { param( [Parameter(Mandatory = $true, Position = 0)] @@ -16,22 +60,28 @@ function Get-LanzouFile { ) Write-Host "Downloading $Uri to $OutFile..." try { - Write-Host "Using api.xrgzs.top..." - Invoke-WebRequest -Uri "https://api.xrgzs.top/lanzou/?type=down&url=$Uri" -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect - + Write-Host "Using PowerShell Function to parse link..." + $directlink = Get-LanzouLink -Uri $Uri + Invoke-WebRequest -Uri $directlink -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect } catch { try { - Write-Host "Using api.hanximeng.com..." - Invoke-WebRequest -Uri "https://api.hanximeng.com/lanzou/?type=down&url=$Uri" -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect + Write-Host "Using api.xrgzs.top to parse link..." + Invoke-WebRequest -Uri "https://api.xrgzs.top/lanzou/?type=down&url=$Uri" -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect } catch { try { - Write-Host "Using lz.qaiu.top..." - Invoke-WebRequest -Uri "https://lz.qaiu.top/parser?url=$Uri" -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect + Write-Host "Using api.hanximeng.com to parse link..." + Invoke-WebRequest -Uri "https://api.hanximeng.com/lanzou/?type=down&url=$Uri" -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect } catch { - Write-Error "Failed to download $Uri. ($_)" + try { + Write-Host "Using lz.qaiu.top to parse link..." + Invoke-WebRequest -Uri "https://lz.qaiu.top/parser?url=$Uri" -OutFile $OutFile -ConnectionTimeoutSeconds 5 -AllowInsecureRedirect + } + catch { + Write-Error "Failed to download $Uri. ($_)" + } } } }