From 90c6470ab5ec56abab295e662e2436ff630e397e Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Wed, 23 Nov 2022 11:19:45 +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 +- txt/py/py_alist.py | 1 + txt/py/py_bilibili.py | 1033 ++++++++++++++++++++++++++++++++++------- txt/py/py_bilimy.py | 215 +++++++++ txt/py/py_biliys.py | 536 +++++++++++++++++++++ txt/py/py_bilizb.py | 31 +- 6 files changed, 1623 insertions(+), 195 deletions(-) create mode 100644 txt/py/py_bilimy.py create mode 100644 txt/py/py_biliys.py diff --git a/js/version.txt b/js/version.txt index d90b530..76b8246 100644 --- a/js/version.txt +++ b/js/version.txt @@ -1 +1 @@ -3.9.23beta6 \ No newline at end of file +3.9.23beta7 \ No newline at end of file diff --git a/txt/py/py_alist.py b/txt/py/py_alist.py index bea7970..40849ba 100644 --- a/txt/py/py_alist.py +++ b/txt/py/py_alist.py @@ -25,6 +25,7 @@ class Spider(Spider): # 元类 默认的元类 type def homeContent(self, filter): result = {} cateManual = { + "丫仙女": "http://alist.xiaoya.pro/", "七米蓝": "https://al.chirmyram.com/", "梅花盘": "https://pan.142856.xyz/OneDrive", "触光云盘": "https://pan.ichuguang.com", diff --git a/txt/py/py_bilibili.py b/txt/py/py_bilibili.py index 7597b37..dd92c4d 100644 --- a/txt/py/py_bilibili.py +++ b/txt/py/py_bilibili.py @@ -1,175 +1,870 @@ -#coding=utf-8 -#!/usr/bin/python +# coding=utf-8 +# !/usr/bin/python import sys -sys.path.append('..') + +sys.path.append('..') from base.spider import Spider import json +import requests +from requests import session, utils import time import base64 -class Spider(Spider): # 元类 默认的元类 type - def getName(self): - return "哔哩" - def init(self,extend=""): - print("============{0}============".format(extend)) - pass - def isVideoFormat(self,url): - pass - def manualVideoCheck(self): - pass - def homeContent(self,filter): - result = {} - cateManual = { - "Zard": "Zard", - "玩具汽车": "玩具汽车", - "儿童": "儿童", - "幼儿": "幼儿", - "儿童玩具": "儿童玩具", - "昆虫": "昆虫", - "动物世界": "动物世界", - "纪录片": "纪录片", - "相声小品": "相声小品", - "搞笑": "搞笑", - "假窗-白噪音": "窗+白噪音", - "演唱会": "演唱会" - } - classes = [] - for k in cateManual: - classes.append({ - 'type_name':k, - 'type_id':cateManual[k] - }) - result['class'] = classes - if(filter): - result['filters'] = self.config['filter'] - return result - def homeVideoContent(self): - result = { - 'list':[] - } - return result - cookies = '' - def getCookie(self): - rsp = self.fetch("https://www.bilibili.com/") - self.cookies = rsp.cookies - return rsp.cookies - def categoryContent(self,tid,pg,filter,extend): - result = {} - url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&duration=4&page={1}'.format(tid,pg) - if len(self.cookies) <= 0: - self.getCookie() - rsp = self.fetch(url,cookies=self.cookies) - content = rsp.text - jo = json.loads(content) - if jo['code'] != 0: - rspRetry = self.fetch(url,cookies=self.getCookie()) - content = rspRetry.text - jo = json.loads(content) - videos = [] - vodList = jo['data']['result'] - for vod in vodList: - aid = str(vod['aid']).strip() - title = vod['title'].strip().replace("","").replace("","") - img = 'https:' + vod['pic'].strip() - remark = str(vod['duration']).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 cleanSpace(self,str): - return str.replace('\n','').replace('\t','').replace('\r','').replace(' ','') - def detailContent(self,array): - aid = array[0] - url = "https://api.bilibili.com/x/web-interface/view?aid={0}".format(aid) - - rsp = self.fetch(url,headers=self.header) - jRoot = json.loads(rsp.text) - jo = jRoot['data'] - title = jo['title'].replace("","").replace("","") - pic = jo['pic'] - desc = jo['desc'] - typeName = jo['tname'] - vod = { - "vod_id":aid, - "vod_name":title, - "vod_pic":pic, - "type_name":typeName, - "vod_year":"", - "vod_area":"", - "vod_remarks":"", - "vod_actor":"", - "vod_director":"", - "vod_content":desc - } - ja = jo['pages'] - playUrl = '' - for tmpJo in ja: - cid = tmpJo['cid'] - part = tmpJo['part'] - playUrl = playUrl + '{0}${1}_{2}#'.format(part,aid,cid) - - vod['vod_play_from'] = 'B站' - vod['vod_play_url'] = playUrl - - result = { - 'list':[ - vod - ] - } - return result - def searchContent(self,key,quick): - result = { - 'list':[] - } - return result - def playerContent(self,flag,id,vipFlags): - # https://www.555dianying.cc/vodplay/static/js/playerconfig.js - result = {} - - ids = id.split("_") - url = 'https://api.bilibili.com:443/x/player/playurl?avid={0}&cid=%20%20{1}&qn=112'.format(ids[0],ids[1]) - rsp = self.fetch(url) - jRoot = json.loads(rsp.text) - jo = jRoot['data'] - 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 - - config = { - "player": {}, - "filter": {} - } - header = {} - - def localProxy(self,param): - return [200, "video/MP2T", action, ""] \ No newline at end of file + +class Spider(Spider): + + def getName(self): + return "哔哩哔哩" + + # 主页 + def homeContent(self, filter): + result = {} + cateManual = { + "动态": "动态", + "热门": "热门", + "推荐": "推荐", + "历史记录": "历史记录", + # "稍后再看":"稍后再看", #意义不大,隐藏该项 + "收藏": "收藏", + "动画": "1", + "音乐": "3", + "舞蹈": "129", + "游戏": "4", + "鬼畜": "119", + "知识": "36", + "科技": "188", + "运动": "234", + "生活": "160", + "美食": "211", + "动物": "217", + "汽车": "223", + "时尚": "155", + "娱乐": "5", + "影视": "181", + "每周必看": "每周必看", + "入站必刷": "入站必刷", + "频道": "频道", + # ————————以下可自定义关键字,结果以搜索方式展示———————— + } + classes = [] + for k in cateManual: + classes.append({ + 'type_name': k, + 'type_id': cateManual[k] + }) + result['class'] = classes + if (filter): + result['filters'] = self.config['filter'] + return result + + cookies = '' + userid = '' + + def getCookie(self): + import requests + import http.cookies + # --------↓↓↓↓↓↓↓------在下方双引号内填写-------↓↓↓↓↓↓↓-------- + raw_cookie_line = "" + simple_cookie = http.cookies.SimpleCookie(raw_cookie_line) + cookie_jar = requests.cookies.RequestsCookieJar() + cookie_jar.update(simple_cookie) + rsp = session() + rsp.cookies = cookie_jar + content = self.fetch("http://api.bilibili.com/x/web-interface/nav", cookies=rsp.cookies) + res = json.loads(content.text) + if res["code"] == 0: + self.cookies = rsp.cookies + self.userid = res["data"].get('mid') + return cookie_jar + + 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) + content = rsp.text + jo = json.loads(content) + fav_list = [] + if jo['code'] == 0: + for fav in jo['data'].get('list'): + fav_dict = { + 'n': fav['title'].replace("", "").replace("", "").replace(""", + '"').strip(), + 'v': fav['id']} + fav_list.append(fav_dict) + if self.config["filter"].get('收藏'): + for i in self.config["filter"].get('收藏'): + if i['key'] == 'mlid': + i['value'] = fav_list + + def init(self, extend=""): + print("============{0}============".format(extend)) + pass + + def isVideoFormat(self, url): + pass + + def manualVideoCheck(self): + pass + + # 将超过10000的数字换成成以万和亿为单位 + def zh(self, num): + if int(num) >= 100000000: + p = round(float(num) / float(100000000), 1) + p = str(p) + '亿' + else: + if int(num) >= 10000: + p = round(float(num) / float(10000), 1) + p = str(p) + '万' + else: + p = str(num) + return p + + # 将秒数转化为 时分秒的格式 + def second_to_time(self, a): + if a < 3600: + return time.strftime("%M:%S", time.gmtime(a)) + else: + return time.strftime("%H:%M:%S", time.gmtime(a)) + + # 字符串时分秒以及分秒形式转换成秒 + def str2sec(self, x): + x = str(x) + try: + h, m, s = x.strip().split(':') # .split()函数将其通过':'分隔开,.strip()函数用来除去空格 + return int(h) * 3600 + int(m) * 60 + int(s) # int()函数转换成整数运算 + except: + m, s = x.strip().split(':') # .split()函数将其通过':'分隔开,.strip()函数用来除去空格 + return int(m) * 60 + int(s) # int()函数转换成整数运算 + + # 按时间过滤 + def filter_duration(self, vodlist, key): + if key == '0': + return vodlist + else: + vod_list_new = [i for i in vodlist if + self.time_diff1[key][0] <= self.str2sec(str(i["vod_remarks"])) < self.time_diff1[key][1]] + return vod_list_new + + time_diff1 = {'1': [0, 300], + '2': [300, 900], '3': [900, 1800], '4': [1800, 3600], + '5': [3600, 99999999999999999999999999999999] + } + 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'] + for vod in vodList: + aid = str(vod['aid']).strip() + title = vod['title'].strip().replace("", "").replace("", "") + img = vod['pic'].strip() + # view = "▶" + self.zh(vod['stat']['view']) + ' 🕓' # 标签上加入播放量 + remark = 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 + 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) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + self.dynamic_offset = jo['data'].get('offset') + 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 + }) + result['list'] = videos + result['page'] = pg + result['pagecount'] = 9999 + result['limit'] = 90 + result['total'] = 999999 + return result + + def get_hot(self, pg): + result = {} + url = 'https://api.bilibili.com/x/web-interface/popular?ps=20&pn={0}'.format(pg) + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + videos = [] + vodList = jo['data']['list'] + for vod in vodList: + aid = str(vod['aid']).strip() + title = vod['title'].strip().replace("", "").replace("", "") + img = vod['pic'].strip() + remark = 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 + result['page'] = pg + result['pagecount'] = 9999 + result['limit'] = 90 + result['total'] = 999999 + return result + + def get_rcmd(self, pg): + 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=20'.format( + pg) + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + videos = [] + vodList = jo['data']['item'] + for vod in vodList: + if vod['duration'] > 0: + aid = str(vod['id']).strip() + title = vod['title'].strip().replace("", "").replace("", "") + img = vod['pic'].strip() + remark = 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 + result['page'] = pg + result['pagecount'] = 9999 + result['limit'] = 90 + result['total'] = 999999 + return result + + def get_rank(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'] + for vod in vodList: + aid = str(vod['aid']).strip() + title = vod['title'].strip().replace("", "").replace("", "") + img = vod['pic'].strip() + remark = 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 + result['page'] = 1 + result['pagecount'] = 1 + result['limit'] = 90 + result['total'] = 999999 + return result + + def get_history(self, pg): + result = {} + url = 'https://api.bilibili.com/x/v2/history?pn=%s' % pg + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) # 解析api接口,转化成json数据对象 + if jo['code'] == 0: + videos = [] + vodList = jo['data'] + for vod in vodList: + if vod['duration'] > 0: # 筛选掉非视频的历史记录 + aid = str(vod["aid"]).strip() + title = vod["title"].replace("", "").replace("", "").replace(""", + '"') + img = vod["pic"].strip() + # 获取已观看时间 + if str(vod['progress']) == '-1': + process = str(self.second_to_time(vod['duration'])).strip() + else: + process = str(self.second_to_time(vod['progress'])).strip() + # 获取视频总时长 + total_time = str(self.second_to_time(vod['duration'])).strip() + # 组合 已观看时间 / 总时长 ,赋值给 remark + remark = process + ' / ' + total_time + 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_fav(self, pg, order, extend): + mlid = '' + fav_config = self.config["filter"].get('收藏') + # 默认显示第一个收藏内容 + if fav_config: + for i in fav_config: + if i['key'] == 'mlid': + if len(i['value']) > 0: + mlid = i['value'][0]['v'] + # print(self.config["filter"].get('收藏')) + if 'mlid' in extend: + mlid = extend['mlid'] + if mlid: + return self.get_fav_detail(pg=pg, mlid=mlid, order=order) + else: + return {} + + 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=20&platform=web&type=0' % (mlid, order, pg) + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + videos = [] + vodList = jo['data']['medias'] + for vod in vodList: + # print(vod) + # 只展示类型为 视频的条目 + # 过滤去掉收藏中的 已失效视频;如果不喜欢可以去掉这个 if条件 + if vod.get('type') in [2] and vod.get('title') != '已失效视频': + aid = str(vod['id']).strip() + title = vod['title'].replace("", "").replace("", "").replace(""", + '"') + img = vod['cover'].strip() + remark = str(self.second_to_time(vod['duration'])).strip() + videos.append({ + "vod_id": aid, + "vod_name": title, + "vod_pic": img, + "vod_remarks": remark + }) + # videos=self.filter_duration(videos, duration_diff) + result['list'] = videos + result['page'] = pg + result['pagecount'] = 9999 + result['limit'] = 90 + result['total'] = 999999 + return result + + def get_zone(self, tid): + result = {} + url = 'https://api.bilibili.com/x/web-interface/ranking/v2?rid={0}&type=all'.format(tid) + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + videos = [] + vodList = jo['data']['list'] + for vod in vodList: + aid = str(vod['aid']).strip() + title = vod['title'].strip().replace("", "").replace("", "") + img = vod['pic'].strip() + remark = 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 + result['page'] = 1 + result['pagecount'] = 1 + result['limit'] = 90 + result['total'] = 999999 + return result + + def get_weekly(self): + result = {} + url1 = 'https://api.bilibili.com/x/web-interface/popular/series/list' + rsp1 = self.fetch(url1, 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) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + videos = [] + vodList = jo['data']['list'] + for vod in vodList: + aid = str(vod['aid']).strip() + title = vod['title'].strip() + img = vod['pic'].strip() + remark = 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 + result['page'] = 1 + result['pagecount'] = 1 + result['limit'] = 90 + result['total'] = 999999 + return result + + def get_must_watch(self): + result = {} + url = 'https://api.bilibili.com/x/web-interface/popular/precious?page_size=100&page=1' + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + videos = [] + vodList = jo['data']['list'] + for vod in vodList: + aid = str(vod['aid']).strip() + title = vod['title'].strip() + img = vod['pic'].strip() + remark = 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 + result['page'] = 1 + result['pagecount'] = 1 + result['limit'] = 90 + result['total'] = 999999 + return result + + def get_toview(self, pg): + result = {} + url = 'https://api.bilibili.com/x/v2/history/toview' + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) # 解析api接口,转化成json数据对象 + if jo['code'] == 0: + videos = [] + vodList = jo['data']['list'] + for vod in vodList: + if vod['duration'] > 0: + aid = str(vod["aid"]).strip() + title = vod["title"].replace("", "").replace("", "").replace(""", + '"') + img = vod["pic"].strip() + if str(vod['progress']) == '-1': + process = str(self.second_to_time(vod['duration'])).strip() + else: + process = str(self.second_to_time(vod['progress'])).strip() + # 获取视频总时长 + total_time = str(self.second_to_time(vod['duration'])).strip() + # 组合 已观看时间 / 总时长 ,赋值给 remark + remark = process + ' / ' + total_time + videos.append({ + "vod_id": aid + '&toview', + "vod_name": title, + "vod_pic": img, + "vod_remarks": remark + }) + result['list'] = videos + result['page'] = 1 + result['pagecount'] = 1 + result['limit'] = 90 + result['total'] = 999999 + return result + + chanel_offset = '' + + def get_channel(self, pg, cid, extend, order, duration_diff): + result = {} + url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}&duration={2}&order={3}'.format( + cid, pg, duration_diff, order) + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + if jo.get('code') == 0: + videos = [] + vodList = jo['data']['result'] + for vod in vodList: + aid = str(vod['aid']).strip() + title = vod['title'].replace("", "").replace("", "").replace(""", '"') + img = 'https:' + vod['pic'].strip() + remark = str(self.second_to_time(self.str2sec(vod['duration']))).strip() + videos.append({ + "vod_id": aid, + "vod_name": title, + "vod_pic": img, + "vod_remarks": remark + }) + # videos=self.filter_duration(videos, duration_diff) + result['list'] = videos + result['page'] = pg + result['pagecount'] = 9999 + result['limit'] = 90 + result['total'] = 999999 + return result + + def categoryContent(self, tid, pg, filter, extend): + result = {} + if len(self.cookies) <= 0: + self.getCookie() + if tid == "动态": + return self.get_dynamic(pg=pg) + elif tid == "热门": + return self.get_hot(pg=pg) + elif tid == '推荐': + return self.get_rcmd(pg=pg) + elif tid == '历史记录': + return self.get_history(pg=pg) + elif tid == "每周必看": + return self.get_weekly() + elif tid == "入站必刷": + return self.get_must_watch() + 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) + + elif tid == "收藏": + order = 'mtime' + if 'order' in extend: + order = extend['order'] + return self.get_fav(pg=pg, order=order, extend=extend) + + elif tid == '频道': + cid = '搞笑' + if 'cid' in extend: + cid = extend['cid'] + duration_diff = '0' + if 'duration' in extend: + duration_diff = extend['duration'] + order = 'totalrank' + if 'order' in extend: + order = extend['order'] + return self.get_channel(pg=pg, cid=cid, extend=extend, order=order, duration_diff=duration_diff) + + else: + duration_diff = '0' + if 'duration' in extend: + duration_diff = extend['duration'] + order = 'totalrank' + if 'order' in extend: + order = extend['order'] + url = 'https://api.bilibili.com/x/web-interface/search/type?search_type=video&keyword={0}&page={1}&duration={2}&order={3}'.format( + tid, pg, duration_diff, order) + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + if jo.get('code') == 0: + videos = [] + vodList = jo['data']['result'] + for vod in vodList: + aid = str(vod['aid']).strip() + title = vod['title'].replace("", "").replace("", "").replace(""", + '"') + img = 'https:' + vod['pic'].strip() + # remark = str(vod['duration']).strip() + remark = str(self.second_to_time(self.str2sec(vod['duration']))).strip() + videos.append({ + "vod_id": aid, + "vod_name": title, + "vod_pic": img, + "vod_remarks": remark + }) + # videos=self.filter_duration(videos, duration_diff) + result['list'] = videos + result['page'] = pg + result['pagecount'] = 9999 + result['limit'] = 90 + result['total'] = 999999 + return result + + def cleanSpace(self, str): + return str.replace('\n', '').replace('\t', '').replace('\r', '').replace(' ', '') + + def detailContent(self, array): + aid = array[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'] + title = jo['title'].replace("", "").replace("", "") + pic = jo['pic'] + desc = jo['desc'] + typeName = jo['tname'] + date = time.strftime("%Y%m%d", time.localtime(jo['pubdate'])) # 投稿时间本地年月日表示 + stat = jo['stat'] + # 演员项展示视频状态,包括以下内容: + status = "播放: " + self.zh(stat['view']) + " 弹幕: " + self.zh(stat['danmaku']) + " 点赞: " + self.zh(stat['like']) + " 收藏: " + self.zh(stat['favorite']) + " 投币: " + self.zh(stat['coin']) + remark = str(jo['duration']).strip() + vod = { + "vod_id": aid, + "vod_name": '[' + jo['owner']['name'] + "]" + title, + "vod_pic": pic, + "type_name": typeName, + "vod_year": date, + "vod_area": "bilidanmu", + "vod_remarks": remark, # 不会显示 + 'vod_tags': 'mv', # 不会显示 + "vod_actor": status, + "vod_director": jo['owner']['name'], + "vod_content": desc + } + ja = jo['pages'] + playUrl = '' + for tmpJo in ja: + cid = tmpJo['cid'] + part = tmpJo['part'].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 + + 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) + if jo['code'] != 0: + rspRetry = self.fetch(url, cookies=self.cookies, headers=self.header) + content = rspRetry.text + jo = json.loads(content) + videos = [] + vodList = jo['data']['result'] + for vod in vodList: + aid = str(vod['aid']).strip() + title = '[' + key + ']' + vod['title'].replace("", "").replace("", "").replace(""", '"') + img = 'https:' + vod['pic'].strip() + remark = str(self.second_to_time(self.str2sec(vod['duration']))).strip() + videos.append({ + "vod_id": aid, + "vod_name": title, + "vod_pic": img, + "vod_remarks": remark + }) + result = { + 'list': videos + } + return result + + def playerContent(self, flag, id, vipFlags): + 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() + rsp = self.fetch(url, cookies=self.cookies) + jRoot = json.loads(rsp.text) + jo = jRoot['data'] + 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36' + } + result["contentType"] = 'video/x-flv' + return result + + config = { + "player": {}, + "filter": { + + "收藏": [{ + "key": "order", + "name": "排序", + "value": [ + + { + "n": "收藏时间", + "v": "mtime" + }, + + { + "n": "播放量", + "v": "view" + }, + + { + "n": "投稿时间", + "v": "pubtime" + } + + ] + }, + { + "key": "mlid", + "name": "收藏分区", + "value": [ + ] + }], + + "频道": [{ + "key": "order", + "name": "排序", + "value": [ + + { + "n": "综合排序", + "v": "totalrank" + }, + + { + "n": "最新发布", + "v": "pubdate" + }, + + { + "n": "最多点击", + "v": "click" + }, + { + "n": "最多收藏", + "v": "stow" + }, + + { + "n": "最多弹幕", + "v": "dm" + }, + + ] + }, + { + "key": "duration", + "name": "时长", + "value": [{ + "n": "全部", + "v": "0" + }, + { + "n": "60分钟以上", + "v": "4" + }, + + { + "n": "30~60分钟", + "v": "3" + }, + { + "n": "5~30分钟", + "v": "2" + }, + { + "n": "5分钟以下", + "v": "1" + } + ] + }, {"key": "cid", "name": "分类", + "value": [{'n': '搞笑', 'v': '搞笑'}, {'n': '美食', 'v': '美食'}, {'n': '鬼畜', 'v': '鬼畜'}, + {'n': '美妆', 'v': '美妆'}, {'n': 'mmd', 'v': 'mmd'}, {'n': '科普', 'v': '科普'}, + {'n': 'COSPLAY', 'v': 'COSPLAY'}, {'n': '漫展', 'v': '漫展'}, {'n': 'MAD', 'v': 'MAD'}, + {'n': '手书', 'v': '手书'}, {'n': '穿搭', 'v': '穿搭'}, {'n': '发型', 'v': '发型'}, + {'n': '化妆教程', 'v': '化妆教程'}, {'n': '电音', 'v': '电音'}, {'n': '欧美音乐', 'v': '欧美音乐'}, + {'n': '中文翻唱', 'v': '中文翻唱'}, {'n': '洛天依', 'v': '洛天依'}, {'n': '翻唱', 'v': '翻唱'}, + {'n': '日文翻唱', 'v': '日文翻唱'}, {'n': '科普', 'v': '科普'}, {'n': '技术宅', 'v': '技术宅'}, + {'n': '历史', 'v': '历史'}, {'n': '科学', 'v': '科学'}, {'n': '人文', 'v': '人文'}, + {'n': '科幻', 'v': '科幻'}, {'n': '手机', 'v': '手机'}, {'n': '手机评测', 'v': '手机评测'}, + {'n': '电脑', 'v': '电脑'}, {'n': '摄影', 'v': '摄影'}, {'n': '笔记本', 'v': '笔记本'}, + {'n': '装机', 'v': '装机'}, {'n': '课堂教育', 'v': '课堂教育'}, {'n': '公开课', 'v': '公开课'}, + {'n': '演讲', 'v': '演讲'}, {'n': 'PS教程', 'v': 'PS教程'}, {'n': '编程', 'v': '编程'}, + {'n': '英语学习', 'v': '英语学习'}, {'n': '喵星人', 'v': '喵星人'}, {'n': '萌宠', 'v': '萌宠'}, + {'n': '汪星人', 'v': '汪星人'}, {'n': '大熊猫', 'v': '大熊猫'}, {'n': '柴犬', 'v': '柴犬'}, + {'n': '田园犬', 'v': '田园犬'}, {'n': '吱星人', 'v': '吱星人'}, {'n': '美食', 'v': '美食'}, + {'n': '甜点', 'v': '甜点'}, {'n': '吃货', 'v': '吃货'}, {'n': '厨艺', 'v': '厨艺'}, + {'n': '烘焙', 'v': '烘焙'}, {'n': '街头美食', 'v': '街头美食'}, + {'n': 'A.I.Channel', 'v': 'A.I.Channel'}, {'n': '虚拟UP主', 'v': '虚拟UP主'}, + {'n': '神楽めあ', 'v': '神楽めあ'}, {'n': '白上吹雪', 'v': '白上吹雪'}, {'n': '婺源', 'v': '婺源'}, + {'n': 'hololive', 'v': 'hololive'}, {'n': 'EXO', 'v': 'EXO'}, + {'n': '防弹少年团', 'v': '防弹少年团'}, {'n': '肖战', 'v': '肖战'}, {'n': '王一博', 'v': '王一博'}, + {'n': '易烊千玺', 'v': '易烊千玺'}, {'n': '赵今麦', 'v': '赵今麦'}, {'n': '宅舞', 'v': '宅舞'}, + {'n': '街舞', 'v': '街舞'}, {'n': '舞蹈教学', 'v': '舞蹈教学'}, {'n': '明星舞蹈', 'v': '明星舞蹈'}, + {'n': '韩舞', 'v': '韩舞'}, {'n': '古典舞', 'v': '古典舞'}, {'n': '旅游', 'v': '旅游'}, + {'n': '绘画', 'v': '绘画'}, {'n': '手工', 'v': '手工'}, {'n': 'vlog', 'v': 'vlog'}, + {'n': 'DIY', 'v': 'DIY'}, {'n': '手绘', 'v': '手绘'}, {'n': '综艺', 'v': '综艺'}, + {'n': '国家宝藏', 'v': '国家宝藏'}, {'n': '脱口秀', 'v': '脱口秀'}, {'n': '日本综艺', 'v': '日本综艺'}, + {'n': '国内综艺', 'v': '国内综艺'}, {'n': '人类观察', 'v': '人类观察'}, {'n': '影评', 'v': '影评'}, + {'n': '电影解说', 'v': '电影解说'}, {'n': '影视混剪', 'v': '影视混剪'}, {'n': '影视剪辑', 'v': '影视剪辑'}, + {'n': '漫威', 'v': '漫威'}, {'n': '超级英雄', 'v': '超级英雄'}, {'n': '影视混剪', 'v': '影视混剪'}, + {'n': '影视剪辑', 'v': '影视剪辑'}, + {'n': '诸葛亮', 'v': '诸葛亮'}, {'n': '韩剧', 'v': '韩剧'}, {'n': '王司徒', 'v': '王司徒'}, + {'n': '泰剧', 'v': '泰剧'}, + {'n': '郭德纲', 'v': '郭德纲'}, {'n': '相声', 'v': '相声'}, {'n': '张云雷', 'v': '张云雷'}, + {'n': '秦霄贤', 'v': '秦霄贤'}, {'n': '孟鹤堂', 'v': '孟鹤堂'}, {'n': '岳云鹏', 'v': '岳云鹏'}, + {'n': '假面骑士', 'v': '假面骑士'}, {'n': '特摄', 'v': '特摄'}, {'n': '奥特曼', 'v': '奥特曼'}, + {'n': '迪迦奥特曼', 'v': '迪迦奥特曼'}, {'n': '超级战队', 'v': '超级战队'}, {'n': '铠甲勇士', 'v': '铠甲勇士'}, + {'n': '健身', 'v': '健身'}, {'n': '篮球', 'v': '篮球'}, {'n': '体育', 'v': '体育'}, + {'n': '帕梅拉', 'v': '帕梅拉'}, {'n': '极限运动', 'v': '极限运动'}, {'n': '足球', 'v': '足球'}, + {'n': '星海', 'v': '星海'}, {'n': '张召忠', 'v': '张召忠'}, {'n': '航母', 'v': '航母'}, + {'n': '航天', 'v': '航天'}, {'n': '导弹', 'v': '导弹'}, {'n': '战斗机', 'v': '战斗机'}] + } + ], + } + } + 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' + } + + def localProxy(self, param): + + return [200, "video/MP2T", action, ""] diff --git a/txt/py/py_bilimy.py b/txt/py/py_bilimy.py new file mode 100644 index 0000000..b4e751d --- /dev/null +++ b/txt/py/py_bilimy.py @@ -0,0 +1,215 @@ +# coding=utf-8 +# !/usr/bin/python +import sys + +sys.path.append('..') +from base.spider import Spider +import json +from requests import session, utils +import os +import time +import base64 + + +class Spider(Spider): + box_video_type = '' + + def getDependence(self): + return ['py_bilibili'] + + def getName(self): + return "我的哔哩" + + def init(self, extend=""): + self.bilibili = extend[0] + print("============{0}============".format(extend)) + pass + + def isVideoFormat(self, url): + pass + + def manualVideoCheck(self): + pass + + def homeContent(self, filter): + result = {} + cateManual = { + # ————————以下可自定义关键词,结果以搜索方式展示———————— + "宅舞": "宅舞", + "cosplay": "cosplay", + "周杰伦": "周杰伦", + "狗狗": "汪星人", + "猫咪": "喵星人", + "请自定义关键词": "美女", + # ————————以下可自定义UP主,冒号后须填写UID———————— + "虫哥说电影": "29296192", + + } + classes = [] + for k in cateManual: + classes.append({ + 'type_name': k, + 'type_id': cateManual[k] + }) + result['class'] = classes + if (filter): + filters = {} + for lk in cateManual: + if not cateManual[lk].isdigit(): + link = cateManual[lk] + filters.update({ + link: [{"key": "order", "name": "排序", + "value": [{"n": "综合排序", "v": "totalrank"}, {"n": "最新发布", "v": "pubdate"}, + {"n": "最多点击", "v": "click"}, {"n": "最多收藏", "v": "stow"}, + {"n": "最多弹幕", "v": "dm"}, ]}, + {"key": "duration", "name": "时长", + "value": [{"n": "全部", "v": "0"}, {"n": "60分钟以上", "v": "4"}, + {"n": "30~60分钟", "v": "3"}, {"n": "5~30分钟", "v": "2"}, + {"n": "5分钟以下", "v": "1"}]}] + }) + result['filters'] = filters + return result + + # 用户cookies,请在py_bilibili里填写,此处不用改 + cookies = '' + + def getCookie(self): + self.cookies = self.bilibili.getCookie() + return self.cookies + + def homeVideoContent(self): + result = {} + return result + + def get_up_videos(self, tid, pg): + result = {} + url = 'https://api.bilibili.com/x/space/arc/search?mid={0}&pn={1}&ps=20'.format(tid, pg) + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + videos = [] + vodList = jo['data']['list']['vlist'] + for vod in vodList: + aid = str(vod['aid']).strip() + title = vod['title'].strip().replace("", "").replace("", "") + img = vod['pic'].strip() + remark = str(vod['length']).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 categoryContent(self, tid, pg, filter, extend): + self.box_video_type = "分区" + if tid.isdigit(): + return self.get_up_videos(tid, pg) + else: + result = self.bilibili.categoryContent(tid, pg, filter, extend) + return result + + 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) + 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'] + vod = { + "vod_id": mid, + "vod_name": name + " " + "个人主页", + "vod_pic": pic, + "type_name": "最近投稿", + "vod_year": "", + "vod_area": "bilidanmu", + "vod_remarks": "", # 不会显示 + 'vod_tags': 'mv', # 不会显示 + "vod_actor": "粉丝数:" + self.bilibili.zh(jo2['fans']), + "vod_director": name, + "vod_content": desc + } + 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 + + result = { + 'list': [ + vod + ] + } + return result + else: + 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) + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + videos = [] + vodList = jo['data']['result'] + for vod in vodList: + aid = str(vod['mid']) # str(vod["res"][0]["aid"]) + title = "UP主:" + vod['uname'].strip() + " ☜" + key + img = 'https:' + vod['upic'].strip() + remark = "粉丝数" + self.bilibili.zh(vod['fans']) + videos.append({ + "vod_id": aid, + "vod_name": title, + "vod_pic": img, + "vod_remarks": remark + }) + result = { + 'list': videos + } + return result + + def playerContent(self, flag, id, vipFlags): + return self.bilibili.playerContent(flag, id, vipFlags) + + config = { + "player": {}, + "filter": { + } + } + + 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' + } + + def localProxy(self, param): + return [200, "video/MP2T", action, ""] diff --git a/txt/py/py_biliys.py b/txt/py/py_biliys.py new file mode 100644 index 0000000..02ffce6 --- /dev/null +++ b/txt/py/py_biliys.py @@ -0,0 +1,536 @@ +# coding=utf-8 +# !/usr/bin/python +import sys + +sys.path.append('..') +from base.spider import Spider +import json +from requests import session, utils +import os +import time +import base64 + + +class Spider(Spider): + def getDependence(self): + return ['py_bilibili'] + + def getName(self): + return "哔哩影视" + + def init(self, extend=""): + self.bilibili = extend[0] + print("============{0}============".format(extend)) + pass + + def isVideoFormat(self, url): + pass + + def manualVideoCheck(self): + pass + + def homeContent(self, filter): + result = {} + cateManual = { + "番剧": "1", + "国创": "4", + "电影": "2", + "电视剧": "5", + "纪录片": "3", + "综艺": "7", + "全部": "全部", + "追番": "追番", + "追剧": "追剧", + "时间表": "时间表", + } + classes = [] + for k in cateManual: + classes.append({ + 'type_name': k, + 'type_id': cateManual[k] + }) + result['class'] = classes + if (filter): + result['filters'] = self.config['filter'] + return result + + # 用户cookies + cookies = '' + userid = '' + + def getCookie(self): + self.cookies = self.bilibili.getCookie() + self.userid = self.bilibili.userid + return self.cookies + + # 将超过10000的数字换成成以万和亿为单位 + def zh(self, num): + if int(num) >= 100000000: + p = round(float(num) / float(100000000), 1) + p = str(p) + '亿' + else: + if int(num) >= 10000: + p = round(float(num) / float(10000), 1) + p = str(p) + '万' + else: + p = str(num) + return p + + 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] + result['list'] = videos + return result + + def get_rank(self, tid): + result = {} + url = 'https://api.bilibili.com/pgc/web/rank/list?season_type={0}&day=3'.format(tid) + rsp = self.fetch(url, cookies=self.cookies) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + videos = [] + vodList = jo['result']['list'] + for vod in vodList: + aid = str(vod['season_id']).strip() + title = vod['title'].strip() + img = vod['cover'].strip() + remark = vod['new_ep']['index_show'] + videos.append({ + "vod_id": aid, + "vod_name": title, + "vod_pic": img, + "vod_remarks": remark + }) + result['list'] = videos + result['page'] = 1 + result['pagecount'] = 1 + result['limit'] = 90 + result['total'] = 999999 + return result + + def get_rank2(self, tid): + 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) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + videos = [] + vodList = jo['data']['list'] + for vod in vodList: + aid = str(vod['season_id']).strip() + title = vod['title'].strip() + img = vod['cover'].strip() + remark = vod['new_ep']['index_show'] + videos.append({ + "vod_id": aid, + "vod_name": title, + "vod_pic": img, + "vod_remarks": remark + }) + result['list'] = videos + result['page'] = 1 + result['pagecount'] = 1 + result['limit'] = 90 + 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=20&type=1&season_type={0}&page={1}&season_status={3}'.format(tid, pg, order, season_status) + 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['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_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) + content = rsp.text + jo = json.loads(content) + if jo['code'] == 0: + videos1 = [] + vodList = jo['result']['latest'] + for vod in vodList: + aid = str(vod['season_id']).strip() + title = vod['title'].strip() + img = vod['cover'].strip() + remark = vod['pub_index'] + ' ' + vod['follows'].replace('系列', '') + videos1.append({ + "vod_id": aid, + "vod_name": title, + "vod_pic": img, + "vod_remarks": remark + }) + videos2 = [] + for i in range(0, 7): + vodList = jo['result']['timeline'][i]['episodes'] + for vod in vodList: + if str(vod['published']) == "0": + aid = str(vod['season_id']).strip() + title = str(vod['title']).strip() + img = str(vod['cover']).strip() + date = str(time.strftime("%m-%d %H:%M", time.localtime(vod['pub_ts']))) + remark = date + " " + vod['pub_index'] + videos2.append({ + "vod_id": aid, + "vod_name": title, + "vod_pic": img, + "vod_remarks": remark + }) + result['list'] = videos2 + videos1 + result['page'] = 1 + result['pagecount'] = 1 + result['limit'] = 90 + result['total'] = 999999 + return result + + def categoryContent(self, tid, pg, filter, extend): + result = {} + if len(self.cookies) <= 0: + self.getCookie() + if tid == "1": + return self.get_rank(tid=tid) + elif tid in {"2", "3", "4", "5", "7"}: + return self.get_rank2(tid=tid) + elif tid == "全部": + tid = '1' + order = '2' + season_status = '-1' + if 'tid' in extend: + tid = extend['tid'] + if 'order' in extend: + order = extend['order'] + 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: + tid = extend['tid'] + return self.get_timeline(tid, pg) + else: + result = self.searchContent(key=tid, quick="false") + return result + + def cleanSpace(self, str): + 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: + eid = tmpJo['id'] + cid = tmpJo['cid'] + part = tmpJo['title'].replace("#", "-") + playUrl = playUrl + '{0}${1}_{2}#'.format(part, eid, cid) + + vod['vod_play_from'] = 'B站' + vod['vod_play_url'] = playUrl + + result = { + 'list': [ + vod + ] + } + return result + + 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) + 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) + content2 = rsp2.text + jo2 = json.loads(content2) + rs2 = jo2['data'] + videos = [] + if rs1['numResults'] == 0: + vodList = jo2['data']['result'] + elif rs2['numResults'] == 0: + vodList = jo1['data']['result'] + else: + vodList = jo1['data']['result'] + jo2['data']['result'] + for vod in vodList: + aid = str(vod['season_id']).strip() + title = key + '➢' + vod['title'].strip().replace("", "").replace("", "") + img = vod['cover'].strip() # vod['eps'][0]['cover'].strip()原来的错误写法 + remark = vod['index_show'] + videos.append({ + "vod_id": aid, + "vod_name": title, + "vod_pic": img, + "vod_remarks": remark + }) + result = { + 'list': videos + } + 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&ep_id={0}&cid={1}'.format(ids[0], ids[1]) + if len(self.cookies) <= 0: + self.getCookie() + 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 + + config = { + "player": {}, + "filter": { + "全部": [ + { + "key": "tid", + "name": "分类", + "value": [{ + "n": "番剧", + "v": "1" + }, + { + "n": "国创", + "v": "4" + }, + + { + "n": "电影", + "v": "2" + }, + { + "n": "电视剧", + "v": "5" + }, + { + "n": "记录片", + "v": "3" + }, + { + "n": "综艺", + "v": "7" + } + + ] + }, + { + "key": "order", + "name": "排序", + "value": [ + + { + "n": "播放数量", + "v": "2" + }, + + { + "n": "更新时间", + "v": "0" + }, + + { + "n": "最高评分", + "v": "4" + }, + { + "n": "弹幕数量", + "v": "1" + }, + { + "n": "追看人数", + "v": "3" + }, + + { + "n": "开播时间", + "v": "5" + }, + { + "n": "上映时间", + "v": "6" + }, + + ] + }, + { + "key": "season_status", + "name": "付费", + "value": [ + { + "n": "全部", + "v": "-1" + }, + { + "n": "免费", + "v": "1" + }, + + { + "n": "付费", + "v": "2%2C6" + }, + + { + "n": "大会员", + "v": "4%2C6" + }, + + ] + }, + ], + + + "时间表": [{ + "key": "tid", + "name": "分类", + "value": [ + + { + "n": "番剧", + "v": "1" + }, + + { + "n": "国创", + "v": "4" + }, + + ] + }, + ], + } + } + + + 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' + } + + def localProxy(self, param): + return [200, "video/MP2T", action, ""] diff --git a/txt/py/py_bilizb.py b/txt/py/py_bilizb.py index 44b73fc..7da84e4 100644 --- a/txt/py/py_bilizb.py +++ b/txt/py/py_bilizb.py @@ -11,7 +11,9 @@ import time import base64 -class Spider(Spider): # 元类 默认的元类 type +class Spider(Spider): + def getDependence(self): + return ['py_bilibili'] def getName(self): return "哔哩直播" @@ -49,31 +51,11 @@ class Spider(Spider): # 元类 默认的元类 type userid = '' def getCookie(self): - # --------↓↓↓↓↓↓↓------在下方cookies_str后的双引号内填写-------↓↓↓↓↓↓↓-------- - cookies_str = "" - if cookies_str: - cookies = dict([co.strip().split('=', 1) for co in cookies_str.split(';')]) - bili_jct = cookies['bili_jct'] - SESSDATA = cookies['SESSDATA'] - DedeUserID = cookies['DedeUserID'] - - cookies_jar = {"bili_jct": bili_jct, - 'SESSDATA': SESSDATA, - 'DedeUserID': DedeUserID - } - rsp = session() - rsp.cookies = cookies_jar - content = self.fetch("https://api.bilibili.com/x/web-interface/nav", cookies=rsp.cookies) - res = json.loads(content.text) - if res["code"] == 0: - self.cookies = rsp.cookies - self.userid = res["data"].get('mid') - return rsp.cookies - rsp = self.fetch("https://www.bilibili.com/") - self.cookies = rsp.cookies - return rsp.cookies + self.cookies = self.bilibili.getCookie() + return self.cookies def init(self, extend=""): + self.bilibili = extend[0] print("============{0}============".format(extend)) pass @@ -96,7 +78,6 @@ class Spider(Spider): # 元类 默认的元类 type p = str(num) return p - # 获取主播用户名 uname = '' def get_live_userInfo(self, uid): -- GitLab