powershell -ExecutionPolicy Bypass -File "C:\Users\HighTech\Downloads\nw\download.ps1"



$wget = "C:\Users\HighTech\Downloads\nw\wget.exe"
$urls = Get-Content "C:\Users\HighTech\Downloads\nw\urls.txt"

foreach ($m3u8url in $urls) {
    $uri = [System.Uri]$m3u8url
    $relativePath = $uri.Host + $uri.AbsolutePath -replace '/', '\'
    $saveDir = "C:\Users\HighTech\Downloads\nw\" + ($relativePath -replace '\\[^\\]+$', '')

    New-Item -ItemType Directory -Force -Path $saveDir | Out-Null

    $baseUrl = $m3u8url -replace '/[^/]+$', ''
    $m3u8file = $saveDir + "\" + ($m3u8url -split '/')[-1]

    & $wget -O $m3u8file $m3u8url

    $tsList = Get-Content $m3u8file | Where- { $_ -match '\.ts$' }
    foreach ($ts in $tsList) {
        & $wget -c -O "$saveDir\$ts" "$baseUrl/$ts"
    }
}

Read-Host "완료! 엔터 누르면 닫힘"