mirror of
https://github.com/phin05/discord-rich-presence-plex
synced 2024-11-22 01:23:02 +00:00
Added config option display.statusIcon
to facilitate uncropped posters
This commit is contained in:
parent
804b190b87
commit
9bcbe949ca
4 changed files with 21 additions and 23 deletions
|
@ -17,6 +17,7 @@ config: models.config.Config = {
|
||||||
"genres": True,
|
"genres": True,
|
||||||
"album": True,
|
"album": True,
|
||||||
"year": True,
|
"year": True,
|
||||||
|
"statusIcon": False,
|
||||||
"remainingTime": False,
|
"remainingTime": False,
|
||||||
"paused": False,
|
"paused": False,
|
||||||
"posters": {
|
"posters": {
|
||||||
|
|
40
core/plex.py
40
core/plex.py
|
@ -232,6 +232,7 @@ class PlexAlertListener(threading.Thread):
|
||||||
stateStrings: list[str] = []
|
stateStrings: list[str] = []
|
||||||
if config["display"]["duration"] and item.duration and mediaType != "track":
|
if config["display"]["duration"] and item.duration and mediaType != "track":
|
||||||
stateStrings.append(formatSeconds(item.duration / 1000))
|
stateStrings.append(formatSeconds(item.duration / 1000))
|
||||||
|
largeText, thumb, smallText, smallThumb = "", "", "", ""
|
||||||
if mediaType == "movie":
|
if mediaType == "movie":
|
||||||
title = shortTitle = item.title
|
title = shortTitle = item.title
|
||||||
if config["display"]["year"] and item.year:
|
if config["display"]["year"] and item.year:
|
||||||
|
@ -239,10 +240,7 @@ class PlexAlertListener(threading.Thread):
|
||||||
if config["display"]["genres"] and item.genres:
|
if config["display"]["genres"] and item.genres:
|
||||||
genres: list[Genre] = item.genres[:3]
|
genres: list[Genre] = item.genres[:3]
|
||||||
stateStrings.append(f"{', '.join(genre.tag for genre in genres)}")
|
stateStrings.append(f"{', '.join(genre.tag for genre in genres)}")
|
||||||
largeText = "Watching a movie"
|
|
||||||
thumb = item.thumb
|
thumb = item.thumb
|
||||||
smallText = ""
|
|
||||||
smallThumb = ""
|
|
||||||
elif mediaType == "episode":
|
elif mediaType == "episode":
|
||||||
title = shortTitle = item.grandparentTitle
|
title = shortTitle = item.grandparentTitle
|
||||||
if config["display"]["year"]:
|
if config["display"]["year"]:
|
||||||
|
@ -251,56 +249,54 @@ class PlexAlertListener(threading.Thread):
|
||||||
title += f" ({grandparent.year})"
|
title += f" ({grandparent.year})"
|
||||||
stateStrings.append(f"S{item.parentIndex:02}E{item.index:02}")
|
stateStrings.append(f"S{item.parentIndex:02}E{item.index:02}")
|
||||||
stateStrings.append(item.title)
|
stateStrings.append(item.title)
|
||||||
largeText = "Watching a TV show"
|
|
||||||
thumb = item.grandparentThumb
|
thumb = item.grandparentThumb
|
||||||
smallText = ""
|
|
||||||
smallThumb = ""
|
|
||||||
elif mediaType == "live_episode":
|
elif mediaType == "live_episode":
|
||||||
title = shortTitle = item.grandparentTitle
|
title = shortTitle = item.grandparentTitle
|
||||||
if item.title != item.grandparentTitle:
|
if item.title != item.grandparentTitle:
|
||||||
stateStrings.append(item.title)
|
stateStrings.append(item.title)
|
||||||
largeText = "Watching live TV"
|
|
||||||
thumb = item.grandparentThumb
|
thumb = item.grandparentThumb
|
||||||
smallText = ""
|
|
||||||
smallThumb = ""
|
|
||||||
elif mediaType == "track":
|
elif mediaType == "track":
|
||||||
title = shortTitle = item.title
|
title = shortTitle = item.title
|
||||||
smallText = item.originalTitle or item.grandparentTitle
|
|
||||||
if config["display"]["album"]:
|
if config["display"]["album"]:
|
||||||
largeText = item.parentTitle
|
largeText = item.parentTitle
|
||||||
if config["display"]["year"]:
|
if config["display"]["year"]:
|
||||||
parent = self.server.fetchItem(item.parentRatingKey)
|
parent = self.server.fetchItem(item.parentRatingKey)
|
||||||
if parent.year:
|
if parent.year:
|
||||||
largeText += f" ({parent.year})"
|
largeText += f" ({parent.year})"
|
||||||
stateStrings.append(smallText)
|
|
||||||
else:
|
|
||||||
largeText = smallText
|
|
||||||
thumb = item.thumb
|
thumb = item.thumb
|
||||||
|
smallText = item.originalTitle or item.grandparentTitle
|
||||||
|
stateStrings.append(smallText)
|
||||||
smallThumb = item.grandparentThumb
|
smallThumb = item.grandparentThumb
|
||||||
else:
|
else:
|
||||||
title = shortTitle = item.title
|
title = shortTitle = item.title
|
||||||
largeText = "Watching a video"
|
|
||||||
thumb = item.thumb
|
thumb = item.thumb
|
||||||
smallText = ""
|
|
||||||
smallThumb = ""
|
|
||||||
if state != "playing" and mediaType != "track":
|
if state != "playing" and mediaType != "track":
|
||||||
if config["display"]["remainingTime"]:
|
if config["display"]["remainingTime"]:
|
||||||
stateStrings.append(f"{formatSeconds((item.duration - viewOffset) / 1000, ':')} left")
|
stateStrings.append(f"{formatSeconds((item.duration - viewOffset) / 1000, ':')} left")
|
||||||
else:
|
else:
|
||||||
stateStrings.append(f"{formatSeconds(viewOffset / 1000, ':')} elapsed")
|
stateStrings.append(f"{formatSeconds(viewOffset / 1000, ':')} elapsed")
|
||||||
|
if not config["display"]["statusIcon"]:
|
||||||
|
stateStrings.append(state.capitalize())
|
||||||
stateText = " · ".join(stateString for stateString in stateStrings if stateString)
|
stateText = " · ".join(stateString for stateString in stateStrings if stateString)
|
||||||
thumbUrl = self.uploadToImgur(thumb) if thumb and config["display"]["posters"]["enabled"] else ""
|
thumbUrl = self.uploadToImgur(thumb) if thumb and config["display"]["posters"]["enabled"] else ""
|
||||||
smallThumbUrl = self.uploadToImgur(smallThumb) if smallThumb and config["display"]["posters"]["enabled"] else ""
|
smallThumbUrl = self.uploadToImgur(smallThumb) if smallThumb and config["display"]["posters"]["enabled"] else ""
|
||||||
activity: models.discord.Activity = {
|
activity: models.discord.Activity = {
|
||||||
"type": mediaTypeActivityTypeMap[mediaType],
|
"type": mediaTypeActivityTypeMap[mediaType],
|
||||||
"details": truncate(title, 120),
|
"details": truncate(title, 120),
|
||||||
"assets": {
|
|
||||||
"large_text": largeText,
|
|
||||||
"large_image": thumbUrl or "logo",
|
|
||||||
"small_text": smallText or state.capitalize(),
|
|
||||||
"small_image": smallThumbUrl or state,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
if config["display"]["statusIcon"]:
|
||||||
|
smallText = smallText or state.capitalize()
|
||||||
|
smallThumbUrl = smallThumbUrl or state
|
||||||
|
if largeText or thumbUrl or smallText or smallThumbUrl:
|
||||||
|
activity["assets"] = {}
|
||||||
|
if largeText:
|
||||||
|
activity["assets"]["large_text"] = largeText
|
||||||
|
if thumbUrl:
|
||||||
|
activity["assets"]["large_image"] = thumbUrl
|
||||||
|
if smallText:
|
||||||
|
activity["assets"]["small_text"] = smallText
|
||||||
|
if smallThumbUrl:
|
||||||
|
activity["assets"]["small_image"] = smallThumbUrl
|
||||||
if stateText:
|
if stateText:
|
||||||
activity["state"] = truncate(stateText, 120)
|
activity["state"] = truncate(stateText, 120)
|
||||||
if config["display"]["buttons"]:
|
if config["display"]["buttons"]:
|
||||||
|
|
|
@ -19,6 +19,7 @@ class Display(TypedDict):
|
||||||
genres: bool
|
genres: bool
|
||||||
album: bool
|
album: bool
|
||||||
year: bool
|
year: bool
|
||||||
|
statusIcon: bool
|
||||||
remainingTime: bool
|
remainingTime: bool
|
||||||
paused: bool
|
paused: bool
|
||||||
posters: Posters
|
posters: Posters
|
||||||
|
|
|
@ -5,7 +5,7 @@ class ActivityType(IntEnum):
|
||||||
LISTENING = 2
|
LISTENING = 2
|
||||||
WATCHING = 3
|
WATCHING = 3
|
||||||
|
|
||||||
class ActivityAssets(TypedDict):
|
class ActivityAssets(TypedDict, total = False):
|
||||||
large_text: str
|
large_text: str
|
||||||
large_image: str
|
large_image: str
|
||||||
small_text: str
|
small_text: str
|
||||||
|
|
Loading…
Reference in a new issue