1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
| from email import message from nonebot import require, get_bot import requests import json from bs4 import BeautifulSoup import sqlite3 scheduler = require('nonebot_plugin_apscheduler').scheduler @scheduler.scheduled_job('interval', minutes=4, id='ytb404') async def azuma_ytb_live_pusher(): h = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0', 'Origin': 'https://www.youtube.com', 'Content-Type': 'application/json', 'host': 'www.youtube.com', } bot = get_bot() url = 'https://www.youtube.com/channel/UCEuqN76-F2rl1-08aGt8siA' con = sqlite3.connect(r"/root/nonebot/Seren/seren/plugins/times.db") cur = con.cursor() cur.execute('SELECT * FROM times') data = cur.fetchone() push_time = data[0] r = requests.get(url + '/live') html = r.content.decode("utf-8") soup = BeautifulSoup(html, "lxml") links = soup.find_all('link', rel="canonical") url0 = links[0]['href'] if url == url0: cur.execute("UPDATE times SET id=0 WHERE name='times'") con.commit() else: if push_time == 1: cur.close() con.close() else: cur.execute("UPDATE times SET id=1 WHERE name='times'") con.commit() vid = format(url0.replace('https://www.youtube.com/watch?v=', '')) data = { "context": { "client": { "hl": "zh-CN", "gl": "US", "remoteHost": "104.238.183.19", "deviceMake": "", "deviceModel": "", "visitorData": "CgtvMXpSUVRfTllXVSje7L6PBg%3D%3D", "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0,gzip(gfe)", "clientName": "WEB", "clientVersion": "2.20220124.01.00", "osName": "Windows", "osVersion": "10.0", "originalUrl": "https://www.youtube.com/watch?v=PVCEhD6zyXs", "screenPixelDensity": 1, "platform": "DESKTOP", "clientFormFactor": "UNKNOWN_FORM_FACTOR", "configInfo": { "appInstallData": "CN7svo8GELvH_RIQt8utBRCA6q0FEJjqrQUQveutBRDYvq0FEJH4_BI%3D" }, "screenDensityFloat": 1.25, "userInterfaceTheme": "USER_INTERFACE_THEME_DARK", "timeZone": "Asia/Shanghai", "browserName": "Firefox", "browserVersion": "96.0", "screenWidthPoints": 1536, "screenHeightPoints": 26, "utcOffsetMinutes": 480, "mainAppWebInfo": { "graftUrl": "https://www.youtube.com/watch?v=PVCEhD6zyXs", "webDisplayMode": "WEB_DISPLAY_MODE_BROWSER", "isWebNativeShareAvailable": False } }, "user": { "lockedSafetyMode": False }, "request": { "useSsl": True, "consistencyTokenJars": [{ "encryptedTokenJarContents": "AGDxDePLfe_Lq5NyjA1C5nhEksdINB4VL5EcmFaVNVkqUw-0KdV0PXj-PJef54WriipjpEy-gey1ewetVkOf35qV8ET_YapXqWrpXpvD0Trxq9f4Mg35UouxGk92w1gNkDmmgIbgmaUQRlaGW1uEj384" }], "internalExperimentFlags": [] }, "clickTracking": { "clickTrackingParams": "CLkCEMyrARgAIhMI_NrTw7_M9QIVVEhMCB2ACgrN" }, "adSignalsInfo": { "params": [{ "key": "dt", "value": "1643099758577" }, { "key": "flash", "value": "0" }, { "key": "frm", "value": "0" }, { "key": "u_tz", "value": "480" }, { "key": "u_his", "value": "2" }, { "key": "u_h", "value": "864" }, { "key": "u_w", "value": "1536" }, { "key": "u_ah", "value": "864" }, { "key": "u_aw", "value": "1536" }, { "key": "u_cd", "value": "24" }, { "key": "bc", "value": "31" }, { "key": "bih", "value": "26" }, { "key": "biw", "value": "1519" }, { "key": "brdim", "value": "-7,-7,-7,-7,1536,0,1550,878,1536,26" }, { "key": "vis", "value": "2" }, { "key": "wgl", "value": "true" }, { "key": "ca_type", "value": "image" }] } }, "videoId": vid } apiurl = 'https://www.youtube.com/youtubei/v1/updated_metadata?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8' r = requests.post(apiurl, headers=h, data=json.dumps(data)) r_json = json.loads(r.text) title = r_json["actions"][3]['updateTitleAction']['title']['runs'][0]['text'] last_live = r_json['actions'][2]['updateDateTextAction']['dateText']['simpleText'] img_url = str('https://i.ytimg.com/vi/'+vid+'/hqdefault_live.jpg') cq = "[CQ:image,file="+ img_url + ",id=40000]" userid = *********** try: person = r_json['actions'][0]['updateViewershipAction']['viewCount']['videoViewCountRenderer']['viewCount']['simpleText'] if '预定发布' in last_live: cur.close() con.close() else: cur.execute("UPDATE times SET id=1 WHERE name='times'") con.commit() cur.execute("SELECT * FROM users") objj = cur.fetchall() u_num = len(objj) for i in range(0,u_num): userid = objj[i][1] await bot.send_private_msg(user_id=userid,message=cq) await bot.send_private_msg(user_id=userid, message=f"莲宝在404开播啦!有兴趣可以去看哦\n直播标题:{title}\n直播链接:{url}\n{last_live}\n当前同接:{person}") except: if '预定发布' in last_live: cur.close() con.close() else: cur.execute("UPDATE times SET id=1 WHERE name='times'") con.commit() cur.execute("SELECT * FROM users") objj = cur.fetchall() u_num = len(objj) for i in range(0,u_num): userid = objj[i][1] await bot.send_private_msg(user_id=userid,message=cq) await bot.send_private_msg(user_id=userid, message=f"莲宝在404开播啦!有兴趣可以去看哦\n直播标题:{title}\n直播链接:{url}\n{last_live}")
|