Skip to content

Commit

Permalink
0.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustLigh committed Apr 28, 2024
1 parent ce1067f commit 68c463e
Show file tree
Hide file tree
Showing 8 changed files with 3,566 additions and 3,538 deletions.
510 changes: 510 additions & 0 deletions AminoLightPy/amino_socket.py

Large diffs are not rendered by default.

4,234 changes: 2,117 additions & 2,117 deletions AminoLightPy/client.py

Large diffs are not rendered by default.

134 changes: 67 additions & 67 deletions AminoLightPy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,83 +16,83 @@
cache = OrderedDict()

class AminoSession(Session):
def __init__(self) -> None:
super().__init__()
self.headers.update({
"NDCDEVICEID": device_id,
"Accept-Encoding": "gzip, deflate",
"User-Agent": "Apple iPhone13,1 iOS v16.5 Main/3.19.0"
})
def __init__(self) -> None:
super().__init__()
self.headers.update({
"NDCDEVICEID": device_id,
"Accept-Encoding": "gzip, deflate",
"User-Agent": "Apple iPhone13,1 iOS v16.5 Main/3.19.0"
})

def request(self, method, url, *args, **kwargs):
def request(self, method, url, *args, **kwargs):

headers = kwargs.get("headers", {})
data = kwargs.get("data", None)
headers = kwargs.get("headers", {})
data = kwargs.get("data", None)

if method.lower() == "post":
if "json" in kwargs and data is None:
data = kwargs.get("json") or {}
data["timestamp"] = int(time() * 1000)
if method.lower() == "post":
if "json" in kwargs and data is None:
data = kwargs.get("json") or {}
data["timestamp"] = int(time() * 1000)

data = dumps(data)
data = dumps(data)

headers["Content-Type"] = "application/json"
headers["NDC-MSG-SIG"] = signature(data)
headers["Content-Type"] = "application/json"
headers["NDC-MSG-SIG"] = signature(data)

elif data is None:
headers["Content-Type"] = "application/x-www-form-urlencoded"
elif data is None:
headers["Content-Type"] = "application/x-www-form-urlencoded"

kwargs["headers"] = headers
if data is not None:
kwargs["data"] = data
kwargs["headers"] = headers
if data is not None:
kwargs["data"] = data

response = super().request(method, url, *args, **kwargs)
response = super().request(method, url, *args, **kwargs)

if response.status_code != 200:
CheckException(response.text)
if response.status_code != 200:
CheckException(response.text)

return response
return response


def upload_media(self, file: BinaryIO, fileType: str) -> str:
"""
Upload file to the amino servers.
**Parameters**
- **file** : File to be uploaded.
**Returns**
- **Success** : Url of the file uploaded to the server.
- **Fail** : :meth:`Exceptions <aminofix.lib.util.exceptions>`
"""
data = file.read()

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)

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

response = self.session.post(
url=f"{api}/g/s/media/upload",
data=data,
headers=custom_headers,
stream=True
)

cache[file_hash] = response.json()["mediaValue"]
if len(cache) >= 32:
cache.popitem(last=False)

return cache[file_hash]
"""
Upload file to the amino servers.
**Parameters**
- **file** : File to be uploaded.
**Returns**
- **Success** : Url of the file uploaded to the server.
- **Fail** : :meth:`Exceptions <aminofix.lib.util.exceptions>`
"""
data = file.read()

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)

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

response = self.session.post(
url=f"{api}/g/s/media/upload",
data=data,
headers=custom_headers,
stream=True
)

cache[file_hash] = response.json()["mediaValue"]
if len(cache) >= 32:
cache.popitem(last=False)

return cache[file_hash]
Loading

0 comments on commit 68c463e

Please sign in to comment.