2 $current_dir = Get-Location
3 $bin_dir = Join-Path -Path $current_dir -ChildPath '\bin'
4 $sig_dir = Join-Path -Path $current_dir -ChildPath '\sig'
5 $bin_test = Test-Path -Path $bin_dir
6 $sig_test = Test-Path -Path $sig_dir
7 $exe_location = Join-Path -Path $bin_dir -ChildPath '\yt-dlp.exe'
8 $exe_test = Test-Path -Path $exe_location
9 $ffmpeg_location = Join-Path -Path $bin_dir -ChildPath '\ffmpeg.exe'
10 $ffplay_location = Join-Path -Path $bin_dir -ChildPath '\ffplay.exe'
11 $ffprobe_location = Join-Path -Path $bin_dir -ChildPath '\ffprobe.exe'
12 $ffmpeg_dll_location = Join-Path -Path $bin_dir -ChildPath '\*.dll'
13 $ffmpeg_test = Test-Path -Path $ffmpeg_location
14 $audio_dir = Join-Path -Path $current_dir -ChildPath '\audio'
15 $video_dir = Join-Path -Path $current_dir -ChildPath '\video'
16 $work_dir = Join-Path -Path $current_dir -ChildPath '\work'
17 $ffmpeg_zip_work_location = Join-Path -Path $work_dir -ChildPath 'ffmpeg.zip'
18 $ffmpeg_work_location = Join-Path -Path $work_dir -ChildPath '\ffmpeg-master-latest-win64-gpl-shared\bin\*'
19 $test_audio_dir = Test-Path -Path $audio_dir
20 $test_video_dir = Test-Path -Path $video_dir
21 $audio_title = Join-Path -Path $audio_dir -ChildPath "'\%(title)s.%(ext)s'"
22 $video_title = Join-Path -Path $video_dir -ChildPath "'\%(title)s.%(ext)s'"
26 $yt_sig_location = Join-Path -Path $current_dir -ChildPath '\sig\yt-dlp-windows.sha512'
27 $yt_current_sig = certutil.exe -hashfile $exe_location SHA512
28 $ffmpeg_sig_location = Join-Path -Path $current_dir -ChildPath '\sig\ffmpeg-windows.sha256'
29 $ffmpeg_current_sig = certutil.exe -hashfile $ffmpeg_location SHA256
30 $yt_sig_eq_check = Select-String -Path $yt_sig_location -Pattern $yt_current_sig -SimpleMatch -Quiet
31 $ffmpeg_sig_eq_check = Select-String -Path $ffmpeg_sig_location -Pattern $ffmpeg_current_sig -SimpleMatch -Quiet
32 $ffmpeg_link = "https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl-shared.zip"
33 $yt_dlp_link = "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe"
34 $batch_dl_file = Join-Path -Path $current_dir -ChildPath 'batch-download.txt'
42 # Create work directory to extract archive with new executable
43 New-Item -Path $current_dir -Name "work" -ItemType "directory"
44 Invoke-WebRequest $ffmpeg_link -OutFile $ffmpeg_zip_work_location
45 # Extract archive to work directory
46 Expand-Archive -Path $ffmpeg_zip_work_location -DestinationPath $work_dir
48 # Move new executable to correct location
49 Move-Item -Path $ffmpeg_work_location -Destination $bin_dir
51 # Remove work directory
52 Remove-Item -Recurse -Force $work_dir
58 function Convert-BatchLink {
65 # Ask the user if they are downloading audio or video
66 $Format = Read-Host "Audio or Video?"
69 if($Format -eq "audio") {
70 Invoke-Expression "$exe_location -x -f 'ba' --audio-format mp3 --windows-filenames -o $audio_title -a $batch_dl_file"
74 elseif($Format -eq "video"){
75 Invoke-Expression "$exe_location -f 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' --windows-filenames --sponsorblock-remove sponsor,selfpromo,interaction -o $video_title -a $batch_dl_file"
79 Write-Output "Response must be 'Audio' or 'Video'!"
85 function Convert-Link {
91 while($dl_val -ne 1) {
92 # Ask the user if they are downloading audio or video
93 $Format = Read-Host "Audio or Video?"
96 if($Format -eq "audio") {
97 $url = Read-Host "Enter URL Here"
98 Invoke-Expression "$exe_location -x -f 'ba' --audio-format mp3 --windows-filenames -o $audio_title $url"
102 elseif($Format -eq "video"){
103 $url = Read-Host "Enter URL Here"
104 Invoke-Expression "$exe_location -f 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' --windows-filenames --sponsorblock-remove sponsor,selfpromo,interaction -o $video_title $url"
108 Write-Output "Response must be 'Audio' or 'Video'!"
114 if($bin_test -ne $true) {
115 Write-Output "bin directory not found! Creating now!"
116 New-Item -Path $current_dir -Name "bin" -ItemType "directory"
119 if($sig_test -ne $true) {
120 Write-Output "sig directory not found! Creating now!"
121 New-Item -Path $current_dir -Name "sig" -ItemType "directory"
124 if($ffmpeg_test -eq $true){
125 # Remove old ffmpeg signature
126 Remove-Item $ffmpeg_sig_location
128 Write-Output "ffmpeg executable not found! Downloading now..."
129 Get-FFmpeg($ffmpeg_link)
132 if($exe_test -eq $true) {
133 # Remove old yt-dlp signature
134 Remove-Item $yt_sig_location
136 Write-Output "yt-dlp executable not found! Downloading now..."
137 Invoke-WebRequest $yt_dlp_link -OutFile $exe_location
141 Write-Output "Updating ffmpeg signature..."
142 # Download new ffmpeg signature
143 Invoke-WebRequest https://github.com/arthur-taft/ffmpeg-latest-signatures/releases/latest/download/ffmpeg-windows.sha256 -OutFile $ffmpeg_sig_location
146 Write-Output "Updating yt-dlp signature..."
147 # Download new yt-dlp signature
148 Invoke-WebRequest https://github.com/arthur-taft/yt-dlp-signatures/releases/latest/download/yt-dlp-windows.sha512 -OutFile $yt_sig_location
151 if($yt_sig_eq_check -ne $true) {
152 Write-Output "Old version of yt-dlp found, updating now..."
154 # Remove old executable
155 Remove-Item $exe_location
157 # Download new executable
158 Invoke-WebRequest $yt_dlp_link -OutFile $exe_location
163 if($ffmpeg_sig_eq_check -ne $true) {
164 Write-Output "Old version ffmpeg found, updating now..."
166 # Remove old executables
167 Remove-Item $ffmpeg_location
168 Remove-Item $ffprobe_location
169 Remove-Item $ffplay_location
171 # Remove old libraries
172 Remove-Item $ffmpeg_dll_location
174 Get-FFmpeg($ffmpeg_link)
177 # Check if audio output directory exists, if not, create it
178 if($test_audio_dir -eq $false) {
179 Write-Output "Audio directory not found!"
180 Write-Output "Creating now..."
181 New-Item -Path $current_dir -Name "audio" -ItemType "directory"
185 # Check if video output directory exists, if not, create it
186 if($test_video_dir -eq $false) {
187 Write-Output "Video directory not found!"
188 Write-Output "Creating now..."
189 New-Item -Path $current_dir -Name "video" -ItemType "directory"
194 # Ask the user if they are performing a batch download
195 $Type = Read-Host "Do you want to batch download using links in the 'batch-downloads.txt' file? (y/n)"
198 Convert-BatchLink($dl_val)
201 elseif($Type -eq "n") {
202 Convert-Link($dl_val)
206 Write-Output "Answer must be Y or N!"