forked from emadadel4/itt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newOST.ps1
43 lines (36 loc) · 1.42 KB
/
newOST.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
param (
[string]$json = "./static/Database/OST.json"
)
Write-Host "
+-------------------------------------------------------------------------+
| ___ _____ _____ ____ _ _____ _ ____ _ ____ _____ |
| |_ _|_ _|_ _| | _ \ / \|_ _|/ \ | __ ) / \ / ___|| ____| |
| | | | | | | | | | |/ _ \ | | / _ \ | _ \ / _ \ \___ \| _| |
| | | | | | | | |_| / ___ \| |/ ___ \| |_) / ___ \ ___) | |___ |
| |___| |_| |_| |____/_/ \_\_/_/ \_\____/_/ \_\____/|_____| |
| Made with ♥ By Emad Adel |
+-------------------------------------------------------------------------+
"
try {
# Read existing JSON file
$jsonFilePath = $json
$existingData = Get-Content $json -Raw -ErrorAction Stop | ConvertFrom-Json
# Prompt for input
$name = Read-Host "Enter the track name"
$url = Read-Host "Enter the URL (Example: www.eprojects.orgfree.com/ezio_family.mp3)"
# Store input
$newTrack = @{
name = $name
url = $url
}
# Add new object to existing array
$existingData.Tracks += $newTrack
# Write updated JSON to file
$existingData | ConvertTo-Json -Depth 10 | Set-Content $jsonFilePath -ErrorAction Stop
}
catch {
Write-Host "An error occurred: $_"
}
finally {
Write-Host "Added successfully, Don't forget to build and test it before commit" -ForegroundColor Green
}