mirror of
https://github.com/phin05/discord-rich-presence-plex
synced 2024-11-24 18:43:02 +00:00
Added support for live TV
This commit is contained in:
parent
1a7b7aad58
commit
7aab6fa6d4
2 changed files with 39 additions and 28 deletions
|
@ -45,7 +45,7 @@ The config file is stored in a directory named `data`.
|
|||
* `buttons` (list) - [Information](#buttons)
|
||||
* `label` (string) - The label to be displayed on the button.
|
||||
* `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`, `track` and `clip`.
|
||||
* `mediaTypes` (list, optional) - If set, the button is displayed only for the specified media types. Valid media types are `movie`, `episode`, `live_episode`, `track` and `clip`.
|
||||
* `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))
|
||||
* `servers` (list)
|
||||
|
|
65
core/plex.py
65
core/plex.py
|
@ -34,7 +34,7 @@ def getAuthToken(id: str, code: str) -> Optional[str]:
|
|||
}).json()
|
||||
return response["authToken"]
|
||||
|
||||
validMediaTypes = ["movie", "episode", "track", "clip"]
|
||||
validMediaTypes = ["movie", "episode", "live_episode", "track", "clip"]
|
||||
buttonTypeGuidTypeMap = {
|
||||
"imdb": "imdb",
|
||||
"tmdb": "tmdb",
|
||||
|
@ -157,7 +157,11 @@ class PlexAlertListener(threading.Thread):
|
|||
ratingKey = int(stateNotification["ratingKey"])
|
||||
assert self.server
|
||||
item: PlexPartialObject = self.server.fetchItem(ratingKey)
|
||||
mediaType: str = item.type
|
||||
mediaType: str
|
||||
if item.key and item.key.startswith("/livetv"):
|
||||
mediaType = "live_episode"
|
||||
else:
|
||||
mediaType = item.type
|
||||
if mediaType not in validMediaTypes:
|
||||
self.logger.debug("Unsupported media type '%s', ignoring", mediaType)
|
||||
return
|
||||
|
@ -218,35 +222,42 @@ class PlexAlertListener(threading.Thread):
|
|||
self.lastState, self.lastSessionKey, self.lastRatingKey = state, sessionKey, ratingKey
|
||||
title: str
|
||||
thumb: str
|
||||
if mediaType in ["movie", "episode", "clip"]:
|
||||
stateStrings: list[str] = [] if config["display"]["hideTotalTime"] else [formatSeconds(item.duration / 1000)]
|
||||
if mediaType == "movie":
|
||||
title = f"{item.title} ({item.year})"
|
||||
genres: list[Genre] = item.genres[:3]
|
||||
stateStrings.append(f"{', '.join(genre.tag for genre in genres)}")
|
||||
largeText = "Watching a movie"
|
||||
thumb = item.thumb
|
||||
elif mediaType == "episode":
|
||||
title = item.grandparentTitle
|
||||
stateStrings.append(f"S{item.parentIndex:02}E{item.index:02}")
|
||||
stateStrings: list[str] = []
|
||||
if not config["display"]["hideTotalTime"] and item.duration:
|
||||
stateStrings.append(formatSeconds(item.duration / 1000))
|
||||
if mediaType == "movie":
|
||||
title = f"{item.title} ({item.year})"
|
||||
genres: list[Genre] = item.genres[:3]
|
||||
stateStrings.append(f"{', '.join(genre.tag for genre in genres)}")
|
||||
largeText = "Watching a movie"
|
||||
thumb = item.thumb
|
||||
elif mediaType == "episode":
|
||||
title = item.grandparentTitle
|
||||
stateStrings.append(f"S{item.parentIndex:02}E{item.index:02}")
|
||||
stateStrings.append(item.title)
|
||||
largeText = "Watching a TV show"
|
||||
thumb = item.grandparentThumb
|
||||
elif mediaType == "livetv":
|
||||
title = item.grandparentTitle
|
||||
if item.title != item.grandparentTitle:
|
||||
stateStrings.append(item.title)
|
||||
largeText = "Watching a TV show"
|
||||
thumb = item.grandparentThumb
|
||||
else:
|
||||
title = item.title
|
||||
largeText = "Watching a video"
|
||||
thumb = item.thumb
|
||||
if state != "playing":
|
||||
if config["display"]["useRemainingTime"]:
|
||||
stateStrings.append(f"{formatSeconds((item.duration - viewOffset) / 1000, ':')} left")
|
||||
else:
|
||||
stateStrings.append(f"{formatSeconds(viewOffset / 1000, ':')} elapsed")
|
||||
stateText = " · ".join(stateString for stateString in stateStrings if stateString)
|
||||
else:
|
||||
largeText = "Watching live TV"
|
||||
thumb = item.grandparentThumb
|
||||
elif mediaType == "track":
|
||||
title = item.title
|
||||
stateText = f"{item.originalTitle or item.grandparentTitle} - {item.parentTitle} ({self.server.fetchItem(item.parentRatingKey).year})"
|
||||
stateStrings.append(f"{item.originalTitle or item.grandparentTitle} - {item.parentTitle} ({self.server.fetchItem(item.parentRatingKey).year})")
|
||||
largeText = "Listening to music"
|
||||
thumb = item.thumb
|
||||
else:
|
||||
title = item.title
|
||||
largeText = "Watching a video"
|
||||
thumb = item.thumb
|
||||
if state != "playing" and mediaType != "track":
|
||||
if config["display"]["useRemainingTime"]:
|
||||
stateStrings.append(f"{formatSeconds((item.duration - viewOffset) / 1000, ':')} left")
|
||||
else:
|
||||
stateStrings.append(f"{formatSeconds(viewOffset / 1000, ':')} elapsed")
|
||||
stateText = " · ".join(stateString for stateString in stateStrings if stateString)
|
||||
thumbUrl = ""
|
||||
if thumb and config["display"]["posters"]["enabled"]:
|
||||
thumbUrl = getCacheKey(thumb)
|
||||
|
|
Loading…
Reference in a new issue