2 $current_dir = Get-Location
3 $exe_location = Join-Path -Path $current_dir -ChildPath '\bin\yt-dlp.exe'
4 $ffmpeg_location = Join-Path -Path $current_dir -ChildPath '\bin\ffmpeg.exe'
5 $audio_dir = Join-Path -Path $current_dir -ChildPath '\audio'
6 $video_dir = Join-Path -Path $current_dir -ChildPath '\video'
7 $work_dir = Join-Path -Path $current_dir -ChildPath '\work'
8 $ffmpeg_zip_work_location = Join-Path -Path $work_dir -ChildPath 'ffmpeg.zip'
9 $ffmpeg_work_location = Join-Path -Path $work_dir -ChildPath '\ffmpeg-master-latest-win64-gpl-shared\bin\ffmpeg.exe'
10 $test_audio_dir = Test-Path -Path $audio_dir
11 $test_video_dir = Test-Path -Path $video_dir
14 $yt_sig_location = Join-Path -Path $current_dir -ChildPath '\sig\SHA2-512SUMS'
15 $yt_current_sig = certutil.exe -hashfile $exe_location SHA512
16 $ffmpeg_sig_location = Join-Path -Path $current_dir -ChildPath '\sig\checksums.sha256'
17 $ffmpeg_current_sig = certutil.exe -hashfile $ffmpeg_location SHA256
18 $yt_sig_eq_check = Select-String -Path $yt_sig_location -Pattern $yt_current_sig -SimpleMatch -Quiet
19 $ffmpeg_sig_eq_check = Select-String -Path $ffmpeg_sig_location -Pattern $ffmpeg_current_sig -SimpleMatch -Quiet
21 # Remove old ffmpeg signature
22 Remove-Item $ffmpeg_sig_location
24 # Remove old yt-dlp signature
25 Remove-Item $yt_sig_location
27 Write-Output "Updating ffmpeg signature..."
28 # Download new ffmpeg signature
29 Invoke-WebRequest https://github.com/arthur-taft/ffmpeg-latest-signatures/releases/latest/download/checksums.sha256 -OutFile $ffmpeg_sig_location
32 Write-Output "Updating yt-dlp signature..."
33 # Download new yt-dlp signature
34 Invoke-WebRequest https://github.com/arthur-taft/yt-dlp-signatures/releases/latest/download/SHA2-512SUMS -OutFile $yt_sig_location
37 if($yt_sig_eq_check -ne $true) {
38 Write-Output "Old version of yt-dlp found, updating now..."
40 # Remove old executable
41 Remove-Item $exe_location
43 # Download new executable
44 Invoke-WebRequest https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe -OutFile $exe_location
49 if($ffmpeg_sig_eq_check -ne $true) {
50 Write-Output "Old version ffmpeg found, updating now..."
52 # Remove old executable
53 Remove-Item $ffmpeg_location
55 # Create work directory to extract archive with new executable
56 New-Item -Path $current_dir -Name "work" -ItemType "directory"
58 # Download new archive
59 Invoke-WebRequest https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl-shared.zip -OutFile $ffmpeg_zip_work_location
61 # Extract archive to work directory
62 Expand-Archive -Path $ffmpeg_zip_work_location -DestinationPath $work_dir
64 # Move new executable to correct location
65 Move-Item -Path $ffmpeg_work_location -Destination $ffmpeg_location
67 # Remove work directory
68 Remove-Item -Recurse -Force $work_dir
73 # Check if audio output directory exists, if not, create it
74 if($test_audio_dir -eq $false) {
75 Write-Output "Audio directory not found!"
76 Write-Output "Creating now..."
77 New-Item -Path $current_dir -Name "audio" -ItemType "directory"
81 # Check if video output directory exists, if not, create it
82 if($test_video_dir -eq $false) {
83 Write-Output "Video directory not found!"
84 Write-Output "Creating now..."
85 New-Item -Path $current_dir -Name "video" -ItemType "directory"
91 # Ask the user if they are downloading audio or video
92 $Type = Read-Host "Audio or Video?"
95 if($Type -eq "audio") {
96 $url = Read-Host "Enter URL Here"
97 Invoke-Expression "$exe_location -x -f 'ba' --audio-format mp3 -o $audio_dir'\%(title)s.%(ext)s' $url"
101 elseif($Type -eq "video"){
102 $url = Read-Host "Enter URL Here"
103 Invoke-Expression "$exe_location -f 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' -o $video_dir'\%(title)s.%(ext)s' $url"
107 Write-Output "Response must be 'Audio' or 'Video'!"