inital commit
This commit is contained in:
36
get-media.ps1
Normal file
36
get-media.ps1
Normal file
@@ -0,0 +1,36 @@
|
||||
$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
|
||||
}
|
||||
Reference in New Issue
Block a user