37 lines
1.0 KiB
PowerShell
37 lines
1.0 KiB
PowerShell
|
|
$processes = Get-Process spotify
|
|
$title = (Out-String -InputObject $processes.mainWindowTitle) -replace "`n","" -replace "`r",""
|
|
$song = $null
|
|
if (-Not $title.Contains('Spotify')) {
|
|
$song = $title
|
|
}
|
|
|
|
if ($song) {
|
|
# Split the title into artist and song (assuming "Artist - Title" format)
|
|
if ($song -match "^(.*) - (.*)$") {
|
|
$artist = $Matches[1]
|
|
$songTitle = $Matches[2]
|
|
$jsonOutput = @{
|
|
title = $songTitle
|
|
artist = $artist
|
|
amUri = "" # Spotify doesn't directly provide an "amUri" equivalent
|
|
} | ConvertTo-Json
|
|
Write-Output $jsonOutput
|
|
} else {
|
|
#If it doesn't match the artist - title format, just send the title.
|
|
$jsonOutput = @{
|
|
title = $song
|
|
artist = "Unknown"
|
|
amUri = ""
|
|
} | ConvertTo-Json
|
|
Write-Output $jsonOutput
|
|
}
|
|
} else {
|
|
# Send empty JSON if no song is playing
|
|
$jsonOutput = @{
|
|
title = ""
|
|
artist = ""
|
|
amUri = ""
|
|
} | ConvertTo-Json
|
|
Write-Output $jsonOutput
|
|
} |