Skip to content

Commit

Permalink
Add get_album_files()
Browse files Browse the repository at this point in the history
  • Loading branch information
redphx committed May 21, 2023
1 parent 94cbe51 commit 3d8b08a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
38 changes: 32 additions & 6 deletions apixoo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class APIxoo(object):
'User-Agent': 'Aurabox/3.1.10 (iPad; iOS 14.8; Scale/2.00)',
}

def __init__(self, email: str, password: str = None, md5_password: str = None, is_secure=True):
def __init__(
self, email: str, password: str = None, md5_password: str = None, is_secure=True
):
# Make sure at least one password param is passed
if not any([password, md5_password]):
raise Exception('Empty password!')
Expand All @@ -47,10 +49,12 @@ def _full_url(self, path: str, server: Server = Server.API) -> str:
def _send_request(self, endpoint: ApiEndpoint, payload: dict = {}):
"""Send request to API server"""
if endpoint != ApiEndpoint.USER_LOGIN:
payload.update({
'Token': self._user['token'],
'UserId': self._user['user_id'],
})
payload.update(
{
'Token': self._user['token'],
'UserId': self._user['user_id'],
}
)

full_url = self._full_url(endpoint.value, Server.API)
resp = requests.post(
Expand Down Expand Up @@ -120,7 +124,7 @@ def get_category_files(
page: int = 1,
per_page: int = 20,
) -> list:
"""Get a list of galleries by category"""
"""Get a list of galleries by Category"""
if not self.is_logged_in():
raise Exception('Not logged in!')

Expand Down Expand Up @@ -167,6 +171,28 @@ def get_album_list(self) -> list:
except Exception:
return None

def get_album_files(self, album_id: int, page: int = 1, per_page: int = 20):
"""Get a list of galleries by Album"""
start_num = ((page - 1) * per_page) + 1
end_num = start_num + per_page - 1

payload = {
'AlbumId': album_id,
'StartNum': start_num,
'EndNum': end_num,
}

try:
resp_json = self._send_request(ApiEndpoint.GET_ALBUM_FILES, payload)

lst = []
for item in resp_json['FileList']:
lst.append(GalleryInfo(item))

return lst
except Exception:
return None

def download(self, gallery_info: GalleryInfo) -> PixelBean:
"""Download and decode animation"""
url = self._full_url(gallery_info.file_id, server=Server.FILE)
Expand Down
1 change: 1 addition & 0 deletions apixoo/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Server(str, Enum):

class ApiEndpoint(str, Enum):
GET_ALBUM_LIST = '/Discover/GetAlbumList'
GET_ALBUM_FILES = '/Discover/GetAlbumImageList'
GET_CATEGORY_FILES = '/GetCategoryFileListV2'
GET_GALLERY_INFO = '/Cloud/GalleryInfo'
USER_LOGIN = '/UserLogin'
Expand Down

0 comments on commit 3d8b08a

Please sign in to comment.