Skip to content

Commit

Permalink
feat: Add captcha support to PikPak login #44
Browse files Browse the repository at this point in the history
  • Loading branch information
Quan666 committed Aug 15, 2024
1 parent b786f9a commit 649ed09
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
28 changes: 24 additions & 4 deletions pikpakapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import logging
import asyncio
from base64 import b64decode, b64encode
import sys
import re
from typing import Any, Dict, List, Optional
from .utils import (
CLIENT_ID,
Expand Down Expand Up @@ -75,9 +77,11 @@ def __init__(
)
self.captcha_token = None

self.httpx_client = httpx.AsyncClient(**httpx_client_args)
self.httpx_client = httpx.AsyncClient(
**httpx_client_args if httpx_client_args else {}
)

self._path_id_cache = {}
self._path_id_cache: Dict[str, Any] = {}

self.user_agent: Optional[str] = None

Expand Down Expand Up @@ -246,13 +250,29 @@ async def login(self) -> None:
"""
Login to PikPak
"""
login_url = f"https://{PikPakApi.PIKPAK_USER_HOST}/v1/auth/token"
login_url = f"https://{PikPakApi.PIKPAK_USER_HOST}/v1/auth/signin"
metas = {}
if not self.username or not self.password:
raise PikpakException("username and password are required")
if re.match(r"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", self.username):
metas["email"] = self.username
elif re.match(r"\d{11,18}", self.username):
metas["phone_number"] = self.username
else:
metas["username"] = self.username
result = await self.captcha_init(
action=f"POST:{login_url}",
meta=metas,
)
captcha_token = result.get("captcha_token", "")
if not captcha_token:
raise PikpakException("captcha_token get failed")
login_data = {
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"password": self.password,
"username": self.username,
"grant_type": "password",
"captcha_token": captcha_token,
}
user_info = await self._request_post(
login_url,
Expand Down
26 changes: 16 additions & 10 deletions pikpakapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

CLIENT_ID = "YNxT9w7GMdWvEOKa"
CLIENT_SECRET = "dbw2OtmVEeuUvIptb1Coyg"
CLIENT_VERSION = "1.46.2"
CLIENT_VERSION = "1.47.1"
PACKAG_ENAME = "com.pikcloud.pikpak"
SDK_VERSION = "2.0.4.204000 "
APP_NAME = PACKAG_ENAME
Expand All @@ -25,15 +25,21 @@ def device_id_generator() -> str:


SALTS = [
"PAe56I7WZ6FCSkFy77A96jHWcQA27ui80Qy4",
"SUbmk67TfdToBAEe2cZyP8vYVeN",
"1y3yFSZVWiGN95fw/2FQlRuH/Oy6WnO",
"8amLtHJpGzHPz4m9hGz7r+i+8dqQiAk",
"tmIEq5yl2g/XWwM3sKZkY4SbL8YUezrvxPksNabUJ",
"4QvudeJwgJuSf/qb9/wjC21L5aib",
"D1RJd+FZ+LBbt+dAmaIyYrT9gxJm0BB",
"1If",
"iGZr/SJPUFRkwvC174eelKy",
"Gez0T9ijiI9WCeTsKSg3SMlx",
"zQdbalsolyb1R/",
"ftOjr52zt51JD68C3s",
"yeOBMH0JkbQdEFNNwQ0RI9T3wU/v",
"BRJrQZiTQ65WtMvwO",
"je8fqxKPdQVJiy1DM6Bc9Nb1",
"niV",
"9hFCW2R1",
"sHKHpe2i96",
"p7c5E6AcXQ/IJUuAEC9W6",
"",
"aRv9hjc9P+Pbn+u3krN6",
"BzStcgE8qVdqjEH16l4",
"SqgeZvL5j9zoHP95xWHt",
"zVof5yaJkPe3VFpadPof",
]


Expand Down

0 comments on commit 649ed09

Please sign in to comment.