From e3c5602731a1f040fbd7c979bf9dcf912f616c8e Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Sun, 4 Dec 2022 20:43:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86py=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/version.txt | 2 +- readme.md | 1 + txt/py/py_bilibili.py | 620 ++++++++++++++++++++++++++++++++---------- txt/py/py_bilimy.py | 304 ++++++++++++++++----- txt/py/py_biliys.py | 212 ++++----------- txt/py/py_bilizb.py | 94 ++++--- txt/py/py_czspp.py | 72 +++-- 7 files changed, 850 insertions(+), 455 deletions(-) diff --git a/js/version.txt b/js/version.txt index 0f5d7e5..45248f6 100644 --- a/js/version.txt +++ b/js/version.txt @@ -1 +1 @@ -3.9.29beta1 \ No newline at end of file +3.9.29beta2 \ No newline at end of file diff --git a/readme.md b/readme.md index 89a573e..d7ff4ee 100644 --- a/readme.md +++ b/readme.md @@ -54,6 +54,7 @@ - [X] alist.js更新,增加了首页推荐 - [X] 仙人模式逻辑优化,增加ver参数,0,1,2。其中默认0为仙人自动识别,1为强制drpy.min.js,2为强制drpy2.min.js - [X] 默哀模式优化 +- [X] 更新部分py源 ###### 2022/12/2 - [X] js0/js1 api更新,增加新特性:pagecount(单独指定某些分类的总页数) ```json diff --git a/txt/py/py_bilibili.py b/txt/py/py_bilibili.py index c645ae4..1b69f6a 100644 --- a/txt/py/py_bilibili.py +++ b/txt/py/py_bilibili.py @@ -6,10 +6,8 @@ sys.path.append('..') from base.spider import Spider import json import requests -from requests import session, utils +import threading import time -import base64 - class Spider(Spider): @@ -20,12 +18,15 @@ class Spider(Spider): def homeContent(self, filter): result = {} cateManual = { - "动态": "动态", - "热门": "热门", + #"动态": "动态", "推荐": "推荐", - "历史记录": "历史记录", + "热门": "热门", + "排行榜": "排行榜", + #"历史记录": "历史记录", # "稍后再看":"稍后再看", #意义不大,隐藏该项 - "收藏": "收藏", + #"收藏": "收藏", + "每周必看": "每周必看", + "频道": "频道", "动画": "1", "音乐": "3", "舞蹈": "129", @@ -41,9 +42,7 @@ class Spider(Spider): "时尚": "155", "娱乐": "5", "影视": "181", - "每周必看": "每周必看", "入站必刷": "入站必刷", - "频道": "频道", } classes = [] for k in cateManual: @@ -68,9 +67,10 @@ class Spider(Spider): simple_cookie = http.cookies.SimpleCookie(raw_cookie_line) cookie_jar = requests.cookies.RequestsCookieJar() cookie_jar.update(simple_cookie) - rsp = session() + rsp = requests.session() rsp.cookies = cookie_jar - content = self.fetch("http://api.bilibili.com/x/web-interface/nav", cookies=rsp.cookies) + url = 'http://api.bilibili.com/x/web-interface/nav' + content = self.fetch(url, headers=self.header, cookies=rsp.cookies) res = json.loads(content.text) if res["code"] == 0: self.cookies = rsp.cookies @@ -81,7 +81,7 @@ class Spider(Spider): def __init__(self): self.getCookie() url = 'https://api.bilibili.com/x/v3/fav/folder/created/list-all?up_mid=%s&jsonp=jsonp' % self.userid - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) fav_list = [] @@ -107,10 +107,6 @@ class Spider(Spider): def manualVideoCheck(self): pass - def post_history(self, aid, cid): - url = 'http://api.bilibili.com/x/v2/history/report?aid={0}&cid={1}&csrf={2}'.format(aid, cid, self.csrf) - requests.post(url=url, cookies=self.cookies) - # 将超过10000的数字换成成以万和亿为单位 def zh(self, num): if int(num) >= 100000000: @@ -156,41 +152,16 @@ class Spider(Spider): } time_diff = '0' - def homeVideoContent(self): - result = {} - url = 'https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all' - rsp = self.fetch(url, cookies=self.cookies) - content = rsp.text - jo = json.loads(content) - if jo['code'] == 0: - videos = [] - vodList = jo['data']['list'][0:50] - for vod in vodList: - aid = str(vod['aid']).strip() - title = vod['title'].strip().replace("", "").replace("", "") - img = vod['pic'].strip() - remark = "观看:" + self.zh(vod['stat']['view']) + "  " + str(self.second_to_time(vod['duration'])).strip() - videos.append({ - "vod_id": aid, - "vod_name": title, - "vod_pic": img, - "vod_remarks": remark - }) - result = { - 'list': videos - } - return result - dynamic_offset = '' def get_dynamic(self, pg): result = {} if str(pg) == '1': - url = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=all&page=%s' % pg + url = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=video&page=%s' % pg else: # print('偏移',self.dynamic_offset) - url = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=all&offset=%s&page=%s' % (self.dynamic_offset, pg) - rsp = self.fetch(url, cookies=self.cookies) + url = 'https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/all?timezone_offset=-480&type=video&offset=%s&page=%s' % (self.dynamic_offset, pg) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: @@ -198,52 +169,56 @@ class Spider(Spider): videos = [] vodList = jo['data']['items'] for vod in vodList: - if vod['type'] == 'DYNAMIC_TYPE_AV': - up = vod['modules']["module_author"]['name'] - ivod = vod['modules']['module_dynamic']['major']['archive'] - aid = str(ivod['aid']).strip() - title = ivod['title'].strip().replace("", "").replace("", "") - img = ivod['cover'].strip() - # remark = str(ivod['duration_text']).strip() - remark = str(self.second_to_time(self.str2sec(ivod['duration_text']))).strip() + ' ' + str( - up).strip() # 显示分钟数+up主名字 - videos.append({ - "vod_id": aid, - "vod_name": title, - "vod_pic": img, - "vod_remarks": remark - }) + up = vod['modules']["module_author"]['name'] + ivod = vod['modules']['module_dynamic']['major']['archive'] + aid = str(ivod['aid']).strip() + title = ivod['title'].strip().replace("", "").replace("", "") + img = ivod['cover'].strip() + # remark = str(ivod['duration_text']).strip() + remark = str(self.second_to_time(self.str2sec(ivod['duration_text']))).strip() + ' ' + str( + up).strip() # 显示分钟数+up主名字 + videos.append({ + "vod_id": aid, + "vod_name": title, + "vod_pic": img + '@672w_378h_1c.jpg', + "vod_remarks": remark + }) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result def get_hot(self, pg): result = {} - url = 'https://api.bilibili.com/x/web-interface/popular?ps=10&pn={0}'.format(pg) - rsp = self.fetch(url, cookies=self.cookies) + url = 'https://api.bilibili.com/x/web-interface/popular?ps=10&pn={0}&ps=9'.format(pg) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: videos = [] - vodList = jo['data']['list'][0:50] + vodList = jo['data']['list'] for vod in vodList: aid = str(vod['aid']).strip() title = vod['title'].strip().replace("", "").replace("", "") img = vod['pic'].strip() - remark = "观看:" + self.zh(vod['stat']['view']) + "  " + str(self.second_to_time(vod['duration'])).strip() + reason=vod['rcmd_reason']['content'].strip() + if reason == '': + reason= '' + else: + reason= ' ' + reason + remark = "观看:" + self.zh(vod['stat']['view']) + " " + str(self.second_to_time(vod['duration'])).strip() videos.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, - "vod_remarks": remark + "vod_pic": img + '@672w_378h_1c.jpg', + "vod_remarks": remark + reason }) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result @@ -251,7 +226,7 @@ class Spider(Spider): result = {} url = 'https://api.bilibili.com/x/web-interface/index/top/feed/rcmd?y_num={0}&fresh_type=3&feed_version=SEO_VIDEO&fresh_idx_1h=1&fetch_row=1&fresh_idx=1&brush=0&homepage_ver=1&ps=10'.format( pg) - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: @@ -262,51 +237,60 @@ class Spider(Spider): aid = str(vod['id']).strip() title = vod['title'].strip().replace("", "").replace("", "") img = vod['pic'].strip() - remark = "观看:" + self.zh(vod['stat']['view']) + "  " + str(self.second_to_time(vod['duration'])).strip() + if 'content' in vod['rcmd_reason']: + reason= ' ' + vod['rcmd_reason']['content'].strip() + else: + reason= '' + remark = "观看:" + self.zh(vod['stat']['view']) + " " + str(self.second_to_time(vod['duration'])).strip() videos.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, - "vod_remarks": remark + "vod_pic": img + '@672w_378h_1c.jpg', + "vod_remarks": remark + reason }) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result - def get_rank(self): + def get_rank(self, pg): + ps=9 + pg_max= int(pg) * ps + pg_min= pg_max - ps result = {} url = 'https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all' - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: videos = [] - vodList = jo['data']['list'][0:50] + vodList = jo['data']['list'] + pc = int(len(vodList) / ps) + 1 + vodList = vodList[pg_min:pg_max] for vod in vodList: aid = str(vod['aid']).strip() title = vod['title'].strip().replace("", "").replace("", "") img = vod['pic'].strip() - remark = "观看:" + self.zh(vod['stat']['view']) + "  " + str(self.second_to_time(vod['duration'])).strip() + remark = "观看:" + self.zh(vod['stat']['view']) + " " + str(self.second_to_time(vod['duration'])).strip() videos.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos - result['page'] = 1 - result['pagecount'] = 1 - result['limit'] = 90 + result['page'] = pg + result['pagecount'] = pc + result['limit'] = 2 result['total'] = 999999 return result def get_history(self, pg): result = {} url = 'https://api.bilibili.com/x/v2/history?pn=%s&ps=10' % pg - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) # 解析api接口,转化成json数据对象 if jo['code'] == 0: @@ -315,6 +299,11 @@ class Spider(Spider): for vod in vodList: if vod['duration'] > 0: # 筛选掉非视频的历史记录 aid = str(vod["aid"]).strip() + if 'redirect_url' in vod: + if 'bangumi' in vod['redirect_url']: + redirect_url = str(vod['redirect_url']).strip() + ep_id = redirect_url.split(r"/")[-1] + aid = ep_id.split(r"?")[0] title = vod["title"].replace("", "").replace("", "").replace(""", '"') img = vod["pic"].strip() @@ -327,16 +316,18 @@ class Spider(Spider): total_time = str(self.second_to_time(vod['duration'])).strip() # 组合 已观看时间 / 总时长 ,赋值给 remark remark = process + ' / ' + total_time + # 视频类型 + type = str(vod["type"]).strip() videos.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result @@ -360,7 +351,7 @@ class Spider(Spider): def get_fav_detail(self, pg, mlid, order): result = {} url = 'https://api.bilibili.com/x/v3/fav/resource/list?media_id=%s&order=%s&pn=%s&ps=10&platform=web&type=0' % (mlid, order, pg) - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: @@ -375,116 +366,157 @@ class Spider(Spider): title = vod['title'].replace("", "").replace("", "").replace(""", '"') img = vod['cover'].strip() - remark = "观看:" + self.zh(vod['cnt_info']['play']) + "  " + str(self.second_to_time(vod['duration'])).strip() + remark = "观看:" + self.zh(vod['cnt_info']['play']) + " " + str(self.second_to_time(vod['duration'])).strip() videos.append({ - "vod_id": aid, + "vod_id": aid + '_mlid' + str(mlid), "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) # videos=self.filter_duration(videos, duration_diff) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result - def get_zone(self, tid): + def get_up_info(self, mid, info): + url = "https://api.bilibili.com/x/web-interface/card?mid={0}".format(mid) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) + jRoot = json.loads(rsp.text) + jo = jRoot['data']['card'] + info['mid'] = mid + info['name'] = jo['name'].replace("", "").replace("", "") + info['face'] = jo['face'] + info['fans'] = self.zh(jo['fans']) + info['like_num'] = self.zh(jRoot['data']['like_num']) + info['vod_count'] = str(jRoot['data']['archive_count']).strip() + info['desc'] = jo['Official']['desc'] + " " + jo['Official']['title'] + if jRoot['data']['following'] == True: + info['following'] = '已关注' + info['followAct'] = 2 + info['followActName'] = '取消关注' + else: + info['following'] = '未关注' + info['followAct'] = 1 + info['followActName'] = '关注' + + def get_zone(self, tid, pg): + ps=9 + pg_max= int(pg) * ps + pg_min= pg_max - ps result = {} url = 'https://api.bilibili.com/x/web-interface/ranking/v2?rid={0}&type=all'.format(tid) - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: videos = [] - vodList = jo['data']['list'][0:50] + vodList = jo['data']['list'] + pc = int(len(vodList) / ps) + 1 + vodList = vodList[pg_min:pg_max] for vod in vodList: aid = str(vod['aid']).strip() title = vod['title'].strip().replace("", "").replace("", "") img = vod['pic'].strip() - remark = "观看:" + self.zh(vod['stat']['view']) + "  " + str(self.second_to_time(vod['duration'])).strip() + remark = "观看:" + self.zh(vod['stat']['view']) + " " + str(self.second_to_time(vod['duration'])).strip() videos.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos - result['page'] = 1 - result['pagecount'] = 1 - result['limit'] = 90 + result['page'] = pg + result['pagecount'] = pc + result['limit'] = 2 result['total'] = 999999 return result - def get_weekly(self): + def get_weekly(self, pg): + ps=9 + pg_max= int(pg) * ps + pg_min= pg_max - ps result = {} url1 = 'https://api.bilibili.com/x/web-interface/popular/series/list' - rsp1 = self.fetch(url1, cookies=self.cookies) + rsp1 = self.fetch(url1, headers=self.header, cookies=self.cookies) content1 = rsp1.text jo1 = json.loads(content1) number = jo1['data']['list'][0]['number'] url = 'https://api.bilibili.com/x/web-interface/popular/series/one?number=' + str(number) - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: videos = [] vodList = jo['data']['list'] + pc = int(len(vodList) / ps) + 1 + vodList = vodList[pg_min:pg_max] for vod in vodList: aid = str(vod['aid']).strip() title = vod['title'].strip() img = vod['pic'].strip() - remark = "观看:" + self.zh(vod['stat']['view']) + "  " + str(self.second_to_time(vod['duration'])).strip() + remark = "观看:" + self.zh(vod['stat']['view']) + " " + str(self.second_to_time(vod['duration'])).strip() videos.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos - result['page'] = 1 - result['pagecount'] = 1 - result['limit'] = 90 + result['page'] = pg + result['pagecount'] = pc + result['limit'] = 2 result['total'] = 999999 return result - def get_must_watch(self): + def get_must_watch(self, pg): + ps=9 + pg_max= int(pg) * ps + pg_min= pg_max - ps result = {} - url = 'https://api.bilibili.com/x/web-interface/popular/precious?page_size=100&page=1' - rsp = self.fetch(url, cookies=self.cookies) + url = 'https://api.bilibili.com/x/web-interface/popular/precious?page_size={0}&page={1}'.format(ps, pg) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: videos = [] vodList = jo['data']['list'] + pc = int(len(vodList) / ps) + 1 + vodList = vodList[pg_min:pg_max] for vod in vodList: aid = str(vod['aid']).strip() title = vod['title'].strip() img = vod['pic'].strip() - remark = "观看:" + self.zh(vod['stat']['view']) + "  " + str(self.second_to_time(vod['duration'])).strip() + remark = "观看:" + self.zh(vod['stat']['view']) + " " + str(self.second_to_time(vod['duration'])).strip() videos.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos - result['page'] = 1 - result['pagecount'] = 1 - result['limit'] = 90 + result['page'] = pg + result['pagecount'] = pc + result['limit'] = 2 result['total'] = 999999 return result def get_toview(self, pg): + ps=9 + pg_max= int(pg) * ps + pg_min= pg_max - ps result = {} url = 'https://api.bilibili.com/x/v2/history/toview' - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) # 解析api接口,转化成json数据对象 if jo['code'] == 0: videos = [] vodList = jo['data']['list'] + pc = int(len(vodList) / ps) + 1 + vodList = vodList[pg_min:pg_max] for vod in vodList: if vod['duration'] > 0: aid = str(vod["aid"]).strip() @@ -502,13 +534,13 @@ class Spider(Spider): videos.append({ "vod_id": aid + '&toview', "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos - result['page'] = 1 - result['pagecount'] = 1 - result['limit'] = 90 + result['page'] = pg + result['pagecount'] = pc + result['limit'] = 2 result['total'] = 999999 return result @@ -518,7 +550,7 @@ class Spider(Spider): result = {} url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}&duration={2}&order={3}&page_size=10'.format( cid, pg, duration_diff, order) - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo.get('code') == 0: @@ -532,17 +564,23 @@ class Spider(Spider): videos.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) # videos=self.filter_duration(videos, duration_diff) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result + def homeVideoContent(self): + result = {} + videos = self.get_rank(pg=1)['list'][0:3] + result['list'] = videos + return result + def categoryContent(self, tid, pg, filter, extend): result = {} if len(self.cookies) <= 0: @@ -553,16 +591,18 @@ class Spider(Spider): return self.get_hot(pg=pg) elif tid == '推荐': return self.get_rcmd(pg=pg) + elif tid == "排行榜": + return self.get_rank(pg=pg) elif tid == '历史记录': return self.get_history(pg=pg) elif tid == "每周必看": - return self.get_weekly() + return self.get_weekly(pg=pg) elif tid == "入站必刷": - return self.get_must_watch() + return self.get_must_watch(pg=pg) elif tid == '稍后再看': return self.get_toview(pg=pg) elif tid in ("1", "3", "129", "4", "119", "36", "188", "234", "160", "211", "217", "223", "155", "5", "181"): - return self.get_zone(tid=tid) + return self.get_zone(tid=tid, pg=pg) elif tid == "收藏": order = 'mtime' @@ -591,7 +631,7 @@ class Spider(Spider): order = extend['order'] url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}&duration={2}&order={3}&page_size=10'.format( tid, pg, duration_diff, order) - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo.get('code') == 0: @@ -607,28 +647,53 @@ class Spider(Spider): videos.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) # videos=self.filter_duration(videos, duration_diff) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result def cleanSpace(self, str): return str.replace('\n', '').replace('\t', '').replace('\r', '').replace(' ', '') + up_mid = '' + def detailContent(self, array): aid = array[0] + if not aid.isdigit() and not 'mlid' in aid: + return self.ysContent(array) + mlid = '' + if 'mlid' in aid: + aid = aid.split('_') + mlid = aid[1].replace('mlid', '') + aid = aid[0] url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid) rsp = self.fetch(url, headers=self.header, cookies=self.cookies) jRoot = json.loads(rsp.text) jo = jRoot['data'] + if 'redirect_url' in jo: + if 'bangumi' in jo['redirect_url']: + redirect_url = str(jo['redirect_url']).strip() + ep_id = redirect_url.split(r"/")[-1] + ep_id = ep_id.split(r"?")[0] + new_array = [] + for i in array: + new_array.append(i) + new_array[0] = ep_id + return self.ysContent(new_array) + self.up_mid = str(jo['owner']['mid']) + info = {} + self.get_up_info(self.up_mid, info) title = jo['title'].replace("", "").replace("", "") pic = jo['pic'] + up_name = jo['owner']['name'] + if not up_name in title: + title += '【' + up_name + "】" desc = jo['desc'] typeName = jo['tname'] date = time.strftime("%Y%m%d", time.localtime(jo['pubdate'])) # 投稿时间本地年月日表示 @@ -638,7 +703,7 @@ class Spider(Spider): remark = str(jo['duration']).strip() vod = { "vod_id": aid, - "vod_name": '[' + jo['owner']['name'] + "]" + title, + "vod_name": title, "vod_pic": pic, "type_name": typeName, "vod_year": date, @@ -646,19 +711,177 @@ class Spider(Spider): "vod_remarks": remark, # 不会显示 'vod_tags': 'mv', # 不会显示 "vod_actor": status, - "vod_director": jo['owner']['name'], - "vod_content": desc + 'vod_director': up_name + ' ' + info['following'], + "vod_content": desc, + 'vod_play_from': 'B站$$$做点什么' + #'vod_play_from': 'B站' } ja = jo['pages'] playUrl = '' for tmpJo in ja: cid = tmpJo['cid'] part = tmpJo['part'].replace("#", "-") - playUrl = playUrl + '{0}${1}_{2}#'.format(part, aid, cid) + playUrl += '{0}${1}_{2}#'.format(part, aid, cid) + follow = '关注UP$' + str(self.up_mid) + '_1_notplay_follow' + unfollow = '取消关注$' + str(self.up_mid) + '_2_notplay_follow' + like = '点赞$' + str(aid) + '_1_notplay_like' + unlike = '取消点赞$' + str(aid) + '_2_notplay_like' + coin1 = '投1币并点赞$' + str(aid) + '_1_notplay_coin' + coin2 = '投2币并点赞$' + str(aid) + '_2_notplay_coin' + fav = '收藏$' + str(aid) + '_0_notplay_fav' + triple = '一键三连$' + str(aid) + '_notplay_triple' + secondPList = [triple, like, coin1, coin2, fav, unlike] + if mlid: + favdel = '取消收藏$' + str(aid) + '_'+ str(mlid) + '_notplay_fav' + secondPList.append(favdel) + secondP = '#'.join(secondPList) + vod['vod_play_url'] = playUrl + '$$$' + secondP + #vod['vod_play_url'] = playUrl + + if 'ugc_season' in jRoot['data']: + season_title = jRoot['data']['ugc_season']['title'].replace("#", "-") + sections = jRoot['data']['ugc_season']['sections'] + sec_len = len(sections) + for section in sections: + episodes = section['episodes'] + playUrl = '' + for episode in episodes: + aid = episode['aid'] + cid = episode['cid'] + ep_title = episode['title'].replace("#", "-") + playUrl += '{0}${1}_{2}#'.format(ep_title, aid, cid) + if sec_len > 1: + sec_title = season_title + section['title'].replace("#", "-") + else: + sec_title = season_title + vod['vod_play_from'] += '$$$' + sec_title + vod['vod_play_url'] += '$$$' + playUrl + + result = { + 'list': [ + vod + ] + } + return result + + con = threading.Condition() + + def get_season(self, n, nList, fromList, urlList, season_id, season_title): + url = 'https://api.bilibili.com/pgc/view/web/season?season_id={0}'.format(season_id) + try: + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) + season = json.loads(rsp.text) + except: + with self.con: + nList.remove(n) + self.con.notifyAll() + return + episode = season['result']['episodes'] + if len(episode) == 0: + with self.con: + nList.remove(n) + self.con.notifyAll() + return + playUrl = '' + for tmpJo in episode: + aid = tmpJo['aid'] + cid = tmpJo['cid'] + part = tmpJo['title'].replace("#", "-") + if tmpJo['badge'] != '': + part += '【' + tmpJo['badge'].replace("#", "-") + '】' + part += tmpJo['long_title'].replace("#", "-") + playUrl += '{0}${1}_{2}_bangumi#'.format(part, aid, cid) + with self.con: + while True: + if n == nList[0]: + fromList.append(season_title) + urlList.append(playUrl) + nList.remove(n) + self.con.notifyAll() + break + else: + self.con.wait() - vod['vod_play_from'] = 'B站' - vod['vod_play_url'] = playUrl + def ysContent(self, array): + aid = array[0] + if 'ep' in aid: + aid = 'ep_id=' + aid.replace('ep', '') + elif 'ss' in aid: + aid = 'season_id=' + aid.replace('ss', '') + else: + aid = 'season_id=' + aid + url = "https://api.bilibili.com/pgc/view/web/season?{0}".format(aid) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) + jRoot = json.loads(rsp.text) + jo = jRoot['result'] + id = jo['season_id'] + title = jo['title'] + s_title = jo['season_title'] + pic = jo['cover'] + # areas = jo['areas']['name'] 改bilidanmu显示弹幕 + typeName = jo['share_sub_title'] + date = jo['publish']['pub_time'][0:4] + dec = jo['evaluate'] + remark = jo['new_ep']['desc'] + stat = jo['stat'] + # 演员和导演框展示视频状态,包括以下内容: + status = "弹幕: " + self.zh(stat['danmakus']) + " 点赞: " + self.zh(stat['likes']) + " 投币: " + self.zh( + stat['coins']) + " 追番追剧: " + self.zh(stat['favorites']) + if 'rating' in jo: + score = "评分: " + str(jo['rating']['score']) + ' ' + jo['subtitle'] + else: + score = "暂无评分" + ' ' + jo['subtitle'] + vod = { + "vod_id": id, + "vod_name": title, + "vod_pic": pic, + "type_name": typeName, + "vod_year": date, + "vod_area": "bilidanmu", + "vod_remarks": remark, + "vod_actor": status, + "vod_director": score, + "vod_content": dec + } + playUrl = '' + for tmpJo in jo['episodes']: + aid = tmpJo['aid'] + cid = tmpJo['cid'] + part = tmpJo['title'].replace("#", "-") + if tmpJo['badge'] != '': + part += '【' + tmpJo['badge'].replace("#", "-") + '】' + part += tmpJo['long_title'].replace("#", "-") + playUrl += '{0}${1}_{2}_bangumi#'.format(part, aid, cid) + fromList = [] + urlList = [] + if playUrl != '': + fromList.append(s_title) + urlList.append(playUrl) + nList = [] + if len(jo['seasons']) > 1: + n = 0 + for season in jo['seasons']: + season_id = season['season_id'] + season_title = season['season_title'] + if season_id == id and len(fromList) > 0: + isHere = fromList.index(s_title) + fromList[isHere] = season_title + continue + n +=1 + nList.append(n) + t = threading.Thread(target=self.get_season, args=(n, nList, fromList, urlList, season_id, season_title, )) + t.start() + while True: + _count = threading.active_count() + #计算线程数,不出结果就调大,结果少了就调小 + if _count <= 2: + break + fromList.insert(1, '追番剧/不追') + urlList.insert(1, '追番剧$' + str(id) + '_add_zhui#取消追番剧$' + str(id) + '_del_zhui') + vod['vod_play_from'] = '$$$'.join(fromList) + vod['vod_play_url'] = '$$$'.join(urlList) + result = { 'list': [ vod @@ -668,7 +891,6 @@ class Spider(Spider): def searchContent(self, key, quick): url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page=1'.format(key) - rsp = self.fetch(url, cookies=self.cookies, headers=self.header) content = rsp.text jo = json.loads(content) @@ -686,7 +908,7 @@ class Spider(Spider): videos.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result = { @@ -694,18 +916,91 @@ class Spider(Spider): } return result + def post_history(self, aid, cid): + data= {'aid': str(aid), 'cid': str(cid), 'csrf': str(self.csrf)} + url = 'http://api.bilibili.com/x/v2/history/report' + self.post(url=url, headers=self.header, cookies=self.cookies, data=data) + + def do_follow(self, mid, act): + data= {'fid': str(mid), 'act': str(act), 'csrf': str(self.csrf)} + url = 'https://api.bilibili.com/x/relation/modify' + self.post(url=url, headers=self.header, cookies=self.cookies, data=data) + + def do_like(self, aid, act): + data= {'aid': str(aid), 'like': str(act), 'csrf': str(self.csrf)} + url = 'https://api.bilibili.com/x/web-interface/archive/like' + self.post(url=url, headers=self.header, cookies=self.cookies, data=data) + + def do_coin(self, aid, coin_num): + data= {'aid': str(aid), 'multiply': str(coin_num), 'select_like': '1', 'csrf': str(self.csrf)} + url = 'https://api.bilibili.com/x/web-interface/coin/add' + self.post(url=url, headers=self.header, cookies=self.cookies, data=data) + + def do_fav(self, aid, act): + data= {'rid': str(aid), 'type': '2', 'csrf': str(self.csrf)} + if str(act) == '0': + data['add_media_ids'] = '0' + else: + data['del_media_ids'] = str(act) + url = 'https://api.bilibili.com/x/v3/fav/resource/deal' + self.post(url=url, headers=self.header, cookies=self.cookies, data=data) + + def do_triple(self, aid): + data= {'aid': str(aid), 'csrf': str(self.csrf)} + url = 'https://api.bilibili.com/x/web-interface/archive/like/triple' + self.post(url=url, headers=self.header, cookies=self.cookies, data=data) + + def do_zhui(self, season_id, act): + data= {'season_id': str(season_id), 'csrf': str(self.csrf)} + url = 'https://api.bilibili.com/pgc/web/follow/{0}'.format(act) + self.post(url=url, headers=self.header, cookies=self.cookies, data=data) + def playerContent(self, flag, id, vipFlags): + if len(self.cookies) <= 0: + self.getCookie() result = {} ids = id.split("_") if len(ids) < 2: return result - url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid={1}&qn=116'.format(ids[0], ids[1]) - if len(self.cookies) <= 0: - self.getCookie() - self.post_history(ids[0], ids[1]) # 回传播放历史记录 - rsp = self.fetch(url, cookies=self.cookies) + elif len(ids) >= 2: + aid = ids[0] + cid = ids[1] + if 'zhui' in ids: + self.do_zhui(aid, cid) + return result + if 'follow' in ids: + self.do_follow(aid, cid) + return result + if 'notplay' in ids: + if 'like' in ids: + self.do_like(aid, cid) + elif 'coin' in ids: + self.do_coin(aid, cid) + elif 'fav' in ids: + self.do_fav(aid, cid) + elif 'do_triple' in ids: + self.do_dislike(aid) + return result + if cid == 'cid': + url = "https://api.bilibili.com/x/web-interface/view?aid=%s" % str(aid) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) + jRoot = json.loads(rsp.text) + cid = jRoot['data']['cid'] + url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid={1}&qn=116'.format(aid, cid) + if 'bangumi' in ids: + url = 'https://api.bilibili.com/pgc/player/web/playurl?aid={0}&cid={1}&qn=116'.format(aid, cid) + self.post_history(aid, cid) # 回传播放历史记录 + rsp = self.fetch(url, cookies=self.cookies, headers=self.header) jRoot = json.loads(rsp.text) - jo = jRoot['data'] + if jRoot['code'] == 0: + if 'data' in jRoot: + jo = jRoot['data'] + elif 'result' in jRoot: + jo = jRoot['result'] + else: + return result + else: + return result ja = jo['durl'] maxSize = -1 position = -1 @@ -733,34 +1028,64 @@ class Spider(Spider): config = { "player": {}, "filter": { - + "关注": [{ + "key": "order", + "name": "排序", + "value": [ + { + "n": "最常访问", + "v": "attention" + }, + { + "n": "最近添加", + "v": "" + } + ] + }], + "UP": [{ + "key": "order", + "name": "排序", + "value": [ + { + "n": "最新发布", + "v": "pubdate" + }, + { + "n": "最多播放", + "v": "click" + }, + { + "n": "最多收藏", + "v": "stow" + }, + { + "n": "最早发布", + "v": "oldest" + } + ] + }], "收藏": [{ "key": "order", "name": "排序", "value": [ - { "n": "收藏时间", "v": "mtime" }, - { "n": "播放量", "v": "view" }, - { "n": "投稿时间", "v": "pubtime" } - ] }, { "key": "mlid", "name": "收藏分区", - "value": [ - ] + "value": [] }], "频道": [{ @@ -865,6 +1190,7 @@ class Spider(Spider): ], } } + header = { "Referer": "https://www.bilibili.com", "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36' diff --git a/txt/py/py_bilimy.py b/txt/py/py_bilimy.py index bfda54e..43d9fc3 100644 --- a/txt/py/py_bilimy.py +++ b/txt/py/py_bilimy.py @@ -5,11 +5,7 @@ import sys sys.path.append('..') from base.spider import Spider import json -from requests import session, utils -import os -import time -import base64 - +import threading class Spider(Spider): box_video_type = '' @@ -34,17 +30,19 @@ class Spider(Spider): def homeContent(self, filter): result = {} cateManual = { + "动态": "动态", + "UP": "UP", + "关注": "关注", + "追番": "追番", + "追剧": "追剧", + "收藏": "收藏", + "历史记录": "历史记录", + # ————————以下可自定义UP主,冒号后须填写UID———————— + #"虫哥说电影": "29296192", # ————————以下可自定义关键词,结果以搜索方式展示———————— - "宅舞": "宅舞", - "cosplay": "cosplay", "周杰伦": "周杰伦", - "狗狗": "汪星人", - "猫咪": "喵星人", - "请自定义关键词": "美女", - # ————————以下可自定义UP主,冒号后须填写UID———————— - "徐云流浪中国": "697166795", - # "虫哥说电影": "29296192", - + #"狗狗": "汪星人", + #"猫咪": "喵星人", } classes = [] for k in cateManual: @@ -56,7 +54,11 @@ class Spider(Spider): if (filter): filters = {} for lk in cateManual: - if not cateManual[lk].isdigit(): + if lk in self.bilibili.config['filter']: + filters.update({ + cateManual[lk]: self.bilibili.config['filter'][lk] + }) + elif not cateManual[lk].isdigit(): link = cateManual[lk] filters.update({ link: [{"key": "order", "name": "排序", @@ -73,18 +75,90 @@ class Spider(Spider): # 用户cookies,请在py_bilibili里填写,此处不用改 cookies = '' + userid = '' def getCookie(self): self.cookies = self.bilibili.getCookie() + self.userid = self.bilibili.userid return self.cookies def homeVideoContent(self): result = {} + videos = self.bilibili.get_dynamic(1)['list'][0:3] + result['list'] = videos return result - def get_up_videos(self, tid, pg): + def get_follow(self, pg, order): + if len(self.cookies) <= 0: + self.getCookie() result = {} - url = 'https://api.bilibili.com/x/space/arc/search?mid={0}&pn={1}&ps=10'.format(tid, pg) + ps = 10 + url = 'https://api.bilibili.com/x/relation/followings?vmid={0}&order=desc&order_type={3}&ps={1}&pn={2}'.format(self.userid, ps, pg, order) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + follow = [] + for f in jo['data']['list']: + mid = f['mid'] + title = str(f['uname']).strip() + img = str(f['face']).strip() + remark = '' + if f['special'] == 1: + remark = '特别关注' + follow.append({ + "vod_id": str(mid) + '_mid', + "vod_name": title, + "vod_pic": img + '@672w_378h_1c.jpg', + "vod_remarks": remark + }) + total = jo['data']['total'] + pc = divmod(total, ps) + if pc[1] != 0: + pc = pc[0] + 1 + else: + pc = pc[0] + result['list'] = follow + result['page'] = pg + result['pagecount'] = pc + result['limit'] = 2 + result['total'] = 999999 + return result + + def get_up_archive(self, pg, order): + mid = self.bilibili.up_mid + if mid.isdigit(): + return self.get_up_videos(mid, pg, order) + else: + return {} + + get_up_videos_mid = '' + get_up_videos_pc = 1 + + def get_up_videos(self, mid, pg, order): + result = {} + ps = 10 + order2 = '' + if order == 'oldest': + order2 = order + order = 'pubdate' + if order2 and int(pg) == 1: + url = 'https://api.bilibili.com/x/space/arc/search?mid={0}&pn={1}&ps={2}&order={3}'.format(mid, pg, ps, order) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + total = jo['data']['page']['count'] + pc = divmod(total, ps) + if pc[1] != 0: + pc = pc[0] + 1 + else: + pc = pc[0] + self.get_up_videos_mid = mid + self.get_up_videos_pc = pc + tmp_pg = pg + if order2: + tmp_pg = self.get_up_videos_pc - int(pg) + 1 + url = 'https://api.bilibili.com/x/space/arc/search?mid={0}&pn={1}&ps={2}&order={3}'.format(mid, tmp_pg, ps, order) rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) @@ -99,20 +173,88 @@ class Spider(Spider): videos.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) + if order2: + videos.reverse() + if int(pg) == 1: + info = {} + self.bilibili.get_up_info(mid, info) + gotoUPHome={ + "vod_id": str(mid) + '_mid', + "vod_name": info['name'] + " 个人主页", + "vod_pic": info['face'] + '@672w_378h_1c.jpg', + "vod_remarks": info['following'] + ' 投稿:' + str(info['vod_count']) + } + videos.insert(0, gotoUPHome) + pc = self.get_up_videos_pc + if self.get_up_videos_mid != mid: + total = jo['data']['page']['count'] + pc = divmod(total, ps) + if pc[1] != 0: + pc = pc[0] + 1 + else: + pc = pc[0] + self.get_up_videos_mid = mid + self.get_up_videos_pc = pc result['list'] = videos result['page'] = pg - result['pagecount'] = 9999 - result['limit'] = 90 + result['pagecount'] = pc + result['limit'] = 2 result['total'] = 999999 return result + def get_zhui(self, pg, mode): + result = {} + if len(self.cookies) <= 0: + self.getCookie() + url = 'https://api.bilibili.com/x/space/bangumi/follow/list?type={2}&pn={1}&ps=10&vmid={0}'.format(self.userid, pg, mode) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + videos = [] + vodList = jo['data']['list'] + for vod in vodList: + aid = str(vod['season_id']).strip() + title = vod['title'] + img = vod['cover'].strip() + remark = '' + if 'index_show' in vod['new_ep']: + remark = vod['new_ep']['index_show'] + videos.append({ + "vod_id": 'ss' + aid, + "vod_name": title, + "vod_pic": img + '@672w_378h_1c.jpg', + "vod_remarks": remark + }) + result['list'] = videos + result['page'] = pg + result['pagecount'] = 9999 + result['limit'] = 2 + result['total'] = 999999 + return result + def categoryContent(self, tid, pg, filter, extend): - self.box_video_type = "分区" if tid.isdigit(): - return self.get_up_videos(tid, pg) + order = 'pubdate' + if 'order' in extend: + order = extend['order'] + return self.get_up_videos(tid, pg, order) + elif tid == "关注": + order = 'attention' + if 'order' in extend: + order = extend['order'] + return self.get_follow(pg, order) + elif tid == "UP": + order = 'pubdate' + if 'order' in extend: + order = extend['order'] + return self.get_up_archive(pg, order) + elif tid == "追番": + return self.get_zhui(pg, 1) + elif tid == "追剧": + return self.get_zhui(pg, 2) else: result = self.bilibili.categoryContent(tid, pg, filter, extend) return result @@ -120,48 +262,87 @@ class Spider(Spider): def cleanSpace(self, str): return str.replace('\n', '').replace('\t', '').replace('\r', '').replace(' ', '') - def detailContent(self, array): - if self.box_video_type == "搜索": - mid = array[0] - # 获取UP主视频列表,ps后面为视频数量,默认为20,加快加载速度 - url = 'https://api.bilibili.com/x/space/arc/search?mid={0}&pn=1&ps=20'.format(mid) - rsp = self.fetch(url, headers=self.header) + con = threading.Condition() + + def get_up_vod(self, mid, n, nList, urlList): + # 获取UP主视频列表 + url = 'https://api.bilibili.com/x/space/arc/search?mid={0}&ps=50&pn={1}'.format(mid, n) + try: + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text - jRoot = json.loads(content) - jo = jRoot['data']['list']['vlist'] - - url2 = "https://api.bilibili.com/x/web-interface/card?mid={0}".format(mid) - rsp2 = self.fetch(url2, headers=self.header) - jRoot2 = json.loads(rsp2.text) - jo2 = jRoot2['data']['card'] - name = jo2['name'].replace("", "").replace("", "") - pic = jo2['face'] - desc = jo2['Official']['desc'] + " " + jo2['Official']['title'] + except: + with self.con: + nList.remove(n) + self.con.notifyAll() + return + jRoot = json.loads(content) + jo = jRoot['data']['list']['vlist'] + if len(jo) == 0: + with self.con: + nList.remove(n) + self.con.notifyAll() + return + playUrl = '' + vodItems = [] + for tmpJo in jo: + aid = tmpJo['aid'] + part = tmpJo['title'].replace("#", "-") + url = '{0}${1}_cid'.format(part, aid) + vodItems.append(url) + playUrl = '#'.join(vodItems) + with self.con: + while True: + if n == nList[0]: + urlList.append(playUrl) + nList.remove(n) + self.con.notifyAll() + break + else: + self.con.wait() + + def detailContent(self, array): + if 'mid' in array[0]: + arrays = array[0].split("_") + mid = arrays[0] + self.bilibili.up_mid = mid + info = {} + i = threading.Thread(target=self.bilibili.get_up_info, args=(mid, info, )) + i.start() + #最多获取最近2页的投稿 + pn = 3 + urlList = [] + #nList = [] + #for n in range(pn): + # n += 1 + # nList.append(n) + # with self.con: + # if threading.active_count() > 10: + # self.con.wait() + # t = threading.Thread(target=self.get_up_vod, args=(mid, n, nList, urlList, )) + # t.start() + while True: + _count = threading.active_count() + #计算线程数,不出结果就调大,结果少了就调小 + if _count <= 2: + break vod = { "vod_id": mid, - "vod_name": name + " " + "个人主页", - "vod_pic": pic, - "type_name": "最近投稿", - "vod_year": "", + "vod_name": info['name'] + " 个人主页", + "vod_pic": info['face'], "vod_area": "bilidanmu", "vod_remarks": "", # 不会显示 - 'vod_tags': 'mv', # 不会显示 - "vod_actor": "粉丝数:" + self.bilibili.zh(jo2['fans']), - "vod_director": name, - "vod_content": desc + "vod_tags": 'mv', # 不会显示 + "vod_actor": "粉丝数:" + info['fans'] + " 投稿数:" + info['vod_count'] + " 点赞数:" +info['like_num'], + "vod_director": info['name'] + ' UID:' +str(mid) + " " + info['following'], + "vod_content": info['desc'], + 'vod_play_from': '更多视频在我的哔哩——UP标签,按上键刷新查看' } - playUrl = '' - for tmpJo in jo: - eid = tmpJo['aid'] - url3 = "https://api.bilibili.com/x/web-interface/view?aid=%s" % str(eid) - rsp3 = self.fetch(url3) - jRoot3 = json.loads(rsp3.text) - cid = jRoot3['data']['cid'] - part = tmpJo['title'].replace("#", "-") - playUrl = playUrl + '{0}${1}_{2}#'.format(part, eid, cid) - - vod['vod_play_from'] = 'B站' - vod['vod_play_url'] = playUrl + first = '点击相应按钮可以关注/取关$' + str(mid) + '_mid' + follow = '关注$' + str(mid) + '_1_mid_follow' + unfollow = '取消关注$' + str(mid) + '_2_mid_follow' + doWhat = [first, follow, unfollow] + urlList = doWhat + urlList + vod['vod_play_url'] = '#'.join(urlList) result = { 'list': [ @@ -173,7 +354,6 @@ class Spider(Spider): return self.bilibili.detailContent(array) def searchContent(self, key, quick): - self.box_video_type = "搜索" if len(self.cookies) <= 0: self.getCookie() url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=bili_user&keyword={0}'.format(key) @@ -183,14 +363,14 @@ class Spider(Spider): videos = [] vodList = jo['data']['result'] for vod in vodList: - aid = str(vod['mid']) # str(vod["res"][0]["aid"]) + mid = str(vod['mid']) title = "UP主:" + vod['uname'].strip() + " ☜" + key img = 'https:' + vod['upic'].strip() remark = "粉丝数" + self.bilibili.zh(vod['fans']) videos.append({ - "vod_id": aid, + "vod_id": mid + '_mid', "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result = { diff --git a/txt/py/py_biliys.py b/txt/py/py_biliys.py index d19b4a5..a47e587 100644 --- a/txt/py/py_biliys.py +++ b/txt/py/py_biliys.py @@ -10,7 +10,6 @@ import os import time import base64 - class Spider(Spider): def getDependence(self): return ['py_bilibili'] @@ -40,8 +39,6 @@ class Spider(Spider): "纪录片": "3", "综艺": "7", "全部": "全部", - "追番": "追番", - "追剧": "追剧", "时间表": "时间表", # ————————以下可自定义关键字,结果以影视类搜索展示———————— # "喜羊羊": "喜羊羊" @@ -60,11 +57,9 @@ class Spider(Spider): # 用户cookies cookies = '' - userid = '' def getCookie(self): self.cookies = self.bilibili.getCookie() - self.userid = self.bilibili.userid return self.cookies # 将超过10000的数字换成成以万和亿为单位 @@ -82,100 +77,87 @@ class Spider(Spider): def homeVideoContent(self): result = {} - videos = self.get_rank(1)['list'][0:5] - for i in [4, 2, 5, 3, 7]: - videos += self.get_rank2(i)['list'][0:5] + videos = self.get_rank2(tid=4, pg=1)['list'][0:3] + #videos = self.get_rank(tid=1, pg=1)['list'][0:5] + #for i in [4, 2, 5, 3, 7]: + # videos += self.get_rank2(tid=i, pg=1)['list'][0:5] result['list'] = videos return result - def get_rank(self, tid): + def get_rank(self, tid, pg): + ps=9 + pg_max= int(pg) * ps + pg_min= pg_max - ps result = {} url = 'https://api.bilibili.com/pgc/web/rank/list?season_type={0}&day=3'.format(tid) - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: videos = [] vodList = jo['result']['list'] + pc = int(len(vodList) / ps) + 1 + vodList = vodList[pg_min:pg_max] for vod in vodList: aid = str(vod['season_id']).strip() title = vod['title'].strip() img = vod['cover'].strip() - remark = vod['new_ep']['index_show'] + remark = '' + if 'index_show' in vod['new_ep']: + remark = vod['new_ep']['index_show'] videos.append({ - "vod_id": aid, + "vod_id": 'ss' + aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos - result['page'] = 1 - result['pagecount'] = 1 - result['limit'] = 90 + result['page'] = pg + result['pagecount'] = pc + result['limit'] = 2 result['total'] = 999999 return result - def get_rank2(self, tid): + def get_rank2(self, tid, pg): + ps=9 + pg_max= int(pg) * ps + pg_min= pg_max - ps result = {} url = 'https://api.bilibili.com/pgc/season/rank/web/list?season_type={0}&day=3'.format(tid) - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: videos = [] vodList = jo['data']['list'] + pc = int(len(vodList) / ps) + 1 + vodList = vodList[pg_min:pg_max] for vod in vodList: aid = str(vod['season_id']).strip() title = vod['title'].strip() img = vod['cover'].strip() - remark = vod['new_ep']['index_show'] + remark = '' + if 'index_show' in vod['new_ep']: + remark = vod['new_ep']['index_show'] videos.append({ - "vod_id": aid, + "vod_id": 'ss' + aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos - result['page'] = 1 - result['pagecount'] = 1 - result['limit'] = 90 + result['page'] = pg + result['pagecount'] = pc + result['limit'] = 2 result['total'] = 999999 return result - def get_zhui(self, pg, mode): - result = {} - if len(self.cookies) <= 0: - self.getCookie() - url = 'https://api.bilibili.com/x/space/bangumi/follow/list?type={2}&follow_status=0&pn={1}&ps=10&vmid={0}'.format(self.userid, pg, mode) - rsp = self.fetch(url, cookies=self.cookies) - content = rsp.text - jo = json.loads(content) - videos = [] - vodList = jo['data']['list'] - for vod in vodList: - aid = str(vod['season_id']).strip() - title = vod['title'] - img = vod['cover'].strip() - remark = vod['new_ep']['index_show'].strip() - videos.append({ - "vod_id": aid, - "vod_name": title, - "vod_pic": img, - "vod_remarks": remark - }) - result['list'] = videos - result['page'] = pg - result['pagecount'] = 9999 - result['limit'] = 90 - result['total'] = 999999 - return result - def get_all(self, tid, pg, order, season_status, extend): result = {} if len(self.cookies) <= 0: self.getCookie() url = 'https://api.bilibili.com/pgc/season/index/result?order={2}&pagesize=10&type=1&season_type={0}&page={1}&season_status={3}'.format(tid, pg, order, season_status) - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) videos = [] @@ -186,22 +168,22 @@ class Spider(Spider): img = vod['cover'].strip() remark = vod['index_show'].strip() videos.append({ - "vod_id": aid, + "vod_id": 'ss' + aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result def get_timeline(self, tid, pg): result = {} url = 'https://api.bilibili.com/pgc/web/timeline/v2?season_type={0}&day_before=2&day_after=4'.format(tid) - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: @@ -213,9 +195,9 @@ class Spider(Spider): img = vod['cover'].strip() remark = vod['pub_index'] + ' ' + vod['follows'].replace('系列', '') videos1.append({ - "vod_id": aid, + "vod_id": 'ss' + aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) videos2 = [] @@ -229,9 +211,9 @@ class Spider(Spider): date = str(time.strftime("%m-%d %H:%M", time.localtime(vod['pub_ts']))) remark = date + " " + vod['pub_index'] videos2.append({ - "vod_id": aid, + "vod_id": 'ss' + aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos2 + videos1 @@ -246,9 +228,9 @@ class Spider(Spider): if len(self.cookies) <= 0: self.getCookie() if tid == "1": - return self.get_rank(tid=tid) + return self.get_rank(tid=tid, pg=pg) elif tid in {"2", "3", "4", "5", "7"}: - return self.get_rank2(tid=tid) + return self.get_rank2(tid=tid, pg=pg) elif tid == "全部": tid = '1' # 全部界面默认展示最多播放的番剧 order = '2' @@ -260,10 +242,6 @@ class Spider(Spider): if 'season_status' in extend: season_status = extend['season_status'] return self.get_all(tid, pg, order, season_status, extend) - elif tid == "追番": - return self.get_zhui(pg, 1) - elif tid == "追剧": - return self.get_zhui(pg, 2) elif tid == "时间表": tid = 1 if 'tid' in extend: @@ -277,69 +255,20 @@ class Spider(Spider): return str.replace('\n', '').replace('\t', '').replace('\r', '').replace(' ', '') def detailContent(self, array): - aid = array[0] - url = "https://api.bilibili.com/pgc/view/web/season?season_id={0}".format(aid) - rsp = self.fetch(url, headers=self.header) - jRoot = json.loads(rsp.text) - jo = jRoot['result'] - id = jo['season_id'] - title = jo['title'] - pic = jo['cover'] - # areas = jo['areas']['name'] 改bilidanmu显示弹幕 - typeName = jo['share_sub_title'] - date = jo['publish']['pub_time'][0:4] - dec = jo['evaluate'] - remark = jo['new_ep']['desc'] - stat = jo['stat'] - # 演员和导演框展示视频状态,包括以下内容: - status = "弹幕: " + self.zh(stat['danmakus']) + " 点赞: " + self.zh(stat['likes']) + " 投币: " + self.zh( - stat['coins']) + " 追番追剧: " + self.zh(stat['favorites']) - if 'rating' in jo: - score = "评分: " + str(jo['rating']['score']) + ' ' + jo['subtitle'] - else: - score = "暂无评分" + ' ' + jo['subtitle'] - vod = { - "vod_id": id, - "vod_name": title, - "vod_pic": pic, - "type_name": typeName, - "vod_year": date, - "vod_area": "bilidanmu", - "vod_remarks": remark, - "vod_actor": status, - "vod_director": score, - "vod_content": dec - } - ja = jo['episodes'] - playUrl = '' - for tmpJo in ja: - aid = tmpJo['aid'] - cid = tmpJo['cid'] - part = tmpJo['title'].replace("#", "-") - playUrl = playUrl + '{0}${1}_{2}#'.format(part, aid, cid) - - vod['vod_play_from'] = 'B站' - vod['vod_play_url'] = playUrl - - result = { - 'list': [ - vod - ] - } - return result + return self.bilibili.ysContent(array) def searchContent(self, key, quick): if len(self.cookies) <= 0: self.getCookie() url1 = 'https://api.bilibili.com/x/web-interface/search/type?search_type=media_bangumi&keyword={0}'.format( key) # 番剧搜索 - rsp1 = self.fetch(url1, cookies=self.cookies) + rsp1 = self.fetch(url1, headers=self.header, cookies=self.cookies) content1 = rsp1.text jo1 = json.loads(content1) rs1 = jo1['data'] url2 = 'https://api.bilibili.com/x/web-interface/search/type?search_type=media_ft&keyword={0}'.format( key) # 影视搜索 - rsp2 = self.fetch(url2, cookies=self.cookies) + rsp2 = self.fetch(url2, headers=self.header, cookies=self.cookies) content2 = rsp2.text jo2 = json.loads(content2) rs2 = jo2['data'] @@ -356,9 +285,9 @@ class Spider(Spider): img = vod['cover'].strip() # vod['eps'][0]['cover'].strip()原来的错误写法 remark = vod['index_show'] videos.append({ - "vod_id": aid, + "vod_id": 'ss' + aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result = { @@ -367,46 +296,7 @@ class Spider(Spider): return result def playerContent(self, flag, id, vipFlags): - result = {} - ids = id.split("_") - header = { - "Referer": "https://www.bilibili.com", - "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36" - } - url = 'https://api.bilibili.com/pgc/player/web/playurl?qn=116&aid={0}&cid={1}'.format(ids[0], ids[1]) - if len(self.cookies) <= 0: - self.getCookie() - self.bilibili.post_history(ids[0], ids[1]) # 回传播放历史记录 - rsp = self.fetch(url, cookies=self.cookies, headers=header) - jRoot = json.loads(rsp.text) - if jRoot['message'] != 'success': - print("需要大会员权限才能观看") - return {} - jo = jRoot['result'] - ja = jo['durl'] - maxSize = -1 - position = -1 - for i in range(len(ja)): - tmpJo = ja[i] - if maxSize < int(tmpJo['size']): - maxSize = int(tmpJo['size']) - position = i - - url = '' - if len(ja) > 0: - if position == -1: - position = 0 - url = ja[position]['url'] - - result["parse"] = 0 - result["playUrl"] = '' - result["url"] = url - result["header"] = { - "Referer": "https://www.bilibili.com", - "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36" - } - result["contentType"] = 'video/x-flv' - return result + return self.bilibili.playerContent(flag, id, vipFlags) config = { "player": {}, diff --git a/txt/py/py_bilizb.py b/txt/py/py_bilizb.py index 18a17e5..fd4f3d0 100644 --- a/txt/py/py_bilizb.py +++ b/txt/py/py_bilizb.py @@ -5,11 +5,6 @@ import sys sys.path.append('..') from base.spider import Spider import json -import requests -from requests import session, utils -import time -import base64 - class Spider(Spider): def getDependence(self): @@ -22,7 +17,10 @@ class Spider(Spider): def homeContent(self, filter): result = {} cateManual = { + "我的关注": "我的关注", + "观看记录": "观看记录", "推荐": "推荐", + "热门": "热门", "网游": "2", "手游": "3", "单机": "6", @@ -32,8 +30,6 @@ class Spider(Spider): "赛事": "13", "电台": "5", "虚拟": "9", - "我的关注": "我的关注", - "观看记录": "观看记录", } classes = [] @@ -49,7 +45,6 @@ class Spider(Spider): # 用户cookies cookies = '' - userid = '' def getCookie(self): self.cookies = self.bilibili.getCookie() @@ -83,19 +78,22 @@ class Spider(Spider): def get_live_userInfo(self, uid): url = 'https://api.live.bilibili.com/live_user/v1/Master/info?uid=%s' % uid - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: return jo['data']["info"]["uname"] def homeVideoContent(self,): - return self.get_hot(1) + result = {} + videos = self.get_hot(1)['list'][0:3] + result['list'] = videos + return result def get_recommend(self, pg): result = {} url = 'https://api.live.bilibili.com/xlive/web-interface/v1/webMain/getList?platform=web&page=%s' % pg - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: @@ -109,20 +107,20 @@ class Spider(Spider): videos.append({ "vod_id": aid + '&live', "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result def get_hot(self, pg): result = {} - url = 'https://api.live.bilibili.com/room/v1/room/get_user_recommend?page=%s&page_size=20' % pg - rsp = self.fetch(url, cookies=self.cookies) + url = 'https://api.live.bilibili.com/room/v1/room/get_user_recommend?page=%s&page_size=10' % pg + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: @@ -136,13 +134,13 @@ class Spider(Spider): videos.append({ "vod_id": aid + '&live', "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result @@ -150,7 +148,7 @@ class Spider(Spider): result = {} url = 'https://api.live.bilibili.com/xlive/web-interface/v1/second/getList?platform=web&parent_area_id=%s&area_id=%s&sort_type=online&page=%s' % ( parent_area_id, area_id, pg) - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: @@ -164,20 +162,20 @@ class Spider(Spider): videos.append({ "vod_id": aid + '&live', "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result def get_fav(self, pg): result = {} url = 'https://api.live.bilibili.com/xlive/web-ucenter/v1/xfetter/GetWebList?page=%s&page_size=10' % pg - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) videos = [] @@ -190,20 +188,20 @@ class Spider(Spider): videos.append({ "vod_id": aid + '&live', "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos result['page'] = pg result['pagecount'] = 9999 - result['limit'] = 90 + result['limit'] = 2 result['total'] = 999999 return result def get_history(self): result = {} - url = 'https://api.bilibili.com/x/web-interface/history/cursor?ps=10&type=live' - rsp = self.fetch(url, cookies=self.cookies) + url = 'https://api.bilibili.com/x/web-interface/history/cursor?ps=21&type=live' + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) content = rsp.text jo = json.loads(content) if jo['code'] == 0: @@ -217,7 +215,7 @@ class Spider(Spider): videos.append({ "vod_id": aid + '&live', "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) result['list'] = videos @@ -239,6 +237,8 @@ class Spider(Spider): return self.get_live(pg=pg, parent_area_id=parent_area_id, area_id=area_id) if tid == "推荐": return self.get_recommend(pg) + if tid == "热门": + return self.get_hot(pg) if tid == "我的关注": return self.get_fav(pg) if tid == "观看记录": @@ -250,8 +250,8 @@ class Spider(Spider): def detailContent(self, array): arrays = array[0].split("&") - aid = arrays[0] - url = "https://api.live.bilibili.com/room/v1/Room/get_info?room_id=%s" % aid + room_id = arrays[0] + url = "https://api.live.bilibili.com/room/v1/Room/get_info?room_id=%s" % room_id rsp = self.fetch(url, headers=self.header, cookies=self.cookies) jRoot = json.loads(rsp.text) if jRoot.get('code') == 0: @@ -259,27 +259,34 @@ class Spider(Spider): title = jo['title'].replace("", "").replace("", "") pic = jo.get("user_cover") desc = jo.get('description') - dire = self.get_live_userInfo(jo["uid"]) - typeName = jo.get("area_name") - live_status = str(jo.get('live_status')).replace("0", "未开播").replace("1", "").replace("2", "") - live_time = str(jo.get('live_time'))[5: 16] + uid = str(jo["uid"]) + info = {} + self.bilibili.get_up_info(uid, info) + dire = self.get_live_userInfo(uid) + self.bilibili.up_mid = uid + typeName = jo['parent_area_name'] + '--' + jo['area_name'] + if jo['live_status'] == 0: + live_status = "未开播" + else: + live_status = "开播时间:" + jo['live_time'] remark = '在线人数:' + str(jo['online']).strip() vod = { - "vod_id": aid, + "vod_id": room_id, "vod_name": title, "vod_pic": pic, "type_name": typeName, "vod_year": "", "vod_area": "bilidanmu", "vod_remarks": remark, - "vod_actor": "主播:" + dire + "  " + "房间号:" + aid + "  " + live_status, - "vod_director": "关注:" + self.zh(jo.get('attention')) + "  " + "开播时间:" + live_time, + "vod_actor": "关注:" + self.zh(jo.get('attention')) + " 房间号:" + room_id + " UID:" + uid, + "vod_director": dire + '  ' + info['following'] + "  " + live_status, "vod_content": desc, } - playUrl = 'flv线路原画$platform=web&quality=4_' + aid + '#flv线路高清$platform=web&quality=3_' + aid + '#h5线路原画$platform=h5&quality=4_' + aid + '#h5线路高清$platform=h5&quality=3_' + aid + playUrl = 'flv线路原画$platform=web&quality=4_' + room_id + '#flv线路高清$platform=web&quality=3_' + room_id + '#h5线路原画$platform=h5&quality=4_' + room_id + '#h5线路高清$platform=h5&quality=3_' + room_id - vod['vod_play_from'] = 'B站' - vod['vod_play_url'] = playUrl + vod['vod_play_from'] = 'B站$$$关注/取关' + secondP = info['followActName'] + '$' + str(uid) + '_' + str(info['followAct']) + '_follow#' + vod['vod_play_url'] = playUrl + '$$$' + secondP result = { 'list': [ vod @@ -309,7 +316,7 @@ class Spider(Spider): videos1.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) videos2 = [] @@ -323,7 +330,7 @@ class Spider(Spider): videos2.append({ "vod_id": aid, "vod_name": title, - "vod_pic": img, + "vod_pic": img + '@672w_378h_1c.jpg', "vod_remarks": remark }) videos = videos1 + videos2 @@ -335,13 +342,14 @@ class Spider(Spider): def playerContent(self, flag, id, vipFlags): result = {} ids = id.split("_") - + if 'follow' in ids: + self.bilibili.do_follow(ids[0], ids[1]) + return result url = 'https://api.live.bilibili.com/room/v1/Room/playUrl?cid=%s&%s' % (ids[1], ids[0]) - # raise Exception(url) if len(self.cookies) <= 0: self.getCookie() - rsp = self.fetch(url, cookies=self.cookies) + rsp = self.fetch(url, headers=self.header, cookies=self.cookies) jRoot = json.loads(rsp.text) if jRoot['code'] == 0: diff --git a/txt/py/py_czspp.py b/txt/py/py_czspp.py index 999a063..dbaba70 100644 --- a/txt/py/py_czspp.py +++ b/txt/py/py_czspp.py @@ -67,32 +67,40 @@ class Spider(Spider): # 元类 默认的元类 type } return result - def getCookie(self,url,header): + def getCookie(self,url): + header = { + "Referer": 'https://czspp.com/', + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" + } session = requests.session() rsp = session.get(url) - nurl = 'https://czspp.com' + self.regStr(rsp.text, 'src=\"(.*?)\"') - nrsp = session.get(nurl, headers=header) - key = self.regStr(nrsp.text, 'var key=\"(.*?)\"') - avalue = self.regStr(nrsp.text, 'value=\"(.*?)\"') - c = '' - for i in range(0, len(avalue)): - a = avalue[i] - b = ord(a) - c = c + str(b) - value = hashlib.md5(c.encode()).hexdigest() - session.get('https://czspp.com/a20be899_96a6_40b2_88ba_32f1f75f1552_yanzheng_ip.php?type=96c4e20a0e951f471d32dae103e83881&key={0}&value={1}'.format(key,value), headers=header) - return session + if '人机验证' in rsp.text: + append = self.regStr(rsp.text, 'src=\"(/.*?)\"') + nurl = 'https://czspp.com' + append + nrsp = session.get(nurl, headers=header) + key = self.regStr(nrsp.text, 'var key=\"(.*?)\"') + avalue = self.regStr(nrsp.text, 'value=\"(.*?)\"') + c = '' + for i in range(0, len(avalue)): + a = avalue[i] + b = ord(a) + c = c + str(b) + value = hashlib.md5(c.encode()).hexdigest() + session.get('https://czspp.com/a20be899_96a6_40b2_88ba_32f1f75f1552_yanzheng_ip.php?type=96c4e20a0e951f471d32dae103e83881&key={0}&value={1}'.format(key, value), headers=header) + return session.get(url, headers=header) + elif '检测中' in rsp.text: + append = self.regStr(rsp.text, 'href =\"(/.*?)\"') + session.get('https://czspp.com{0}'.format(append), headers=header) + return session.get(url, headers=header) + else: + return rsp + + def categoryContent(self, tid, pg, filter, extend): result = {} url = 'https://czspp.com/{0}/page/{1}'.format(tid,pg) - header = { - "Connection": "keep-alive", - "Referer": url, - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" - } - session = self.getCookie(url,header) - rsp = session.get(url, headers=header) + rsp = self.getCookie(url) root = self.html(self.cleanText(rsp.text)) aList = root.xpath("//div[contains(@class,'bt_img mi_ne_kd mrb')]/ul/li") videos = [] @@ -121,13 +129,7 @@ class Spider(Spider): # 元类 默认的元类 type def detailContent(self, array): tid = array[0] url = 'https://czspp.com/movie/{0}.html'.format(tid) - header = { - "Connection": "keep-alive", - "Referer": url, - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" - } - session = self.getCookie(url, header) - rsp = session.get(url, headers=header) + rsp = self.getCookie(url) root = self.html(self.cleanText(rsp.text)) node = root.xpath("//div[@class='dyxingq']")[0] pic = node.xpath(".//div[@class='dyimg fl']/img/@src")[0] @@ -198,13 +200,7 @@ class Spider(Spider): # 元类 默认的元类 type def searchContent(self, key, quick): url = 'https://czspp.com/xssearch?q={0}'.format(urllib.parse.quote(key)) - header = { - "Connection": "keep-alive", - "Referer": url, - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" - } - session = self.getCookie(url, header) - rsp = session.get(url, headers=header) + rsp = self.getCookie(url) root = self.html(self.cleanText(rsp.text)) vodList = root.xpath("//div[contains(@class,'mi_ne_kd')]/ul/li/a") videos = [] @@ -247,14 +243,8 @@ class Spider(Spider): # 元类 默认的元类 type def playerContent(self, flag, id, vipFlags): result = {} url = 'https://czspp.com/v_play/{0}.html'.format(id) - header = { - "Connection": "keep-alive", - "Referer": url, - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36" - } - session = self.getCookie(url, header) + rsp = self.getCookie(url) pat = '\\"([^\\"]+)\\";var [\\d\\w]+=function dncry.*md5.enc.Utf8.parse\\(\\"([\\d\\w]+)\\".*md5.enc.Utf8.parse\\(([\\d]+)\\)' - rsp = session.get(url, headers=header) html = rsp.text content = self.regStr(html, pat) if content == '': -- GitLab