# === YT Audio Cutter PRO Ultimate v3 ===
# by @blublulangit & chatgpt 🚀🔥
# === Config ===
$toolsFolder = "C:\Tools"
$ytDlpExe = "$toolsFolder\yt-dlp.exe"
$ffmpegExe = "$toolsFolder\ffmpeg.exe"
$outputFolder = "$env:USERPROFILE\Downloads"
# === Functions ===
function Test-Internet {
Write-Host "🌐 Checking Internet connection..."
try {
$response = Invoke-WebRequest -Uri "https://www.google.com" -Method Head -TimeoutSec 5 -ErrorAction Stop
Write-Host "✅ Internet OK`n"
}
catch {
Write-Host "❌ No Internet connection! Please connect to Internet first." -ForegroundColor Red
exit
}
}
function Ensure-ToolsFolder {
if (-not (Test-Path $toolsFolder)) {
New-Item -ItemType Directory -Path $toolsFolder | Out-Null
}
}
function Ensure-YTDLP {
Write-Host "🔍 Checking yt-dlp.exe..."
if (-not (Test-Path $ytDlpExe)) {
Write-Host "❌ yt-dlp.exe not found. Downloading..."
Invoke-WebRequest -Uri "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe" -OutFile $ytDlpExe
Write-Host "✅ yt-dlp.exe ready.`n"
} else {
Write-Host "✅ yt-dlp.exe found.`n"
}
}
function Ensure-FFMPEG {
Write-Host "🔍 Checking ffmpeg.exe..."
if (-not (Test-Path $ffmpegExe)) {
Write-Host "❌ ffmpeg.exe not found. Downloading and extracting..."
$ffmpegZip = "$toolsFolder\ffmpeg.zip"
$ffmpegUrl = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip"
Invoke-WebRequest -Uri $ffmpegUrl -OutFile $ffmpegZip
Write-Host "📦 Extracting ffmpeg.zip..."
Expand-Archive -Path $ffmpegZip -DestinationPath $toolsFolder -Force
Remove-Item $ffmpegZip
# Find ffmpeg.exe inside extracted folder
$ffmpegFound = Get-ChildItem -Path $toolsFolder -Recurse -Filter "ffmpeg.exe" | Select-Object -First 1
if ($ffmpegFound) {
Copy-Item $ffmpegFound.FullName -Destination $ffmpegExe -Force
Write-Host "✅ ffmpeg.exe ready.`n"
} else {
Write-Host "❌ ERROR: Failed to extract ffmpeg.exe" -ForegroundColor Red
exit
}
} else {
Write-Host "✅ ffmpeg.exe found.`n"
}
}
# === MAIN ===
Write-Host "==== YT Audio Cutter PRO Ultimate v3 ====" -ForegroundColor Cyan
# Step 1 → Check Internet
Test-Internet
# Step 2 → Ensure Tools folder & tools
Ensure-ToolsFolder
Ensure-YTDLP
Ensure-FFMPEG
# Step 3 → Ensure output folder
if (-not (Test-Path $outputFolder)) {
New-Item -ItemType Directory -Path $outputFolder | Out-Null
}
# Step 4 → User input
$videoUrl = Read-Host "🎵 Paste YouTube Video URL"
$startInput = Read-Host "🎵 Enter START second (leave empty for 0)"
if ([string]::IsNullOrWhiteSpace($startInput)) {
$startSec = 0
} else {
$startSec = [int]$startInput
}
$endInput = Read-Host "🎵 Enter END second (leave empty for FULL duration)"
$useEnd = $true
if ([string]::IsNullOrWhiteSpace($endInput)) {
$useEnd = $false
$endSec = 0
} else {
$endSec = [int]$endInput
}
# Temp full audio filename
$tempAudioFile = Join-Path $outputFolder "temp_full_audio.m4a"
# Get video title (optional, for nice filename)
Write-Host "🎵 Getting video title..."
$videoTitle = & $ytDlpExe --get-title $videoUrl
$videoTitleClean = $videoTitle -replace '[\\/:*?"<>|]', '' -replace '\s+', '_' # Clean filename
# Final output filename
$outputFile = Join-Path $outputFolder "${videoTitleClean}_${startSec}s"
if ($useEnd) {
$outputFile += "_to_${endSec}s"
}
$outputFile += ".mp3"
# STEP 5 → Download audio
Write-Host "⏬ Downloading audio..."
& $ytDlpExe -f bestaudio -o $tempAudioFile $videoUrl
# STEP 6 → Cut audio → convert to MP3 (safe!)
if (Test-Path $tempAudioFile) {
if ($useEnd) {
$duration = $endSec - $startSec
Write-Host "✂️ Cutting audio from $startSec s to $endSec s..."
& $ffmpegExe -ss $startSec -t $duration -i $tempAudioFile -acodec libmp3lame -b:a 192k $outputFile -y
} else {
Write-Host "✂️ Cutting audio from $startSec s to END of video..."
& $ffmpegExe -ss $startSec -i $tempAudioFile -acodec libmp3lame -b:a 192k $outputFile -y
}
# STEP 7 → Cleanup temp
Remove-Item $tempAudioFile
Write-Host "✅ DONE! Saved in: $outputFile" -ForegroundColor Green
} else {
Write-Host "❌ ERROR: Download failed! temp_full_audio.m4a not found." -ForegroundColor Red
}