]> Arthur Taft Gitweb - yt-dlp-wrapper.git/blob - windows/yt-dlp-wrapper.ps1
515f4fc02b48ff16e867d5d4de06f89866b2d600
[yt-dlp-wrapper.git] / windows / yt-dlp-wrapper.ps1
1 # Set Variables
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
12 $val = 0
13 $url = ""
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
20
21 # Remove old ffmpeg signature
22 Remove-Item $ffmpeg_sig_location
23
24 # Remove old yt-dlp signature 
25 Remove-Item $yt_sig_location
26
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
30 Write-Output "Done!"
31
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
35 Write-Output "Done!"
36
37 if($yt_sig_eq_check -ne $true) {
38     Write-Output "Old version of yt-dlp found, updating now..."
39
40     # Remove old executable
41     Remove-Item $exe_location
42
43     # Download new executable
44     Invoke-WebRequest https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe -OutFile $exe_location
45
46     Write-Output "Done!"
47 }
48
49 if($ffmpeg_sig_eq_check -ne $true) {
50     Write-Output "Old version ffmpeg found, updating now..."
51
52     # Remove old executable
53     Remove-Item $ffmpeg_location
54
55     # Create work directory to extract archive with new executable
56     New-Item -Path $current_dir -Name "work" -ItemType "directory"
57
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
60
61     # Extract archive to work directory
62     Expand-Archive -Path $ffmpeg_zip_work_location -DestinationPath $work_dir
63
64     # Move new executable to correct location
65     Move-Item -Path $ffmpeg_work_location -Destination $ffmpeg_location
66
67     # Remove work directory
68     Remove-Item -Recurse -Force $work_dir
69
70     Write-Output "Done!"
71 }
72
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"
78     Write-Output "Done!"
79 }
80
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"
86     Write-Output "Done!"
87 }
88
89
90 while($val -ne 1) {
91     # Ask the user if they are downloading audio or video
92     $Type = Read-Host "Audio or Video?"
93
94     # Download audio
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"
98         $val++
99     }
100     # Download video
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"
104         $val++
105     }
106     else {
107         Write-Output "Response must be 'Audio' or 'Video'!"
108         continue
109     }
110 }