Files
2026-08-09 11:43:39 +03:00

121 lines
3.3 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#requires -Version 5.1
$ErrorActionPreference = "Stop"
# Корень проекта определяется независимо от текущей папки PowerShell.
$ProjectRoot = Split-Path -Parent $PSScriptRoot
$ToolsDir = Join-Path $ProjectRoot "tools"
$OutputDir = Join-Path $ProjectRoot "output"
if (-not (Test-Path $OutputDir)) {
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
}
function Find-Tool {
param(
[Parameter(Mandatory = $true)]
[string]$Name,
[string[]]$LocalNames = @()
)
foreach ($localName in $LocalNames) {
$localPath = Join-Path $ToolsDir $localName
if (Test-Path $localPath -PathType Leaf) {
return (Resolve-Path $localPath).Path
}
}
$command = Get-Command $Name -ErrorAction SilentlyContinue
if ($command) {
return $command.Source
}
return $null
}
function Require-Tool {
param(
[Parameter(Mandatory = $true)]
[string]$Name,
[string[]]$LocalNames = @(),
[string]$InstallHint = ""
)
$tool = Find-Tool -Name $Name -LocalNames $LocalNames
if (-not $tool) {
Write-Host ""
Write-Host "ОШИБКА: не найдена зависимость '$Name'." -ForegroundColor Red
Write-Host "Проверены:"
Write-Host " 1. Папка: $ToolsDir"
Write-Host " 2. Системная переменная PATH"
if ($InstallHint) {
Write-Host ""
Write-Host $InstallHint
}
Write-Host ""
Read-Host "Нажмите Enter для выхода"
exit 1
}
return $tool
}
$YtDlp = Require-Tool `
-Name "yt-dlp" `
-LocalNames @("yt-dlp.exe", "yt-dlp.cmd", "yt-dlp.ps1") `
-InstallHint "Скачать yt-dlp: https://github.com/yt-dlp/yt-dlp/releases/latest"
$Ffmpeg = Require-Tool `
-Name "ffmpeg" `
-LocalNames @("ffmpeg.exe") `
-InstallHint "Скачать FFmpeg: https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full.7z"
$FfmpegDir = Split-Path -Parent $Ffmpeg
Write-Host ""
Write-Host "============================================================"
Write-Host " СКАЧИВАНИЕ ВИДЕО С YOUTUBE"
Write-Host "============================================================"
Write-Host "Результат: $OutputDir"
Write-Host ""
$Url = Read-Host "Введите URL видео с YouTube"
if ([string]::IsNullOrWhiteSpace($Url)) {
Write-Host ""
Write-Host "ОШИБКА: ссылка не введена." -ForegroundColor Red
Read-Host "Нажмите Enter для выхода"
exit 1
}
$OutputTemplate = Join-Path $OutputDir "%(title)s.%(ext)s"
Write-Host ""
Write-Host "Скачивание видео в максимально доступном качестве..."
Write-Host ""
& $YtDlp `
"-f" "bv*+ba/b" `
"--ffmpeg-location" $FfmpegDir `
"-o" $OutputTemplate `
$Url
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host "ОШИБКА: yt-dlp завершил работу с кодом $LASTEXITCODE." -ForegroundColor Red
Read-Host "Нажмите Enter для выхода"
exit $LASTEXITCODE
}
Write-Host ""
Write-Host "Готово." -ForegroundColor Green
Write-Host "Файл сохранён в: $OutputDir"
Write-Host ""
Read-Host "Нажмите Enter для выхода"