Skip to content

Commit

Permalink
Merge pull request #2 from xXxCLOTIxXx/patch-1
Browse files Browse the repository at this point in the history
slight improvement in media loading
  • Loading branch information
AugustLigh committed May 6, 2024
2 parents 5da1306 + b8edffb commit 83be547
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions AminoLightPy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import BinaryIO
from collections import OrderedDict
from requests import Session
from mimetypes import guess_type

from .lib.util.exceptions import SpecifyType
from .lib.util import signature, gen_deviceId
Expand Down Expand Up @@ -54,7 +55,7 @@ def request(self, method, url, *args, **kwargs):
return response


def upload_media(self, file: BinaryIO, fileType: str) -> str:
def upload_media(self, file: BinaryIO) -> str:
"""
Upload file to the amino servers.
Expand All @@ -71,15 +72,13 @@ def upload_media(self, file: BinaryIO, fileType: str) -> str:
file_hash = sha1(data).hexdigest()
if file_hash in cache:
return cache[file_hash]

if fileType == "audio":
t = "audio/aac"
elif fileType == "image":
t = "image/jpg"
elif fileType == "gif":
t = "image/gif"
else: raise SpecifyType(fileType)


fileType = guess_type(file.name)[0]
if fileType not in (
"image/gif", "image/jpg",
"audio/aac", "audio/png"
): raise SpecifyType(fileType) #but this check can be removed, I think

custom_headers = self.session.headers
custom_headers["Content-Type"] = t

Expand All @@ -95,4 +94,4 @@ def upload_media(self, file: BinaryIO, fileType: str) -> str:
cache.popitem(last=False)

return cache[file_hash]


0 comments on commit 83be547

Please sign in to comment.