|
| 1 | +import requests |
| 2 | +import json |
| 3 | +import time |
| 4 | +import random |
| 5 | + |
| 6 | +cookies = "_uuid=033B11A7-07D4-2E24-3830-32A59DFACE2303106infoc; buvid3=675D7837-17AF-40C1-A04D-93ECD0C6B15813422infoc; rpdid=|(JYYk)|JJ|~0J'uYkllY~kmY; PVID=1; buvid_fp=675D7837-17AF-40C1-A04D-93ECD0C6B15813422infoc; buvid_fp_plain=675D7837-17AF-40C1-A04D-93ECD0C6B15813422infoc; CURRENT_QUALITY=0; SESSDATA=7df0deb3%2C1654955986%2C76995%2Ac1; bili_jct=074962e462340ac9cc2ae1673d906394; DedeUserID=10927197; DedeUserID__ckMd5=902c45cc54ce17cb; sid=agwcnv6j; i-wanna-go-back=1; b_ut=6; bp_t_offset_10927197=603736801110449695; CURRENT_FNVAL=2000; CURRENT_BLACKGAP=0; blackside_state=0; fingerprint=0dcd15d27d8afae5c38936e518ab5656; fingerprint3=aa0fd784f61f005b0c742ed5785e4b9b; fingerprint_s=29c59ad2325d7824a6f2c02bfbaf2838; innersign=0; b_lsid=F4E2AAC1_17DB8DCAF41; bsource=search_google" |
| 7 | + |
| 8 | + |
| 9 | +def convert_cookies_to_dict(cookies): |
| 10 | + cookies = dict([l.split("=", 1) for l in cookies.split("; ")]) |
| 11 | + return cookies |
| 12 | + |
| 13 | +def getInfo(cookie): |
| 14 | + url = "http://api.bilibili.com/x/space/myinfo" |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + resp = requests.get(url, cookies=cookie).text |
| 19 | + myinfo = json.loads(resp) |
| 20 | + |
| 21 | + data = myinfo['data'] |
| 22 | + name = data['name'] |
| 23 | + level_exp = data['level_exp'] |
| 24 | + current_level = level_exp['current_exp'] |
| 25 | + current_exp = level_exp['current_exp'] |
| 26 | + next_exp = level_exp['next_exp'] |
| 27 | + sub_exp = int(next_exp) - int(current_exp) |
| 28 | + days = int(sub_exp/70) |
| 29 | + coin = data['coins'] |
| 30 | + print(data) |
| 31 | + print("{},你的等级是{},当前经验是{},下一级经验是{},还需要{}天升级,有{}个硬币".format(name, current_level,current_exp,next_exp,days,coin)) |
| 32 | + |
| 33 | +def getVideo(cookie): |
| 34 | + url = "http://api.bilibili.cn/recommend" |
| 35 | + |
| 36 | + resp = requests.get(url, cookies=cookie).text |
| 37 | + data = json.loads(resp) |
| 38 | + |
| 39 | + list_length = len(data['list']) |
| 40 | + result = [] |
| 41 | + for i in range(list_length): |
| 42 | + data['list'][i] |
| 43 | + bvid = data['list'][i]['bvid'] |
| 44 | + aid = data['list'][i]['aid'] |
| 45 | + result.append({'bvid': bvid, 'aid': aid}) |
| 46 | + return result |
| 47 | + |
| 48 | +def view(bvid, aid, csrf): |
| 49 | + playedTime = random.randint(15, 100) |
| 50 | + url = "https://api.bilibili.com/x/click-interface/web/heartbeat" |
| 51 | + header = { |
| 52 | + "origin": "https://www.bilibili.com", |
| 53 | + "referer": "https://www.bilibili.com/video/"+bvid, |
| 54 | + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36", |
| 55 | + "cookie": cookies |
| 56 | + |
| 57 | + } |
| 58 | + data = { |
| 59 | + 'aid': aid, |
| 60 | + 'bvid': bvid, |
| 61 | + 'played_time': playedTime, |
| 62 | + 'csrf': csrf |
| 63 | + } |
| 64 | + resp = requests.post(url, data = data ,headers=header).text |
| 65 | + json_data = json.loads(resp) |
| 66 | + code = json_data['code'] |
| 67 | + if code == 0: |
| 68 | + print('视频观看成功,bvid 号为:' + bvid) |
| 69 | + else: |
| 70 | + print('视频观看失败,bvid 号为:' + bvid) |
| 71 | + |
| 72 | +def coin(bvid, aid, csrf): |
| 73 | + |
| 74 | + url = "https://api.bilibili.com/x/web-interface/coin/add" |
| 75 | + data = { |
| 76 | + 'aid': aid, |
| 77 | + 'multiply': 1, |
| 78 | + 'select_like': 1, |
| 79 | + 'cross_domain': 'true', |
| 80 | + 'csrf': csrf |
| 81 | + } |
| 82 | + header = { |
| 83 | + "origin": "https://www.bilibili.com", |
| 84 | + "referer": "https://www.bilibili.com/video/"+bvid, |
| 85 | + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36", |
| 86 | + "cookie": cookies |
| 87 | + |
| 88 | + } |
| 89 | + |
| 90 | + resp = requests.post(url, headers=header, data=data).text |
| 91 | + data = json.loads(resp) |
| 92 | + code = data['code'] |
| 93 | + if code == 0: |
| 94 | + print("投币成功") |
| 95 | + else: |
| 96 | + print('投币失败') |
| 97 | + |
| 98 | + |
| 99 | +def share( bvid, csrf): |
| 100 | + url = 'https://api.bilibili.com/x/web-interface/share/add' |
| 101 | + data = { |
| 102 | + 'csrf': csrf, |
| 103 | + 'bvid': bvid |
| 104 | + } |
| 105 | + header = { |
| 106 | + 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8', |
| 107 | + "Connection": "keep-alive", |
| 108 | + "origin": "https://t.bilibili.com", |
| 109 | + "referer": 'https://t.bilibili.com', |
| 110 | + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36", |
| 111 | + "cookie": cookies |
| 112 | + |
| 113 | + } |
| 114 | + resp = requests.post(url, data=data, headers=header).text |
| 115 | + json_data = json.loads(resp) |
| 116 | + code = json_data['code'] |
| 117 | + if code == 0: |
| 118 | + print('视频分享成功') |
| 119 | + else: |
| 120 | + print('视频分享失败') |
| 121 | + |
| 122 | +if __name__ == '__main__': |
| 123 | + |
| 124 | + cookie = convert_cookies_to_dict(cookies) |
| 125 | + csrf = cookie['bili_jct'] |
| 126 | + |
| 127 | + getInfo(cookie) |
| 128 | + |
| 129 | + data = getVideo(cookie) |
| 130 | + view(data[1]['bvid'], data[1]['aid'], csrf) |
| 131 | + |
| 132 | + for item in data: |
| 133 | + |
| 134 | + for i in range(6): |
| 135 | + coin(cookie,data[i]['bvid'], data[i]['aid'],csrf) |
| 136 | + time.sleep(5) |
| 137 | + |
| 138 | + share(data[1]['bvid'],data[1]['aid'], csrf) |
0 commit comments