Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support activity types #91

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions core/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def getAuthToken(id: str, code: str) -> Optional[str]:
"letterboxd": "tmdb",
"musicbrainz": "mbid",
}
discordActivityTypeMap = {
"playing": 0,
"listening": 2,
"watching": 3,
}

class PlexAlertListener(threading.Thread):

Expand Down Expand Up @@ -221,6 +226,7 @@ def handleAlert(self, alert: models.plex.Alert) -> None:
if not config["display"]["hideTotalTime"] and item.duration and mediaType != "track":
stateStrings.append(formatSeconds(item.duration / 1000))
if mediaType == "movie":
type = discordActivityTypeMap.get("watching")
title = shortTitle = item.title
if item.year:
title += f" ({item.year})"
Expand All @@ -230,6 +236,7 @@ def handleAlert(self, alert: models.plex.Alert) -> None:
largeText = "Watching a movie"
thumb = item.thumb
elif mediaType == "episode":
type = discordActivityTypeMap.get("watching")
title = shortTitle = item.grandparentTitle
grandparent = self.server.fetchItem(item.grandparentRatingKey)
if grandparent.year:
Expand All @@ -239,12 +246,14 @@ def handleAlert(self, alert: models.plex.Alert) -> None:
largeText = "Watching a TV show"
thumb = item.grandparentThumb
elif mediaType == "live_episode":
type = discordActivityTypeMap.get("watching")
title = shortTitle = item.grandparentTitle
if item.title != item.grandparentTitle:
stateStrings.append(item.title)
largeText = "Watching live TV"
thumb = item.grandparentThumb
elif mediaType == "track":
type = discordActivityTypeMap.get("listening")
title = shortTitle = item.title
artistAlbum = f"{item.originalTitle or item.grandparentTitle} - {item.parentTitle}"
parent = self.server.fetchItem(item.parentRatingKey)
Expand All @@ -254,6 +263,7 @@ def handleAlert(self, alert: models.plex.Alert) -> None:
largeText = "Listening to music"
thumb = item.thumb
else:
type = discordActivityTypeMap.get("watching")
title = shortTitle = item.title
largeText = "Watching a video"
thumb = item.thumb
Expand All @@ -271,6 +281,7 @@ def handleAlert(self, alert: models.plex.Alert) -> None:
thumbUrl = uploadToImgur(self.server.url(thumb, True), config["display"]["posters"]["maxSize"])
setCacheKey(thumb, thumbUrl)
activity: models.discord.Activity = {
"type": type or discordActivityTypeMap.get("playing"),
"details": truncate(title, 128),
"assets": {
"large_text": largeText,
Expand Down
1 change: 1 addition & 0 deletions models/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ActivityButton(TypedDict):
url: str

class Activity(TypedDict, total = False):
type: int
details: str
state: str
assets: ActivityAssets
Expand Down