]> Arthur Taft Gitweb - yt-dlp-wrapper.git/blobdiff - windows/yt-dlp-wrapper.ps1
Add windows auto updating and update gitignore
[yt-dlp-wrapper.git] / windows / yt-dlp-wrapper.ps1
index e0a96fcc6ebb52d675a0b6dd787ce8667c3c01e3..515f4fc02b48ff16e867d5d4de06f89866b2d600 100644 (file)
@@ -1,27 +1,89 @@
 # Set Variables
 $current_dir = Get-Location
 $exe_location = Join-Path -Path $current_dir -ChildPath '\bin\yt-dlp.exe'
 # Set Variables
 $current_dir = Get-Location
 $exe_location = Join-Path -Path $current_dir -ChildPath '\bin\yt-dlp.exe'
+$ffmpeg_location = Join-Path -Path $current_dir -ChildPath '\bin\ffmpeg.exe'
 $audio_dir = Join-Path -Path $current_dir -ChildPath '\audio'
 $video_dir = Join-Path -Path $current_dir -ChildPath '\video'
 $audio_dir = Join-Path -Path $current_dir -ChildPath '\audio'
 $video_dir = Join-Path -Path $current_dir -ChildPath '\video'
+$work_dir = Join-Path -Path $current_dir -ChildPath '\work'
+$ffmpeg_zip_work_location = Join-Path -Path $work_dir -ChildPath 'ffmpeg.zip'
+$ffmpeg_work_location = Join-Path -Path $work_dir -ChildPath '\ffmpeg-master-latest-win64-gpl-shared\bin\ffmpeg.exe'
 $test_audio_dir = Test-Path -Path $audio_dir
 $test_video_dir = Test-Path -Path $video_dir
 $val = 0
 $url = ""
 $test_audio_dir = Test-Path -Path $audio_dir
 $test_video_dir = Test-Path -Path $video_dir
 $val = 0
 $url = ""
+$yt_sig_location = Join-Path -Path $current_dir -ChildPath '\sig\SHA2-512SUMS'
+$yt_current_sig = certutil.exe -hashfile $exe_location SHA512
+$ffmpeg_sig_location = Join-Path -Path $current_dir -ChildPath '\sig\checksums.sha256'
+$ffmpeg_current_sig = certutil.exe -hashfile $ffmpeg_location SHA256
+$yt_sig_eq_check = Select-String -Path $yt_sig_location -Pattern $yt_current_sig -SimpleMatch -Quiet
+$ffmpeg_sig_eq_check = Select-String -Path $ffmpeg_sig_location -Pattern $ffmpeg_current_sig -SimpleMatch -Quiet
 
 
-# Remove old executable
-Remove-Item $exe_location
+# Remove old ffmpeg signature
+Remove-Item $ffmpeg_sig_location
 
 
-# Download new executable
-Invoke-WebRequest https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe -OutFile $exe_location
+# Remove old yt-dlp signature 
+Remove-Item $yt_sig_location
+
+Write-Output "Updating ffmpeg signature..."
+# Download new ffmpeg signature
+Invoke-WebRequest https://github.com/arthur-taft/ffmpeg-latest-signatures/releases/latest/download/checksums.sha256 -OutFile $ffmpeg_sig_location
+Write-Output "Done!"
+
+Write-Output "Updating yt-dlp signature..."
+# Download new yt-dlp signature
+Invoke-WebRequest https://github.com/arthur-taft/yt-dlp-signatures/releases/latest/download/SHA2-512SUMS -OutFile $yt_sig_location
+Write-Output "Done!"
+
+if($yt_sig_eq_check -ne $true) {
+    Write-Output "Old version of yt-dlp found, updating now..."
+
+    # Remove old executable
+    Remove-Item $exe_location
+
+    # Download new executable
+    Invoke-WebRequest https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe -OutFile $exe_location
+
+    Write-Output "Done!"
+}
+
+if($ffmpeg_sig_eq_check -ne $true) {
+    Write-Output "Old version ffmpeg found, updating now..."
+
+    # Remove old executable
+    Remove-Item $ffmpeg_location
+
+    # Create work directory to extract archive with new executable
+    New-Item -Path $current_dir -Name "work" -ItemType "directory"
+
+    # Download new archive
+    Invoke-WebRequest https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl-shared.zip -OutFile $ffmpeg_zip_work_location
+
+    # Extract archive to work directory
+    Expand-Archive -Path $ffmpeg_zip_work_location -DestinationPath $work_dir
+
+    # Move new executable to correct location
+    Move-Item -Path $ffmpeg_work_location -Destination $ffmpeg_location
+
+    # Remove work directory
+    Remove-Item -Recurse -Force $work_dir
+
+    Write-Output "Done!"
+}
 
 # Check if audio output directory exists, if not, create it
 if($test_audio_dir -eq $false) {
 
 # Check if audio output directory exists, if not, create it
 if($test_audio_dir -eq $false) {
+    Write-Output "Audio directory not found!"
+    Write-Output "Creating now..."
     New-Item -Path $current_dir -Name "audio" -ItemType "directory"
     New-Item -Path $current_dir -Name "audio" -ItemType "directory"
+    Write-Output "Done!"
 }
 
 # Check if video output directory exists, if not, create it
 if($test_video_dir -eq $false) {
 }
 
 # Check if video output directory exists, if not, create it
 if($test_video_dir -eq $false) {
+    Write-Output "Video directory not found!"
+    Write-Output "Creating now..."
     New-Item -Path $current_dir -Name "video" -ItemType "directory"
     New-Item -Path $current_dir -Name "video" -ItemType "directory"
+    Write-Output "Done!"
 }
 
 
 }