├── delete_hbili.py └── hbilibili_scan.py /delete_hbili.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # @Time : 2018/9/8 17:33 4 | # @Author : Dawn 5 | # @Contact : 1050596704@qq.com 6 | import requests 7 | import time 8 | import traceback 9 | import datetime 10 | import hashlib 11 | 12 | ####################### 13 | # 账户设置 # 14 | ####################### 15 | cookie = "" 16 | uid = 0 17 | access_key = "" 18 | csrf = "" 19 | 20 | 21 | # 格式化打印模块 22 | def printer(info, *args): 23 | at_now = int(time.time()) 24 | time_arr = time.localtime(at_now) 25 | format_time = time.strftime("%Y-%m-%d %H:%M:%S", time_arr) 26 | # flag = "," if len(args) else " " 27 | content = f'[{format_time}] {info} {" ".join(f"{str(arg)}" for arg in args)}' 28 | print(content) 29 | 30 | 31 | # 计算sign 32 | def calc_sign(str): 33 | str = str + "560c52ccd288fed045859ed18bffd973" 34 | hash = hashlib.md5() 35 | hash.update(str.encode('utf-8')) 36 | sign = hash.hexdigest() 37 | return sign 38 | 39 | 40 | # 获取当前时间戳 41 | def CurrentTime(): 42 | currenttime = int(time.mktime(datetime.datetime.now().timetuple())) 43 | return str(currenttime) 44 | 45 | 46 | # 删除动态 47 | def del_dynamic_id(dy_id): 48 | printer(f'删除{dy_id}动态!') 49 | headers = { 50 | "User-Agent": "Mozilla/5.0 BiliDroid/5.31.3 (bbcallen@gmail.com)", 51 | "Cookie": "l=v; sid=6gpbr48u", 52 | "Device-ID": "SX1NL0wuHCsaKRt4BHhIfRguTXxOfj5WN1BkBTdLfhstTn9NfUouFiUV", 53 | "Buvid": "32E49244-E168-4A0F-8361-EC61D73973DC20798infoc", 54 | "Content-Type": "application/x-www-form-urlencoded; charset=utf-8", 55 | "Display-ID": "48766812-1536402060" 56 | } 57 | temp_data = f"_device=android&_hwid=SX1NL0wuHCsaKRt4BHhIfRguTXxOfj5WN1BkBTdLfhstTn9NfUouFiUV&access_key={access_key}&appkey=1d8b6e7d45233436&build=5310300&dynamic_id={dy_id}&mobi_app=android&platform=android&src=meizu&trace_id=20180909020900047&ts={CurrentTime()*1000}&uid={uid}&version=5.31.3.5310300" 58 | data = f"{temp_data}&sign={calc_sign(temp_data)}" 59 | url = 'https://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/rm_rp_dyn' 60 | response = requests.post(url, data=data, headers=headers) 61 | printer(response.json()) 62 | 63 | 64 | # 获取所有动态id 65 | def get_dynamic_list(): 66 | dy_id = 0 67 | dy_uid_list = [] 68 | start = 1 69 | while 1: 70 | printer(f"当前进行到第{start}页") 71 | temp_params = f"_device=android&_hwid=SX1NL0wuHCsaKRt4BHhIfRguTXxOfj5WN1BkBTdLfhstTn9NfUouFiUV&access_key={access_key}&appkey=1d8b6e7d45233436&build=5310300&host_uid={uid}&mobi_app=android&offset_dynamic_id={dy_id}&page={start}&platform=android&qn=32&src=meizu&trace_id=20180908182200005&ts={CurrentTime()}&version=5.31.3.5310300&visitor_uid={uid}" 72 | url = f"https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?{temp_params}&sign={calc_sign(temp_params)}" 73 | headers = { 74 | "User-Agent": "Mozilla/5.0 BiliDroid/5.31.3 (bbcallen@gmail.com)", 75 | "Device-ID": "SX1NL0wuHCsaKRt4BHhIfRguTXxOfj5WN1BkBTdLfhstTn9NfUouFiUV", 76 | "Buvid": "32E49244-E168-4A0F-8361-EC61D73973DC20798infoc" 77 | } 78 | 79 | response = requests.get(url, headers=headers) 80 | exist = (response.json()['data']['has_more']) 81 | if exist == 0: 82 | break 83 | _len = len(response.json()['data']['cards']) 84 | for i in range(0, _len): 85 | dyid = response.json()['data']['cards'][i]['desc']['dynamic_id'] 86 | tmp = (response.json()['data']['cards'][i]['card']).replace("true", "True").replace("false", "False") 87 | tmp = eval(tmp) 88 | if 'origin' in tmp.keys(): 89 | tmp = eval(tmp['origin']) 90 | if 'id' in tmp['item'].keys(): 91 | printer(f"该条动态id:{dyid},对应的up主uid为{tmp['user']['uid']},对应的原始动态id为{tmp['item']['id']}") 92 | dy_uid_list.append([dyid, tmp['user']['uid'], tmp['item']['id']]) 93 | else: 94 | printer(f"出现了一个旧版动态{response.json()}") 95 | else: 96 | printer(f"该条动态id:{dyid}已被原up主删除或者不是抽奖动态,将尝试删除") 97 | del_dynamic_id(dyid) 98 | dy_id = response.json()['data']['cards'][_len - 1]['desc']['dynamic_id'] 99 | start = start + 1 100 | 101 | continue 102 | return dy_uid_list 103 | 104 | 105 | # 取消关注 106 | def unfollow(uid): 107 | printer(f'取消{uid}关注状态!') 108 | url = "https://api.live.bilibili.com/liveact/attention" 109 | headers = { 110 | "Referer": "https://link.bilibili.com/p/center/index", 111 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36", 112 | "Origin": "https://link.bilibili.com", 113 | "Cookie": cookie, 114 | } 115 | data = { 116 | "type": 0, 117 | "uid": uid, 118 | "token": "", 119 | "csrf_token": csrf 120 | } 121 | response = requests.post(url, data=data, headers=headers) 122 | printer(response.json()) 123 | 124 | 125 | # 检查抽奖是否过期 126 | def check_lottery_time(dy_id): 127 | url = f"https://api.vc.bilibili.com/lottery_svr/v1/lottery_svr/lottery_notice?business_type=2&business_id={dy_id}" 128 | headers = { 129 | "Referer": "https://t.bilibili.com/lottery/h5/index/", 130 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36", 131 | "Cookie": cookie, 132 | "Host": "api.vc.bilibili.com" 133 | } 134 | response = requests.get(url, headers=headers) 135 | if 'lottery_time' in (response.json()['data']).keys(): 136 | unix_time = response.json()['data']['lottery_time'] 137 | printer(unix_time) 138 | printer(time.time()) 139 | if unix_time < time.time(): 140 | return True 141 | else: 142 | return False 143 | else: 144 | return True 145 | 146 | 147 | if __name__ == "__main__": 148 | all_list = get_dynamic_list() 149 | for i in range(0, len(all_list)): 150 | try: 151 | printer(all_list[i]) 152 | statu = check_lottery_time(all_list[i][2]) 153 | if statu: 154 | unfollow(all_list[i][1]) 155 | del_dynamic_id(all_list[i][0]) 156 | except: 157 | traceback.print_exc() 158 | -------------------------------------------------------------------------------- /hbilibili_scan.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import hashlib 3 | import time 4 | import datetime 5 | # keywords = ['抽奖','盖楼','抢楼','转发并评论','参与抽奖','参与活动','就有机会','本动态','此动态',"这条动态","开奖","'评论并转发'"] 6 | # keywords = ['​动态互动抽奖','互动抽奖'] 7 | cookie = "" 8 | access_key = "" 9 | csrf = "" 10 | headers = { 11 | "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36", 12 | "Cookie": cookie 13 | } 14 | # def check(des): 15 | # for i in keywords: 16 | # if des.find(i) != -1: 17 | # return True 18 | 19 | 20 | def modify(uid): 21 | url = "https://api.bilibili.com/x/relation/modify" 22 | data = { 23 | "fid":uid, 24 | "act":"1", 25 | "re_src":"11", 26 | "jsonp":"jsonp", 27 | "csrf":csrf 28 | } 29 | response = requests.post(url,data=data,headers=headers) 30 | print("关注状态:",response.json()) 31 | 32 | def repost(dynamic_id): 33 | temp_params = "access_key="+access_key+"&appkey=1d8b6e7d45233436&build=5260003&mobi_app=android&platform=android&src=meizu&trace_id=20180531235400023&ts=1527782063000&version=5.26.3.5260003" 34 | 35 | url = "https://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/repost?access_key="+access_key+"&appkey=1d8b6e7d45233436&build=5260003&mobi_app=android&platform=android&src=meizu&trace_id=20180531235400023&ts=1527782063000&version=5.26.3.5260003&sign="+calc_sign(temp_params) 36 | headers={ 37 | "User-Agent":"Mozilla/5.0 BiliDroid/5.26.3 (bbcallen@gmail.com)", 38 | "Host":"api.vc.bilibili.com" 39 | } 40 | data = { 41 | "uid":"1", 42 | "dynamic_id":"0", 43 | "type":"2", 44 | "rid":dynamic_id, 45 | "content":"@大姬八云紫@゚大鹏不想飞", 46 | "ctrl":'[{"data":"3453410","length":7,"location":0,"type":1},{"data":"240834777","length":6,"location":8,"type":1}]', 47 | "at_uids":"3453410,2408347,28272030", 48 | "spec_type":"0", 49 | "repost_code":"10000", 50 | "extension":"{}" 51 | } 52 | response = requests.post(url,headers=headers,data=data) 53 | print("转发状态:",response.json()) 54 | 55 | def calc_sign(str): 56 | str = str + "560c52ccd288fed045859ed18bffd973" 57 | hash = hashlib.md5() 58 | hash.update(str.encode('utf-8')) 59 | sign = hash.hexdigest() 60 | return sign 61 | 62 | # //暂时废弃 63 | # def doc2id(id): 64 | # temp_params = "_device=android&_hwid=SX1NL0wuHCsaKRt4BHhIfRguTXxOfj5WN1BkBTdLfhstTn9NfUouFiUV&access_key="+access_key+"&appkey=1d8b6e7d45233436&build=5260003&doc_id="+str(id)+"&mobi_app=android&platform=android&src=meizu&trace_id=20180531234300045&ts=1527781425&version=5.26.3.5260003" 65 | # url = "http://api.vc.bilibili.com/link_draw/v2/doc/dynamic_id?_device=android&_hwid=SX1NL0wuHCsaKRt4BHhIfRguTXxOfj5WN1BkBTdLfhstTn9NfUouFiUV&access_key="+access_key+"&appkey=1d8b6e7d45233436&build=5260003&doc_id="+str(id)+"&mobi_app=android&platform=android&src=meizu&trace_id=20180531234300045&ts=1527781425&version=5.26.3.5260003&sign="+calc_sign(temp_params) 66 | # headers={ 67 | # "User-Agent":"Mozilla/5.0 BiliDroid/5.26.3 (bbcallen@gmail.com)", 68 | # "Host":"api.vc.bilibili.com" 69 | # } 70 | # response = requests.get(url,headers=headers) 71 | # dynamic_id = response.json()['data']['dynamic_id'] 72 | # print(dynamic_id) 73 | # return dynamic_id 74 | 75 | def helper(i): 76 | url = "https://api.vc.bilibili.com/link_draw/v1/doc/detail?doc_id=" + str(i) 77 | response = requests.get(url) 78 | if response.json()['code'] == 0: 79 | lottery = (response.json()['data']['item']['extension']) 80 | des = (response.json()['data']['item']['description']) 81 | format_lottery = eval(lottery) 82 | if len(format_lottery) >= 1: 83 | tmp = eval(format_lottery['lott_cfg']) 84 | title = tmp['title'] 85 | uid = response.json()['data']['user']['uid'] 86 | return title, des, uid 87 | else: 88 | title = "不符合规则的动态" 89 | des = "不符合规则的动态" 90 | uid = "不符合规则的动态" 91 | return title, des, uid 92 | elif response.json()['msg'] == "doc not found": 93 | title = "未找到id" 94 | des = "未找到id" 95 | uid = "未找到id" 96 | return title, des, uid 97 | else: 98 | title = "error" 99 | des = "error" 100 | uid = "error" 101 | return title,des,uid 102 | 103 | def monitor(): 104 | for i in range(8771704, 10000000): 105 | print(i) 106 | try: 107 | # url = "https://api.vc.bilibili.com/link_draw/v1/doc/detail?doc_id="+str(i) 108 | # # response = requests.get(url) 109 | # # lottery = (response.json()['data']['item']['extension']) 110 | # # des = (response.json()['data']['item']['description']) 111 | # # format_lottery = eval(lottery) 112 | # # if len(format_lottery) >= 1: 113 | # # tmp = eval(format_lottery['lott_cfg']) 114 | # # title = tmp['title'] 115 | data = helper(i) 116 | flag = 5 117 | while data[0] == "未找到id": 118 | if flag < 10: 119 | print("休眠一下") 120 | time.sleep(5) 121 | print("休眠完成") 122 | data = helper(i) 123 | flag = flag + 1 124 | print(flag) 125 | else: 126 | i = i + 1 127 | data = helper(i) 128 | if data[0] == "不符合规则的动态": 129 | print("不符合规则的动态") 130 | if data[0] == "error": 131 | print("出现了异常情况") 132 | if data[0] == "互动抽奖": 133 | # print(url) 134 | print(data[1]) 135 | print("https://h.bilibili.com/"+str(i)) 136 | modify(data[2]) 137 | # tmp = doc2id(i) 138 | # print(tmp) 139 | repost(i) 140 | 141 | except: 142 | pass 143 | 144 | monitor() 145 | --------------------------------------------------------------------------------