|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +import json |
| 3 | +import os |
| 4 | +import re |
| 5 | + |
| 6 | +import requests |
| 7 | +import urllib3 |
| 8 | + |
| 9 | +from dailycheckin import CheckIn |
| 10 | + |
| 11 | +urllib3.disable_warnings() |
| 12 | + |
| 13 | + |
| 14 | +class AcFun(CheckIn): |
| 15 | + name = "AcFun" |
| 16 | + |
| 17 | + def __init__(self, check_item: dict): |
| 18 | + self.check_item = check_item |
| 19 | + self.contentid = "27259341" |
| 20 | + self.st = None |
| 21 | + |
| 22 | + @staticmethod |
| 23 | + def login(phone, password, session): |
| 24 | + url = "https://id.app.acfun.cn/rest/web/login/signin" |
| 25 | + body = f"username={phone}&password={password}&key=&captcha=" |
| 26 | + res = session.post(url=url, data=body).json() |
| 27 | + return (True, res) if res.get("result") == 0 else (False, res.get("err_msg")) |
| 28 | + |
| 29 | + @staticmethod |
| 30 | + def get_cookies(session, phone, password): |
| 31 | + url = "https://id.app.acfun.cn/rest/app/login/signin" |
| 32 | + headers = { |
| 33 | + "Host": "id.app.acfun.cn", |
| 34 | + "user-agent": "AcFun/6.39.0 (iPhone; iOS 14.3; Scale/2.00)", |
| 35 | + "devicetype": "0", |
| 36 | + "accept-language": "zh-Hans-CN;q=1, en-CN;q=0.9, ja-CN;q=0.8, zh-Hant-HK;q=0.7, io-Latn-CN;q=0.6", |
| 37 | + "accept": "application/json", |
| 38 | + "content-type": "application/x-www-form-urlencoded", |
| 39 | + } |
| 40 | + data = f"password={password}&username={phone}" |
| 41 | + response = session.post(url=url, data=data, headers=headers, verify=False) |
| 42 | + acpasstoken = response.json().get("acPassToken") |
| 43 | + auth_key = str(response.json().get("auth_key")) |
| 44 | + if acpasstoken and auth_key: |
| 45 | + cookies = {"acPasstoken": acpasstoken, "auth_key": auth_key} |
| 46 | + return cookies |
| 47 | + else: |
| 48 | + return False |
| 49 | + |
| 50 | + def get_token(self, session): |
| 51 | + url = "https://id.app.acfun.cn/rest/web/token/get?sid=acfun.midground.api" |
| 52 | + res = session.post(url=url).json() |
| 53 | + self.st = res.get("acfun.midground.api_st") if res.get("result") == 0 else "" |
| 54 | + return self.st |
| 55 | + |
| 56 | + def get_video(self, session): |
| 57 | + url = "https://www.acfun.cn/rest/pc-direct/rank/channel" |
| 58 | + res = session.get(url=url).json() |
| 59 | + self.contentid = res.get("rankList")[0].get("contentId") |
| 60 | + return self.contentid |
| 61 | + |
| 62 | + @staticmethod |
| 63 | + def sign(session): |
| 64 | + url = "https://www.acfun.cn/rest/pc-direct/user/signIn" |
| 65 | + response = session.post(url=url) |
| 66 | + return {"name": "签到信息", "value": response.json().get("msg")} |
| 67 | + |
| 68 | + def danmu(self, session): |
| 69 | + url = "https://www.acfun.cn/rest/pc-direct/new-danmaku/add" |
| 70 | + data = { |
| 71 | + "mode": "1", |
| 72 | + "color": "16777215", |
| 73 | + "size": "25", |
| 74 | + "body": "123321", |
| 75 | + "videoId": "26113662", |
| 76 | + "position": "2719", |
| 77 | + "type": "douga", |
| 78 | + "id": "31224739", |
| 79 | + "subChannelId": "1", |
| 80 | + "subChannelName": "动画", |
| 81 | + } |
| 82 | + response = session.get(url=f"https://www.acfun.cn/v/ac{self.contentid}") |
| 83 | + videoId = re.findall(r'"currentVideoId":(\d+),', response.text) |
| 84 | + subChannel = re.findall( |
| 85 | + r'{subChannelId:(\d+),subChannelName:"([\u4e00-\u9fa5]+)"}', response.text |
| 86 | + ) |
| 87 | + if videoId: |
| 88 | + data["videoId"] = videoId[0] |
| 89 | + data["subChannelId"] = subChannel[0][0] |
| 90 | + data["subChannelName"] = subChannel[0][1] |
| 91 | + res = session.post(url=url, data=data).json() |
| 92 | + msg = "弹幕成功" if res.get("result") == 0 else "弹幕失败" |
| 93 | + return {"name": "弹幕任务", "value": msg} |
| 94 | + |
| 95 | + def throwbanana(self, session): |
| 96 | + url = "https://www.acfun.cn/rest/pc-direct/banana/throwBanana" |
| 97 | + data = {"resourceId": self.contentid, "count": "1", "resourceType": "2"} |
| 98 | + res = session.post(url=url, data=data).json() |
| 99 | + msg = "投🍌成功" if res.get("result") == 0 else "投🍌失败" |
| 100 | + return {"name": "香蕉任务", "value": msg} |
| 101 | + |
| 102 | + def like(self, session): |
| 103 | + like_url = "https://kuaishouzt.com/rest/zt/interact/add" |
| 104 | + unlike_url = "https://kuaishouzt.com/rest/zt/interact/delete" |
| 105 | + body = ( |
| 106 | + f"kpn=ACFUN_APP&kpf=PC_WEB&subBiz=mainApp&interactType=1&" |
| 107 | + f"objectType=2&objectId={self.contentid}&acfun.midground.api_st={self.st}&" |
| 108 | + f"extParams%5BisPlaying%5D=false&extParams%5BshowCount%5D=1&extParams%5B" |
| 109 | + f"otherBtnClickedCount%5D=10&extParams%5BplayBtnClickedCount%5D=0" |
| 110 | + ) |
| 111 | + res = session.post(url=like_url, data=body).json() |
| 112 | + session.post(url=unlike_url, data=body) |
| 113 | + msg = "点赞成功" if res.get("result") == 1 else "点赞失败" |
| 114 | + return {"name": "点赞任务", "value": msg} |
| 115 | + |
| 116 | + def share(self, session, cookies): |
| 117 | + url = "https://api-ipv6.acfunchina.com/rest/app/task/reportTaskAction?taskType=1&market=tencent&product=ACFUN_APP&appMode=0" |
| 118 | + headers = { |
| 119 | + "Content-Type": "application/x-www-form-urlencoded", |
| 120 | + } |
| 121 | + response = session.get(url=url, headers=headers, cookies=cookies, verify=False) |
| 122 | + if response.json().get("result") == 0: |
| 123 | + msg = "分享成功" |
| 124 | + else: |
| 125 | + msg = "分享失败" |
| 126 | + return {"name": "分享任务", "value": msg} |
| 127 | + |
| 128 | + @staticmethod |
| 129 | + def get_info(session): |
| 130 | + url = "https://www.acfun.cn/rest/pc-direct/user/personalInfo" |
| 131 | + res = session.get(url=url).json() |
| 132 | + if res.get("result") != 0: |
| 133 | + return [{"name": "当前等级", "value": "查询失败"}] |
| 134 | + info = res.get("info") |
| 135 | + return [ |
| 136 | + {"name": "当前等级", "value": info.get("level")}, |
| 137 | + {"name": "持有香蕉", "value": info.get("banana")}, |
| 138 | + ] |
| 139 | + |
| 140 | + def main(self): |
| 141 | + phone = self.check_item.get("phone") |
| 142 | + password = self.check_item.get("password") |
| 143 | + session = requests.session() |
| 144 | + session.headers.update( |
| 145 | + { |
| 146 | + "accept": "*/*", |
| 147 | + "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", |
| 148 | + "content-type": "application/x-www-form-urlencoded; charset=UTF-8", |
| 149 | + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " |
| 150 | + "AppleWebKit/537.36 (KHTML, like Gecko) " |
| 151 | + "Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70", |
| 152 | + "Referer": "https://www.acfun.cn/", |
| 153 | + } |
| 154 | + ) |
| 155 | + flag, res = self.login(phone, password, session) |
| 156 | + if flag is True: |
| 157 | + self.get_video(session=session) |
| 158 | + self.get_token(session=session) |
| 159 | + sign_msg = self.sign(session=session) |
| 160 | + like_msg = self.like(session=session) |
| 161 | + danmu_msg = self.danmu(session=session) |
| 162 | + throwbanana_msg = self.throwbanana(session=session) |
| 163 | + info_msg = self.get_info(session=session) |
| 164 | + msg = [ |
| 165 | + {"name": "帐号信息", "value": phone}, |
| 166 | + sign_msg, |
| 167 | + like_msg, |
| 168 | + danmu_msg, |
| 169 | + throwbanana_msg, |
| 170 | + ] + info_msg |
| 171 | + else: |
| 172 | + msg = [{"name": "帐号信息", "value": phone}, {"name": "错误信息", "value": res}] |
| 173 | + msg = "\n".join([f"{one.get('name')}: {one.get('value')}" for one in msg]) |
| 174 | + return msg |
| 175 | + |
| 176 | + |
| 177 | +if __name__ == "__main__": |
| 178 | + with open( |
| 179 | + os.path.join(os.path.dirname(os.path.dirname(__file__)), "config.json"), |
| 180 | + "r", |
| 181 | + encoding="utf-8", |
| 182 | + ) as f: |
| 183 | + datas = json.loads(f.read()) |
| 184 | + _check_item = datas.get("ACFUN", [])[0] |
| 185 | + print(AcFun(check_item=_check_item).main()) |
0 commit comments