Spotify’s now playing as Skype ‘What’s happening’ text

I went into this one thinking it would be a super simple powershell script. I assumed there would be some sort of powershell integration for Skype to make setting the Mood Text a cake-walk, and then I thought pulling info from Spotify would be a bit of a challenge, but how tough could it be, really? Boy was I in for a shock! Before I knew it I had signed myself up for a Spotify developers account, a Github account, and I was installing .Net SDK’s. This was getting out of hand real fast. But, somehow I made it work. Here’s how I did it. (Full script down the bottom)

Skype Mood Text

I’ll start with the Skype part because that was by far the simplest. The limitation here is that it needs to be run with powershell x86. I haven’t looked into getting it to work with x64 Powershell just yet.

  1. Install the Lync 2013 Client SDK.
  2. Import those modules into the powershell script
    Import-Module “C:Program Files (x86)Microsoft Office 2013LyncSDKAssembliesDesktopMicrosoft.Lync.Controls.dll”;
    Import-Module “C:Program Files (x86)Microsoft Office 2013LyncSDKAssembliesDesktopMicrosoft.Lync.Model.dll”;
  3. Setup some Variables and Objects
    $lc = [Microsoft.Lync.Model.LyncClient]::GetClient();
    $CurrentPersonalNote = "Testing"
    $myContactInfo = New-Object ‘System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]’;
    $myContactInfo.remove([Microsoft.Lync.Model.PublishableContactInformationType]::PersonalNote)
    $myContactInfo.add([Microsoft.Lync.Model.PublishableContactInformationType]::PersonalNote, $PersonalNote)
  4. Push your status to skype
    $cInfo = $lc.self.BeginPublishContactInformation($myContactInfo, $null, $null);
    $lc.self.EndPublishContactInformation($cInfo);

Powershell for Spotify

If I’m being completely honest, I’m still not entirely sure what’s going on here or how I managed to pull it off. I’m not even going to try and explain it here because I’ll just confuse things even more. I’m just gonna link to the Git/blogs I used to get it done.

Githttps://github.com/bmsimons/ps-spotify

Blog to setup Authhttps://bartsimons.me/net-core-and-the-spotify-api-getting-authenticated/

Blog to get powershell working with Spotifyhttps://bartsimons.me/ps-spotify-a-powershell-module-to-control-the-spotify-web-api/

These are very comprehensive instructions, but I’ll add one very important point. Spotify have changed the way permissions work since these posts were published. When editing SpotifyController.cs you need to add user-read-playback-state to the line qb.Add(“scope”, “user-read-private user-read-email”);. The full line should read
qb.Add("scope", "user-read-private user-read-email user-read-playback-state");

Get Current Track from Spotify

  1. Import those spotify modules
    Import-Module C:UsersChrisDocumentsGitHubps-spotifyps-spotify
  2. Pull the current state from Spotify connect
    $Current = Get-SpotifyConnectDevice
  3. Grab the Title and Artist and build the string to be displayed in Skype
    $Artist = $Current.item.artists.name
    $Track = $Current.item.name
    $PersonalNote = "Now Playing: $Track - $Artist"

The Final Script

I’ve added some extra bits and pieces here for fun. The first line launches Spotify so I can replace my desktop shortcut with this script and not have to worry about running Spotify and a script independently of each other. There’s also a couple of loops that will a) check and update the current track as long as Spotify is running, and b) return Skype back to a ‘default’ Mood Text when Spotify is paused.

Here’s the script as it stands right now. I’ll update as I tweak and refine it further.

& Spotify

Import-Module “C:Program Files (x86)Microsoft Office 2013LyncSDKAssembliesDesktopMicrosoft.Lync.Controls.dll”;
Import-Module “C:Program Files (x86)Microsoft Office 2013LyncSDKAssembliesDesktopMicrosoft.Lync.Model.dll”;
Import-Module C:UsersChrisDocumentsGitHubps-spotifyps-spotify

$lc = [Microsoft.Lync.Model.LyncClient]::GetClient();

$CurrentPersonalNote = "Testing"
$myContactInfo = New-Object ‘System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]’;

Do{
$Proc = Get-Process
$Current = Get-SpotifyConnectDevice

IF ($Current.is_playing -eq $false){
$PersonalNote = "#GoRabbitohs"
}ELSE{
$Artist = $Current.item.artists.name
$Track = $Current.item.name
$PersonalNote = "Now Playing: $Track - $Artist"
}

If ($PersonalNote -ne $CurrentPersonalNote){
$myContactInfo.remove([Microsoft.Lync.Model.PublishableContactInformationType]::PersonalNote)
$myContactInfo.add([Microsoft.Lync.Model.PublishableContactInformationType]::PersonalNote, $PersonalNote)

$cInfo = $lc.self.BeginPublishContactInformation($myContactInfo, $null, $null);
$lc.self.EndPublishContactInformation($cInfo);
$CurrentPersonalNote = $PersonalNote
}

Start-Sleep 5
} While ($Proc.Name -contains 'Spotify')

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s