]> Arthur Taft Gitweb - yt-dlp-wrapper.git/commitdiff
Remove Hard Coded Values
authorArthur Taft <[email protected]>
Fri, 7 Feb 2025 08:27:26 +0000 (01:27 -0700)
committerArthur Taft <[email protected]>
Fri, 7 Feb 2025 08:27:26 +0000 (01:27 -0700)
Removed hard coded values from the script

yt-dlp-wrapper.ps1

index 5704e6b20fcf94cd7319bee14a4fb645c05e042a..e0a96fcc6ebb52d675a0b6dd787ce8667c3c01e3 100644 (file)
@@ -1,17 +1,28 @@
 # Set Variables
 # Set Variables
-$Path = Join-Path -Path $HOME -ChildPath "\Documents\YouTube"
-$exe = Join-Path -Path $Path -ChildPath "\yt-dlp.exe"
+$current_dir = Get-Location
+$exe_location = Join-Path -Path $current_dir -ChildPath '\bin\yt-dlp.exe'
+$audio_dir = Join-Path -Path $current_dir -ChildPath '\audio'
+$video_dir = Join-Path -Path $current_dir -ChildPath '\video'
+$test_audio_dir = Test-Path -Path $audio_dir
+$test_video_dir = Test-Path -Path $video_dir
 $val = 0
 $url = ""
 
 $val = 0
 $url = ""
 
-# Switch to directory with executable
-Set-Location $Path
-
 # Remove old executable
 # Remove old executable
-Remove-Item yt-dlp.exe
+Remove-Item $exe_location
 
 # Download new executable
 
 # Download new executable
-Invoke-WebRequest https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe -OutFile $exe
+Invoke-WebRequest https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe -OutFile $exe_location
+
+# Check if audio output directory exists, if not, create it
+if($test_audio_dir -eq $false) {
+    New-Item -Path $current_dir -Name "audio" -ItemType "directory"
+}
+
+# Check if video output directory exists, if not, create it
+if($test_video_dir -eq $false) {
+    New-Item -Path $current_dir -Name "video" -ItemType "directory"
+}
 
 
 while($val -ne 1) {
 
 
 while($val -ne 1) {
@@ -21,13 +32,13 @@ while($val -ne 1) {
     # Download audio
     if($Type -eq "audio") {
         $url = Read-Host "Enter URL Here"
     # Download audio
     if($Type -eq "audio") {
         $url = Read-Host "Enter URL Here"
-        ./yt-dlp.exe -x -f 'ba' --audio-format mp3 -o $HOME'\Music\YouTube\output\%(title)s.%(ext)s' $url
+        Invoke-Expression "$exe_location -x -f 'ba' --audio-format mp3 -o $audio_dir'\%(title)s.%(ext)s' $url"
         $val++
     }
     # Download video
     elseif($Type -eq "video"){
         $url = Read-Host "Enter URL Here"
         $val++
     }
     # Download video
     elseif($Type -eq "video"){
         $url = Read-Host "Enter URL Here"
-        ./yt-dlp.exe -f 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' -o $HOME'\Video\output\%(title)s.%(ext)s' $url
+        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"
         $val++
     }
     else {
         $val++
     }
     else {