mirror of
https://github.com/phin05/discord-rich-presence-plex
synced 2024-11-23 10:03:02 +00:00
Convert poster images to JPG before uploading them
This commit is contained in:
parent
ca7b986ef3
commit
d6ac5e5e90
4 changed files with 51 additions and 3 deletions
36
NOTICE
36
NOTICE
|
@ -463,3 +463,39 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
Pillow
|
||||
https://github.com/python-pillow/Pillow
|
||||
----------------------------------------------------------------------
|
||||
|
||||
The Python Imaging Library (PIL) is
|
||||
|
||||
Copyright © 1997-2011 by Secret Labs AB
|
||||
Copyright © 1995-2011 by Fredrik Lundh
|
||||
|
||||
Pillow is the friendly PIL fork. It is
|
||||
|
||||
Copyright © 2010-2023 by Jeffrey A. Clark (Alex) and contributors.
|
||||
|
||||
Like PIL, Pillow is licensed under the open source HPND License:
|
||||
|
||||
By obtaining, using, and/or copying this software and/or its associated
|
||||
documentation, you agree that you have read, understood, and will comply
|
||||
with the following terms and conditions:
|
||||
|
||||
Permission to use, copy, modify and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appears in all copies, and that
|
||||
both that copyright notice and this permission notice appear in supporting
|
||||
documentation, and that the name of Secret Labs AB or the author not be
|
||||
used in advertising or publicity pertaining to distribution of the software
|
||||
without specific, written prior permission.
|
||||
|
||||
SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
||||
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
|
||||
IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR ANY SPECIAL,
|
||||
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
||||
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
from .config import config
|
||||
from PIL import Image
|
||||
from typing import Optional
|
||||
from utils.logging import logger
|
||||
import io
|
||||
import models.imgur
|
||||
import requests
|
||||
|
||||
def uploadToImgur(url: str) -> 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]
|
||||
newImageBytesIO = io.BytesIO()
|
||||
newImage.save(newImageBytesIO, subsampling = 0, quality = 90, format = "JPEG")
|
||||
data: models.imgur.UploadResponse = requests.post(
|
||||
"https://api.imgur.com/3/image",
|
||||
headers = { "Authorization": f"Client-ID {config['display']['posters']['imgurClientID']}" },
|
||||
files = { "image": requests.get(url).content }
|
||||
files = { "image": newImageBytesIO.getvalue() }
|
||||
).json()
|
||||
if not data["success"]:
|
||||
raise Exception(data["data"]["error"])
|
||||
|
|
7
main.py
7
main.py
|
@ -110,7 +110,10 @@ def testIpc() -> None:
|
|||
discordIpcService.disconnect()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "test-ipc":
|
||||
mode = sys.argv[1] if len(sys.argv) > 1 else ""
|
||||
if not mode:
|
||||
main()
|
||||
elif mode == "test-ipc":
|
||||
testIpc()
|
||||
else:
|
||||
main()
|
||||
print(f"Invalid mode: {mode}")
|
||||
|
|
|
@ -2,3 +2,4 @@ PlexAPI==4.10.1
|
|||
requests==2.31.0
|
||||
websocket-client==1.3.2
|
||||
PyYAML==6.0.1
|
||||
Pillow==10.1.0
|
||||
|
|
Loading…
Reference in a new issue