potatoqualitee/discordrpc

PSPlex

Laim opened this issue · 2 comments

Laim commented

Hey

It looks like PSPlex has been removed from GitHub and I can't seem to find anywhere else to get it. Do you know of a workaround for getting it working with Plex?

Also, could you add a 'Plexamp' template?

Logo: https://pbs.twimg.com/profile_images/935982169326985216/wNDmNBFa_400x400.jpg

Laim commented

RE: PSPlex

If anyone else comes across this for updating their discord status using this method, you can WebRequest /status/session using your X-Plex-Token and then re-do the discordrpc example to use it, took a bit of trial error and this doesn't have a stop etc. in it but hopefully someone smarter than me can work that out :)

$plex_url = "http://PLEX_SERVER_URL:32400";
$plex_x_token = "TOKEN_HERE";

function global:Get-PlexStatus {

    $plex_content = Invoke-WebRequest "$($plex_url)/status/sessions?X-Plex-Token=$($plex_x_token)" -Headers @{"Cache-Control"="no-cache"}
    [xml]$plex = $plex_content.Content
    $track = $plex.MediaContainer.Track;

    [pscustomobject]@{
    
        Song     = $track.title
        Artist   = $track.grandparentTitle
        EndTime  = [int]$track.duration - [int]$track.viewOffset
        Label    = "🐣"
        Url      = "http://laim.scot"
        Player   = $track.Player;

    }
}

$data = Get-PlexStatus

$params = @{
    Template     = "Plex"
    Details      = $data.Song + " - " + $data.Artist
    State        = "Playing"
    End          = $data.EndTime
    Label        = $data.Label
    Url          = $data.Url
    TimerRefresh = 30
    UpdateScript = {
        
        $data = Get-PlexStatus
        
        if ($data.Player.state -eq "paused") {
            $timestamp = New-DSTimestamp
        } else {
            $timestamp = New-DSTimestamp -End $data.EndTime
        }
        
        $params = @{
            Details      = $data.Song + " - " + $data.Artist
            State        = "Playing..."
            Timestamp    = $timestamp
        }

        Update-DSRichPresence @params
    }
}

Start-DSClient @params