-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScript.ps1
128 lines (116 loc) · 3.9 KB
/
Script.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function ProcessUrl {
param (
[string]$url
)
Write-Host "Current URL: $url"
# Check if URL is from Spotify
if ($url -match "spotify.com") {
Write-Host "Downloading from Spotify: $url"
# Use spotdl for Spotify URLs
$spotDlCommand = "spotdl"
$spotDlArgs = @(
"$url",
"--output", "$DownloadFolder\%(title)s.%(ext)s"
)
& $spotDlCommand $spotDlArgs
}
else {
Write-Host "Downloading: $url"
# Use yt-dlp for non-Spotify URLs
$ytDlpCommand = "yt-dlp"
# Check if default format is in audio mode
if ($DefaultFormatInfo -eq "audio") {
$ytDlpArgs = @(
"-x", "--audio-format", "mp3", "--embed-thumbnail", "--audio-quality", "0",
"--output", "$DownloadFolder\%(title)s.%(ext)s",
"$url"
)
} else {
$ytDlpArgs = @(
"-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4",
"--merge-output-format", "mp4",
"--output", "$DownloadFolder\%(title)s.%(ext)s",
"$url"
)
}
& $ytDlpCommand $ytDlpArgs
}
Set-Clipboard
$script:LastUrl = $url
}
function MonitorClipboard {
while ($true) {
try {
Write-Host "Monitoring clipboard for URL..."
$url = Get-Clipboard
if (-not [string]::IsNullOrWhiteSpace($url)) {
ProcessUrl $url
}
Start-Sleep -Seconds 2 # Check every 2 seconds
} catch {
Write-Host "An error occurred: $_"
Start-Sleep -Seconds 2 # Wait before retrying
}
}
}
# Set your folders
$Mp3folder = "C:\Musique"
$Videofolder = "C:\Videos"
$DownloadFolder = $Mp3folder
$DefaultFormatInfo = "audio"
$DefaultFormat = "-x --audio-format mp3 --embed-thumbnail --audio-quality 0"
while ($true) {
Clear-Host
Write-Host "1. Use clipboard URL"
Write-Host "2. Enter URL manually"
Write-Host "3. Choose format (Currently: $DefaultFormatInfo)"
Write-Host "4. Exit"
$choice = Read-Host "Choose an option (1-4)"
switch ($choice) {
"1" {
do {
MonitorClipboard
} while ($true)
}
"2" {
do {
$url = Read-Host "Enter the URL (type 'menu' to return to the main menu)"
if ($url -eq 'menu') { break }
ProcessUrl $url
} while ($true)
}
"3" {
do {
Write-Host "Choose format:"
Write-Host "1. Audio"
Write-Host "2. Video"
Write-Host "3. Back to menu"
$formatChoice = Read-Host "Choose format (1-2, default is Audio)"
if ($formatChoice -eq "1") {
$DefaultFormat = "-x --audio-format mp3 --embed-thumbnail --audio-quality 0"
Write-Host "Set to Audio"
$DefaultFormatInfo = "audio"
$DownloadFolder = $Mp3folder
break
} elseif ($formatChoice -eq "2") {
$DefaultFormat = "-f bestvideo+bestaudio --merge-output-format mp4"
Write-Host "Set to Video"
$DefaultFormatInfo = "video"
$DownloadFolder = $Videofolder
break
} elseif ($formatChoice -eq "3") {
break
} else {
Write-Host "Invalid format option, please try again."
}
} while ($true)
}
"4" {
Write-Host "Exiting..."
return
}
default {
Write-Host "Invalid option, please choose again."
}
}
}