X-Git-Url: https://gitweb.arthurtaft.net/yt-dlp-wrapper.git/blobdiff_plain/3673b239d1687dba61100bd63bc569b7c7ab1587..2fae73fe195893a538a8764ea8763cae95808009:/windows/yt-dlp-wrapper.ps1?ds=sidebyside diff --git a/windows/yt-dlp-wrapper.ps1 b/windows/yt-dlp-wrapper.ps1 index 515f4fc..f4f48f1 100644 --- a/windows/yt-dlp-wrapper.ps1 +++ b/windows/yt-dlp-wrapper.ps1 @@ -1,28 +1,142 @@ # 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' +$bin_dir = Join-Path -Path $current_dir -ChildPath '\bin' +$sig_dir = Join-Path -Path $current_dir -ChildPath '\sig' +$bin_test = Test-Path -Path $bin_dir +$sig_test = Test-Path -Path $sig_dir +$exe_location = Join-Path -Path $bin_dir -ChildPath '\yt-dlp.exe' +$exe_test = Test-Path -Path $exe_location +$ffmpeg_location = Join-Path -Path $bin_dir -ChildPath '\ffmpeg.exe' +$ffplay_location = Join-Path -Path $bin_dir -ChildPath '\ffplay.exe' +$ffprobe_location = Join-Path -Path $bin_dir -ChildPath '\ffprobe.exe' +$ffmpeg_dll_location = Join-Path -Path $bin_dir -ChildPath '\*.dll' +$ffmpeg_test = Test-Path -Path $ffmpeg_location $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' +$ffmpeg_work_location = Join-Path -Path $work_dir -ChildPath '\ffmpeg-master-latest-win64-gpl-shared\bin\*' $test_audio_dir = Test-Path -Path $audio_dir $test_video_dir = Test-Path -Path $video_dir +$audio_title = Join-Path -Path $audio_dir -ChildPath "'\%(title)s.%(ext)s'" +$video_title = Join-Path -Path $video_dir -ChildPath "'\%(title)s.%(ext)s'" $val = 0 $url = "" +$dl_val = 0 $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 +$ffmpeg_link = "https://github.com/yt-dlp/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl-shared.zip" +$yt_dlp_link = "https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe" +$batch_dl_file = Join-Path -Path $current_dir -ChildPath 'batch-download.txt' -# Remove old ffmpeg signature -Remove-Item $ffmpeg_sig_location +function Get-FFmpeg { -# Remove old yt-dlp signature -Remove-Item $yt_sig_location + param ( + $ffmpeg_link + ) + + # Create work directory to extract archive with new executable + New-Item -Path $current_dir -Name "work" -ItemType "directory" + Invoke-WebRequest $ffmpeg_link -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 $bin_dir + + # Remove work directory + Remove-Item -Recurse -Force $work_dir + + Write-Output "Done!" + +} + +function Convert-BatchLink { + + param ( + $dl_val + ) + + while($dl_val -ne 1){ + # Ask the user if they are downloading audio or video + $Format = Read-Host "Audio or Video?" + + # Download audio + if($Format -eq "audio") { + Invoke-Expression "$exe_location -x -f 'ba' --audio-format mp3 --windows-filenames -o $audio_title -a $batch_dl_file" + $dl_val++ + } + # Download video + elseif($Format -eq "video"){ + 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" + $dl_val++ + } + else { + Write-Output "Response must be 'Audio' or 'Video'!" + continue + } + } +} + +function Convert-Link { + + param ( + $dl_val + ) + + while($dl_val -ne 1) { + # Ask the user if they are downloading audio or video + $Format = Read-Host "Audio or Video?" + + # Download audio + if($Format -eq "audio") { + $url = Read-Host "Enter URL Here" + Invoke-Expression "$exe_location -x -f 'ba' --audio-format mp3 --windows-filenames -o $audio_title $url" + $dl_val++ + } + # Download video + elseif($Format -eq "video"){ + $url = Read-Host "Enter URL Here" + 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" + $dl_val++ + } + else { + Write-Output "Response must be 'Audio' or 'Video'!" + continue + } + } +} + +if($bin_test -ne $true) { + Write-Output "bin directory not found! Creating now!" + New-Item -Path $current_dir -Name "bin" -ItemType "directory" +} + +if($sig_test -ne $true) { + Write-Output "sig directory not found! Creating now!" + New-Item -Path $current_dir -Name "sig" -ItemType "directory" +} + +if($ffmpeg_test -eq $true){ + # Remove old ffmpeg signature + Remove-Item $ffmpeg_sig_location +} else { + Write-Output "ffmpeg executable not found! Downloading now..." + Get-FFmpeg($ffmpeg_link) +} + +if($exe_test -eq $true) { + # Remove old yt-dlp signature + Remove-Item $yt_sig_location +} else { + Write-Output "yt-dlp executable not found! Downloading now..." + Invoke-WebRequest $yt_dlp_link -OutFile $exe_location + Write-Output "Done!" +} Write-Output "Updating ffmpeg signature..." # Download new ffmpeg signature @@ -41,7 +155,7 @@ if($yt_sig_eq_check -ne $true) { 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 + Invoke-WebRequest $yt_dlp_link -OutFile $exe_location Write-Output "Done!" } @@ -49,25 +163,15 @@ if($yt_sig_eq_check -ne $true) { if($ffmpeg_sig_eq_check -ne $true) { Write-Output "Old version ffmpeg found, updating now..." - # Remove old executable + # Remove old executables Remove-Item $ffmpeg_location + Remove-Item $ffprobe_location + Remove-Item $ffplay_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 + # Remove old libraries + Remove-Item $ffmpeg_dll_location - Write-Output "Done!" + Get-FFmpeg($ffmpeg_link) } # Check if audio output directory exists, if not, create it @@ -86,25 +190,20 @@ if($test_video_dir -eq $false) { Write-Output "Done!" } - while($val -ne 1) { - # Ask the user if they are downloading audio or video - $Type = Read-Host "Audio or Video?" - - # Download audio - if($Type -eq "audio") { - $url = Read-Host "Enter URL Here" - Invoke-Expression "$exe_location -x -f 'ba' --audio-format mp3 -o $audio_dir'\%(title)s.%(ext)s' $url" + # Ask the user if they are performing a batch download + $Type = Read-Host "Do you want to batch download using links in the 'batch-downloads.txt' file? (y/n)" + + if($Type -eq "y") { + Convert-BatchLink($dl_val) $val++ } - # Download video - elseif($Type -eq "video"){ - $url = Read-Host "Enter URL Here" - 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" + elseif($Type -eq "n") { + Convert-Link($dl_val) $val++ } - else { - Write-Output "Response must be 'Audio' or 'Video'!" + else{ + Write-Output "Answer must be Y or N!" continue } } \ No newline at end of file