potatoqualitee / discordrpc

Discord Rich Presence Client written in PowerShell
MIT License
47 stars 3 forks source link

PSPlex #5

Open Laim opened 2 years ago

Laim commented 2 years ago

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 2 years ago

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
CyberNeonHD commented 7 months ago

Hi there,

Very late response, but there is a plex template already:

{
    "Product": "Plex",
    "ClientID": "645028677033132033",
    "LargeImage": "plex",
    "LargeText": null,
    "SmallImage": null,
    "SmallText": null,
    "Details": null,
    "Start":  "now"
},

You can find it in clientids.json As for the other things related to Plex, I sadly can't help with that since I use Jellyfin myself.