Пример #1
0
    def download_link(self, remotepath: str):
        # if not self._user_id:
        #     return None
        #     path = urllib.parse.quote(remotepath)
        #     return (
        #         'http://c.pcs.baidu.com/rest/2.0/pcs/file'
        #         f'?method=download&app_id={PCS_APP_ID}&path={path}&ver=2.0&clienttype=1'
        #     )

        bduss = self._bduss
        uid = str(self._user_id) or ""

        timestamp = str(int(time.time() * 1000))
        devuid = "0|" + calu_md5(bduss).upper()

        enc = calu_sha1(bduss)
        rand = calu_sha1(enc + uid + "ebrcUYiuxaZv2XGu7KIYKxUrqfnOfpDF" +
                         timestamp + devuid)

        url = self._form_url(PcsNode.File, domain=PCS_BAIDU_COM)
        params = {
            "method": "locatedownload",
            "ver": "2",
            "path": remotepath,
            "time": timestamp,
            "rand": rand,
            "devuid": devuid,
        }

        resp = self._request(Method.Get, url, params=params)
        return resp.json()
Пример #2
0
    def rapid_upload_file(self,
                          localpath: str,
                          remotepath: str,
                          ondup="overwrite"):
        """size > 256KB"""

        localPath = Path(localpath)
        assert localPath.is_file(), f"`{localpath}` is not existed"

        assert remotepath.startswith(
            "/"), "`remotepath` must be an absolute path"

        # Calucate file features
        buf = localPath.open("rb").read(constant.OneM)
        slice_md5 = calu_md5(buf[:256 * constant.OneK])
        content_crc32, content_md5 = calu_crc32_and_md5(
            localPath.open("rb"), constant.OneM)

        url = self._form_url(PcsNode.File)
        params = {
            "method": "rapidupload",
            "BDUSS": self._bduss,
        }
        data = {
            "path": remotepath,
            "content-length": localPath.stat().st_size,
            "content-md5": content_md5,
            "slice-md5": slice_md5,
            "content-crc32": content_crc32,
            "ondup": ondup,
        }
        resp = self._request(Method.Post, url, params=params, data=data)
        return resp.json()
Пример #3
0
    def shared_password(self, share_id: int):
        """
        Only return password
        """

        url = self._form_url(PcsNode.SharedPassword, domain=PAN_BAIDU_COM)
        params = {
            "shareid": str(share_id),
            "sign": calu_md5(f"{share_id}_sharesurlinfo!@#"),
        }
        resp = self._request(Method.Get, url, params=params)
        return resp.json()
Пример #4
0
    def user_info(self):
        bduss = self._bduss
        timestamp = str(int(time.time()))
        model = get_phone_model(bduss)
        phoneIMEIStr = sum_IMEI(bduss)

        data = {
            "bdusstoken": bduss + "|null",
            "channel_id": "",
            "channel_uid": "",
            "stErrorNums": "0",
            "subapp_type": "mini",
            "timestamp": timestamp + "922",
        }
        data["_client_type"] = "2"
        data["_client_version"] = "7.0.0.0"
        data["_phone_imei"] = phoneIMEIStr
        data["from"] = "mini_ad_wandoujia"
        data["model"] = model
        data["cuid"] = (
            calu_md5(bduss + "_" + data["_client_version"] + "_" +
                     data["_phone_imei"] + "_" + data["from"]).upper() + "|" +
            phoneIMEIStr[::-1])
        data["sign"] = calu_md5(
            "".join([k + "=" + data[k] for k in sorted(data.keys())]) +
            "tiebaclient!!!").upper()

        headers = {
            "Content-Type": "application/x-www-form-urlencoded",
            "Cookie": "ka=open",
            "net": "1",
            "User-Agent": "bdtb for Android 6.9.2.1",
            "client_logid": timestamp + "416",
            "Connection": "Keep-Alive",
        }

        resp = requests.post("http://tieba.baidu.com/c/s/login",
                             headers=headers,
                             data=data)
        return resp.json()
Пример #5
0
 def tieba_user_info(self, user_id: int):
     params = f"has_plist=0&need_post_count=1&rn=1&uid={user_id}"
     params += "&sign=" + calu_md5(
         params.replace("&", "") + "tiebaclient!!!")
     url = "http://c.tieba.baidu.com/c/u/user/profile?" + params
     headers = {
         "Content-Type": "application/x-www-form-urlencoded",
         "Cookie": "ka=open",
         "net": "1",
         "User-Agent": "bdtb for Android 6.9.2.1",
         "client_logid": str(int(time.time() * 1000)),
         "Connection": "Keep-Alive",
     }
     resp = requests.get(url, headers=headers, params=None)
     return resp.json()