mirror of
https://github.com/phin05/discord-rich-presence-plex
synced 2024-11-21 17:13:04 +00:00
Downscale poster images before upload
This commit is contained in:
parent
69eef9e94a
commit
aa6088ad23
7 changed files with 16 additions and 3 deletions
8
.github/release-notes/v2.5.0.md
vendored
Normal file
8
.github/release-notes/v2.5.0.md
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
### Release Notes
|
||||
|
||||
* Poster images will now be downscaled to a maximum size of 256x256 before being uploaded (#78)
|
||||
|
||||
### Installation Instructions
|
||||
|
||||
* [Regular](https://github.com/phin05/discord-rich-presence-plex/blob/v2.5.0/README.md#installation)
|
||||
* [Docker](https://github.com/phin05/discord-rich-presence-plex/blob/v2.5.0/README.md#run-with-docker)
|
|
@ -41,6 +41,7 @@ The config file is stored in a directory named `data`.
|
|||
* `posters`
|
||||
* `enabled` (boolean, default: `false`) - Displays media posters if enabled. Requires `imgurClientID`.
|
||||
* `imgurClientID` (string, default: `""`) - [Obtention Instructions](#obtaining-an-imgur-client-id)
|
||||
* `maxSize` (int, default: `256`)
|
||||
* `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).
|
||||
|
|
|
@ -2,7 +2,7 @@ import os
|
|||
import sys
|
||||
|
||||
name = "Discord Rich Presence for Plex"
|
||||
version = "2.4.5"
|
||||
version = "2.5.0"
|
||||
|
||||
plexClientID = "discord-rich-presence-plex"
|
||||
discordClientID = "413407336082833418"
|
||||
|
|
|
@ -18,6 +18,7 @@ config: models.config.Config = {
|
|||
"posters": {
|
||||
"enabled": False,
|
||||
"imgurClientID": "",
|
||||
"maxSize": 256,
|
||||
},
|
||||
"buttons": [],
|
||||
},
|
||||
|
|
|
@ -6,12 +6,14 @@ import io
|
|||
import models.imgur
|
||||
import requests
|
||||
|
||||
def uploadToImgur(url: str) -> Optional[str]:
|
||||
def uploadToImgur(url: str, maxSize: int = 0) -> Optional[str]:
|
||||
try:
|
||||
originalImageBytesIO = io.BytesIO(requests.get(url).content)
|
||||
originalImage = Image.open(originalImageBytesIO)
|
||||
newImage = Image.new("RGB", originalImage.size)
|
||||
newImage.putdata(originalImage.getdata()) # pyright: ignore[reportUnknownMemberType,reportUnknownArgumentType]
|
||||
if maxSize:
|
||||
newImage.thumbnail((maxSize, maxSize))
|
||||
newImageBytesIO = io.BytesIO()
|
||||
newImage.save(newImageBytesIO, subsampling = 0, quality = 90, format = "JPEG")
|
||||
data: models.imgur.UploadResponse = requests.post(
|
||||
|
|
|
@ -229,7 +229,7 @@ class PlexAlertListener(threading.Thread):
|
|||
thumbUrl = getCacheKey(thumb)
|
||||
if not thumbUrl:
|
||||
self.logger.debug("Uploading image to Imgur")
|
||||
thumbUrl = uploadToImgur(self.server.url(thumb, True))
|
||||
thumbUrl = uploadToImgur(self.server.url(thumb, True), config["display"]["posters"]["maxSize"])
|
||||
setCacheKey(thumb, thumbUrl)
|
||||
activity: models.discord.Activity = {
|
||||
"details": title[:128],
|
||||
|
|
|
@ -7,6 +7,7 @@ class Logging(TypedDict):
|
|||
class Posters(TypedDict):
|
||||
enabled: bool
|
||||
imgurClientID: str
|
||||
maxSize: int
|
||||
|
||||
class Button(TypedDict):
|
||||
label: str
|
||||
|
|
Loading…
Reference in a new issue