mirror of
https://github.com/phin05/discord-rich-presence-plex
synced 2024-11-24 18:43:02 +00:00
Added support for artist/music videos
This commit is contained in:
parent
eeeb680877
commit
929bfacaef
2 changed files with 24 additions and 11 deletions
|
@ -45,7 +45,7 @@ The config file is stored in a directory named `data`.
|
||||||
* `buttons` (list) - [Information](#buttons)
|
* `buttons` (list) - [Information](#buttons)
|
||||||
* `label` (string) - The label to be displayed on the button.
|
* `label` (string) - The label to be displayed on the button.
|
||||||
* `url` (string) - A web address or a [dynamic URL placeholder](#dynamic-button-urls).
|
* `url` (string) - A web address or a [dynamic URL placeholder](#dynamic-button-urls).
|
||||||
* `mediaTypes` (list, optional) - If set, the button is displayed only for the specified media types. Valid media types are `movie`, `episode` and `track`.
|
* `mediaTypes` (list, optional) - If set, the button is displayed only for the specified media types. Valid media types are `movie`, `episode`, `track` and `clip`.
|
||||||
* `users` (list)
|
* `users` (list)
|
||||||
* `token` (string) - An access token associated with your Plex account. ([X-Plex-Token](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/), [Authenticating with Plex](https://forums.plex.tv/t/authenticating-with-plex/609370))
|
* `token` (string) - An access token associated with your Plex account. ([X-Plex-Token](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/), [Authenticating with Plex](https://forums.plex.tv/t/authenticating-with-plex/609370))
|
||||||
* `servers` (list)
|
* `servers` (list)
|
||||||
|
|
33
core/plex.py
33
core/plex.py
|
@ -34,6 +34,7 @@ def getAuthToken(id: str, code: str) -> Optional[str]:
|
||||||
}).json()
|
}).json()
|
||||||
return response["authToken"]
|
return response["authToken"]
|
||||||
|
|
||||||
|
validMediaTypes = ["movie", "episode", "track", "clip"]
|
||||||
buttonTypeGuidTypeMap = {
|
buttonTypeGuidTypeMap = {
|
||||||
"imdb": "imdb",
|
"imdb": "imdb",
|
||||||
"tmdb": "tmdb",
|
"tmdb": "tmdb",
|
||||||
|
@ -153,7 +154,14 @@ class PlexAlertListener(threading.Thread):
|
||||||
self.logger.debug("Received alert: %s", stateNotification)
|
self.logger.debug("Received alert: %s", stateNotification)
|
||||||
assert self.server
|
assert self.server
|
||||||
item: PlexPartialObject = self.server.fetchItem(ratingKey)
|
item: PlexPartialObject = self.server.fetchItem(ratingKey)
|
||||||
libraryName: str = item.section().title
|
mediaType: str = item.type
|
||||||
|
if mediaType not in validMediaTypes:
|
||||||
|
self.logger.debug("Unsupported media type '%s', ignoring", mediaType)
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
libraryName: str = item.section().title
|
||||||
|
except:
|
||||||
|
libraryName = "ERROR"
|
||||||
if "blacklistedLibraries" in self.serverConfig and libraryName in self.serverConfig["blacklistedLibraries"]:
|
if "blacklistedLibraries" in self.serverConfig and libraryName in self.serverConfig["blacklistedLibraries"]:
|
||||||
self.logger.debug("Library '%s' is blacklisted, ignoring", libraryName)
|
self.logger.debug("Library '%s' is blacklisted, ignoring", libraryName)
|
||||||
return
|
return
|
||||||
|
@ -202,10 +210,9 @@ class PlexAlertListener(threading.Thread):
|
||||||
self.updateTimeoutTimer = threading.Timer(self.updateTimeoutTimerInterval, self.updateTimeout)
|
self.updateTimeoutTimer = threading.Timer(self.updateTimeoutTimerInterval, self.updateTimeout)
|
||||||
self.updateTimeoutTimer.start()
|
self.updateTimeoutTimer.start()
|
||||||
self.lastState, self.lastSessionKey, self.lastRatingKey = state, sessionKey, ratingKey
|
self.lastState, self.lastSessionKey, self.lastRatingKey = state, sessionKey, ratingKey
|
||||||
mediaType: str = item.type
|
|
||||||
title: str
|
title: str
|
||||||
thumb: str
|
thumb: str
|
||||||
if mediaType in ["movie", "episode"]:
|
if mediaType in ["movie", "episode", "clip"]:
|
||||||
stateStrings: list[str] = [] if config["display"]["hideTotalTime"] else [formatSeconds(item.duration / 1000)]
|
stateStrings: list[str] = [] if config["display"]["hideTotalTime"] else [formatSeconds(item.duration / 1000)]
|
||||||
if mediaType == "movie":
|
if mediaType == "movie":
|
||||||
title = f"{item.title} ({item.year})"
|
title = f"{item.title} ({item.year})"
|
||||||
|
@ -213,26 +220,27 @@ class PlexAlertListener(threading.Thread):
|
||||||
stateStrings.append(f"{', '.join(genre.tag for genre in genres)}")
|
stateStrings.append(f"{', '.join(genre.tag for genre in genres)}")
|
||||||
largeText = "Watching a movie"
|
largeText = "Watching a movie"
|
||||||
thumb = item.thumb
|
thumb = item.thumb
|
||||||
else:
|
elif mediaType == "episode":
|
||||||
title = item.grandparentTitle
|
title = item.grandparentTitle
|
||||||
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"
|
largeText = "Watching a TV show"
|
||||||
thumb = item.grandparentThumb
|
thumb = item.grandparentThumb
|
||||||
|
else:
|
||||||
|
title = item.title
|
||||||
|
largeText = "Watching a video"
|
||||||
|
thumb = item.thumb
|
||||||
if state != "playing":
|
if state != "playing":
|
||||||
if config["display"]["useRemainingTime"]:
|
if config["display"]["useRemainingTime"]:
|
||||||
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")
|
||||||
stateText = " · ".join(stateString for stateString in stateStrings if stateString)
|
stateText = " · ".join(stateString for stateString in stateStrings if stateString)
|
||||||
elif mediaType == "track":
|
else:
|
||||||
title = item.title
|
title = item.title
|
||||||
stateText = f"{item.originalTitle or item.grandparentTitle} - {item.parentTitle} ({self.server.fetchItem(item.parentRatingKey).year})"
|
stateText = f"{item.originalTitle or item.grandparentTitle} - {item.parentTitle} ({self.server.fetchItem(item.parentRatingKey).year})"
|
||||||
largeText = "Listening to music"
|
largeText = "Listening to music"
|
||||||
thumb = item.thumb
|
thumb = item.thumb
|
||||||
else:
|
|
||||||
self.logger.debug("Unsupported media type '%s', ignoring", mediaType)
|
|
||||||
return
|
|
||||||
thumbUrl = ""
|
thumbUrl = ""
|
||||||
if thumb and config["display"]["posters"]["enabled"]:
|
if thumb and config["display"]["posters"]["enabled"]:
|
||||||
thumbUrl = getCacheKey(thumb)
|
thumbUrl = getCacheKey(thumb)
|
||||||
|
@ -242,7 +250,6 @@ class PlexAlertListener(threading.Thread):
|
||||||
setCacheKey(thumb, thumbUrl)
|
setCacheKey(thumb, thumbUrl)
|
||||||
activity: models.discord.Activity = {
|
activity: models.discord.Activity = {
|
||||||
"details": title[:128],
|
"details": title[:128],
|
||||||
"state": stateText[:128],
|
|
||||||
"assets": {
|
"assets": {
|
||||||
"large_text": largeText,
|
"large_text": largeText,
|
||||||
"large_image": thumbUrl or "logo",
|
"large_image": thumbUrl or "logo",
|
||||||
|
@ -250,8 +257,14 @@ class PlexAlertListener(threading.Thread):
|
||||||
"small_image": state,
|
"small_image": state,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
if stateText:
|
||||||
|
activity["state"] = stateText[:128]
|
||||||
if config["display"]["buttons"]:
|
if config["display"]["buttons"]:
|
||||||
guidsRaw: list[Guid] = item.guids if mediaType in ["movie", "track"] else self.server.fetchItem(item.grandparentRatingKey).guids
|
guidsRaw: list[Guid] = []
|
||||||
|
if mediaType in ["movie", "track"]:
|
||||||
|
guidsRaw = item.guids
|
||||||
|
elif mediaType == "episode":
|
||||||
|
guidsRaw = self.server.fetchItem(item.grandparentRatingKey).guids
|
||||||
guids: dict[str, str] = { guidSplit[0]: guidSplit[1] for guidSplit in [guid.id.split("://") for guid in guidsRaw] if len(guidSplit) > 1 }
|
guids: dict[str, str] = { guidSplit[0]: guidSplit[1] for guidSplit in [guid.id.split("://") for guid in guidsRaw] if len(guidSplit) > 1 }
|
||||||
buttons: list[models.discord.ActivityButton] = []
|
buttons: list[models.discord.ActivityButton] = []
|
||||||
for button in config["display"]["buttons"]:
|
for button in config["display"]["buttons"]:
|
||||||
|
|
Loading…
Reference in a new issue