添加 bilibili 每日任务

This commit is contained in:
shitao 2020-12-21 21:08:22 +08:00
parent ed1168a26d
commit e901a5d6aa
16 changed files with 402 additions and 8 deletions

View File

@ -47,6 +47,7 @@ jobs:
FMAPP_ACCOUNT_LIST: ${{secrets.FMAPP_ACCOUNT_LIST}}
BAIDU_URL_SUBMIT_LIST: ${{secrets.BAIDU_URL_SUBMIT_LIST}}
TIEBA_COOKIE_LIST: ${{secrets.TIEBA_COOKIE_LIST}}
BILIBILI_COOKIE_LIST: ${{secrets.BILIBILI_COOKIE_LIST}}
- name: "部署到腾讯云函数"
run: sls deploy --debug

View File

@ -44,3 +44,4 @@ jobs:
FMAPP_ACCOUNT_LIST: ${{secrets.FMAPP_ACCOUNT_LIST}}
BAIDU_URL_SUBMIT_LIST: ${{secrets.BAIDU_URL_SUBMIT_LIST}}
TIEBA_COOKIE_LIST: ${{secrets.TIEBA_COOKIE_LIST}}
BILIBILI_COOKIE_LIST: ${{secrets.BILIBILI_COOKIE_LIST}}

View File

@ -40,6 +40,7 @@
12. 企鹅读书: 每日金币获取
13. Fa米家 APP: 连续签到7天总计获得6粒Fa米粒每月15号23.59分清空Fa米粒。理论一个月最少获得24粒fa米粒。
14. 百度贴吧: 贴吧每日签到
14. BILIBILI 每日签到: 直播签到,漫画签到,每日经验任务,自动投币,银瓜子换硬币等功能
## 支持的通知列表

2
bilibili/__init__.py Normal file
View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from bilibili.bilibili import BiliBiliCheckIn

331
bilibili/bilibili.py Normal file
View File

@ -0,0 +1,331 @@
# -*- coding: utf-8 -*-
import json
import os
import requests
class BiliBiliCheckIn(object):
# 待测试,需要大会员账号测试领取福利
def __init__(self, bilibili_cookie_list):
self.bilibili_cookie_list = bilibili_cookie_list
@staticmethod
def get_nav(session):
url = "https://api.bilibili.com/x/web-interface/nav"
ret = session.get(url).json()
print(ret)
uname = ret.get("data", {}).get("uname")
uid = ret.get("data", {}).get("mid")
is_login = ret.get("data", {}).get("isLogin")
coin = ret.get("data", {}).get("money")
vip_type = ret.get("data", {}).get("vipType")
current_exp = ret.get("data", {}).get("level_info", {}).get("current_exp")
return uname, uid, is_login, coin, vip_type, current_exp
@staticmethod
def reward(session) -> dict:
"""取B站经验信息"""
url = "https://account.bilibili.com/home/reward"
ret = session.get(url).json()
return ret
@staticmethod
def live_sign(session) -> dict:
"""B站直播签到"""
try:
url = "https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign"
ret = session.get(url).json()
if ret["code"] == 0:
msg = f'签到成功,信息:{ret["data"]["text"]},特别信息:{ret["data"]["specialText"]},本月已签到{ret["data"]["hadSignDays"]}'
elif ret["code"] == 1011040:
msg = "今日已签到过,无法重复签到"
else:
msg = f'签到失败,信息为: {ret["message"]}'
except Exception as e:
msg = f"签到异常,原因为{str(e)}"
return msg
@staticmethod
def manga_sign(session, platform="android") -> dict:
"""
模拟B站漫画客户端签到
"""
try:
url = "https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn"
post_data = {"platform": platform}
ret = session.post(url=url, data=post_data).json()
if ret["code"] == 0:
msg = "签到成功"
elif ret["msg"] == "clockin clockin is duplicate":
msg = "今天已经签到过了"
else:
msg = f'签到失败,信息为({ret["msg"]})'
except Exception as e:
msg = f"签到异常,原因为: {str(e)}"
return msg
@staticmethod
def vip_privilege_receive(session, bili_jct, receive_type: int = 1) -> dict:
"""
领取B站大会员权益
receive_type int 权益类型1为B币劵2为优惠券
"""
url = "https://api.bilibili.com/x/vip/privilege/receive"
post_data = {"type": receive_type, "csrf": bili_jct}
ret = session.post(url, data=post_data).json()
return ret
@staticmethod
def vip_manga_reward(session) -> dict:
"""获取漫画大会员福利"""
url = "https://manga.bilibili.com/twirp/user.v1.User/GetVipReward"
ret = session.post(url, json={"reason_id": 1}).json()
return ret
@staticmethod
def report_task(session, bili_jct, aid: int, cid: int, progres: int = 300) -> dict:
"""
B站上报视频观看进度
aid int 视频av号
cid int 视频cid号
progres int 观看秒数
"""
url = "http://api.bilibili.com/x/v2/history/report"
post_data = {"aid": aid, "cid": cid, "progres": progres, "csrf": bili_jct}
ret = session.post(url=url, data=post_data).json()
return ret
@staticmethod
def share_task(session, bili_jct, aid) -> dict:
"""
分享指定av号视频
aid int 视频av号
"""
url = "https://api.bilibili.com/x/web-interface/share/add"
post_data = {"aid": aid, "csrf": bili_jct}
ret = session.post(url, data=post_data).json()
return ret
@staticmethod
def get_followings(
session, uid: int, pn: int = 1, ps: int = 50, order: str = "desc", order_type: str = "attention"
) -> dict:
"""
获取指定用户关注的up主
uid int 账户uid默认为本账户非登录账户只能获取20个*5
pn int 页码默认第一页
ps int 每页数量默认50
order str 排序方式默认desc
order_type 排序类型默认attention
"""
url = f"https://api.bilibili.com/x/relation/followings?vmid={uid}&pn={pn}&ps={ps}&order={order}&order_type={order_type}"
ret = session.get(url).json()
return ret
@staticmethod
def space_arc_search(
session, uid: int, pn: int = 1, ps: int = 100, tid: int = 0, order: str = "pubdate", keyword: str = ""
) -> dict:
"""
获取指定up主空间视频投稿信息
uid int 账户uid默认为本账户
pn int 页码默认第一页
ps int 每页数量默认50
tid int 分区 默认为0(所有分区)
order str 排序方式默认pubdate
keyword str 关键字默认为空
"""
url = f"https://api.bilibili.com/x/space/arc/search?mid={uid}&pn={pn}&ps={ps}&tid={tid}&order={order}&keyword={keyword}"
ret = session.get(url).json()
data_list = [
{
"aid": one.get("aid"),
"cid": 0,
"title": one.get("title"),
"owner": one.get("author")
}
for one in ret.get("data", {}).get("list", {}).get("vlist", [])
]
return data_list
@staticmethod
def elec_pay(session, bili_jct, uid: int, num: int = 50) -> dict:
"""
用B币给up主充电
uid int up主uid
num int 充电电池数量
"""
url = "https://api.bilibili.com/x/ugcpay/trade/elec/pay/quick"
post_data = {"elec_num": num, "up_mid": uid, "otype": "up", "oid": uid, "csrf": bili_jct}
ret = session.post(url, data=post_data).json()
return ret
@staticmethod
def coin_add(session, bili_jct, aid: int, num: int = 1, select_like: int = 1) -> dict:
"""
给指定 av 号视频投币
aid int 视频av号
num int 投币数量
select_like int 是否点赞
"""
url = "https://api.bilibili.com/x/web-interface/coin/add"
post_data = {
"aid": aid,
"multiply": num,
"select_like": select_like,
"cross_domain": "true",
"csrf": bili_jct,
}
ret = session.post(url, data=post_data).json()
return ret
@staticmethod
def live_status(session) -> dict:
"""B站直播获取金银瓜子状态"""
url = "https://api.live.bilibili.com/pay/v1/Exchange/getStatus"
ret = session.get(url).json()
data = ret.get("data")
silver = data.get("silver", 0)
gold = data.get("gold", 0)
coin = data.get("coin", 0)
msg = f"银瓜子数量: {silver}\n金瓜子数量: {gold}\n硬币数量: {coin}"
return msg
@staticmethod
def silver2coin(session, bili_jct) -> dict:
"""银瓜子兑换硬币"""
url = "https://api.live.bilibili.com/pay/v1/Exchange/silver2coin"
post_data = {"csrf_token": bili_jct}
ret = session.post(url, data=post_data).json()
return ret
@staticmethod
def get_region(session, rid=1, num=6) -> dict:
"""
获取 B站分区视频信息
rid int 分区号
num int 获取视频数量
"""
url = "https://api.bilibili.com/x/web-interface/dynamic/region?ps=" + str(num) + "&rid=" + str(rid)
ret = session.get(url).json()
data_list = [
{
"aid": one.get("aid"),
"cid": one.get("cid"),
"title": one.get("title"),
"owner": one.get("owner", {}).get("name")
} for one in ret.get("data", {}).get("archives", [])
]
return data_list
def main(self):
msg_list = []
for bilibili_info in self.bilibili_cookie_list:
bilibili_cookie = {
item.split("=")[0]: item.split("=")[1] for item in bilibili_info.get("bilibili_cookie").split("; ")
}
bili_jct = bilibili_cookie.get("bili_jct")
coin_num = bilibili_info.get("coin_num", 0)
coin_type = bilibili_info.get("coin_type", 1)
silver2coin = bilibili_info.get("silver2coin", True)
session = requests.session()
requests.utils.add_dict_to_cookiejar(session.cookies, bilibili_cookie)
session.headers.update(
{
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/63.0.3239.108",
"Referer": "https://www.bilibili.com/",
"Connection": "keep-alive",
}
)
success_count = 0
today_exp = 5
uname, uid, is_login, coin, vip_type, current_exp = self.get_nav(session=session)
# print(uname, uid, is_login, coin, vip_type, current_exp)
if is_login:
manhua_msg = self.manga_sign(session=session)
print(manhua_msg)
live_msg = self.live_sign(session=session)
print(live_msg)
aid_list = self.get_region(session=session)
reward_ret = self.reward(session=session)
coins_av_count = reward_ret.get("data", {}).get("coins_av") // 10
coin_num = coin_num - coins_av_count
coin_num = coin_num if coin_num < coin else coin
print(coin_num)
if coin_type == 1 and coin_num:
following_list = self.get_followings(session=session, uid=uid)
for following in following_list.get("data", {}).get("list"):
mid = following.get("mid")
if mid:
aid_list += self.space_arc_search(session=session, uid=mid)
if coin_num > 0:
for aid in aid_list[::-1]:
# print(f'成功给{aid.get("title")}投一个币')
# coin_num -= 1
# success_count += 1
ret = self.coin_add(session=session, aid=aid.get("aid"), bili_jct=bili_jct)
if ret["code"] == 0:
coin_num -= 1
print(f'成功给{aid.get("title")}投一个币')
success_count += 1
elif ret["code"] == 34005:
print(f'投币{aid.get("title")}失败,原因为{ret["message"]}')
continue
# -104 硬币不够了 -111 csrf 失败 34005 投币达到上限
else:
print(f'投币{aid.get("title")}失败,原因为{ret["message"]},跳过投币')
break
if coin_num <= 0:
break
today_exp += (success_count + coins_av_count) * 10
coin_msg = f"今日成功投币{success_count + coins_av_count}/{bilibili_info.get('coin_num', 5)}"
print(coin_msg)
else:
today_exp += coins_av_count * 10
coin_msg = f"今日成功投币{coins_av_count}/{bilibili_info.get('coin_num', 5)}"
print(coin_msg)
aid = aid_list[0].get("aid")
cid = aid_list[0].get("cid")
title = aid_list[0].get("title")
report_ret = self.report_task(session=session, bili_jct=bili_jct, aid=aid, cid=cid)
if report_ret.get("code") == 0:
today_exp += 5
report_msg = f"观看《{title}》300秒"
else:
report_msg = f"任务失败"
print(report_msg)
share_ret = self.share_task(session=session, bili_jct=bili_jct, aid=aid)
if share_ret.get("code") == 0:
today_exp += 5
share_msg = f"分享《{title}》成功"
else:
share_msg = f"分享失败"
print(share_msg)
if silver2coin:
silver2coin_ret = self.silver2coin(session=session, bili_jct=bili_jct)
if silver2coin_ret["code"] == 0:
silver2coin_msg = f'成功将银瓜子兑换为1个硬币'
else:
silver2coin_msg = silver2coin_ret["msg"]
print(silver2coin_msg)
else:
silver2coin_msg = f'未开启银瓜子兑换硬币功能'
live_stats = self.live_status(session=session)
uname, uid, is_login, new_coin, vip_type, new_current_exp = self.get_nav(session=session)
print(uname, uid, is_login, new_coin, vip_type, new_current_exp)
msg = f"【Bilibili签到】\n帐号信息: {uname}\n漫画签到: {manhua_msg}\n直播签到: {live_msg}\n" \
f"登陆任务: 今日已登陆\n观看视频: {report_msg}\n分享任务: {share_msg}\n投币任务: {coin_msg}\n" \
f"银瓜子兑换硬币: {silver2coin_msg}\n今日获得经验: {today_exp}\n当前经验: {new_current_exp}\n" \
f"按当前速度升级还需: {(28800 - new_current_exp) // today_exp}\n{live_stats}"
print(msg)
msg_list.append(msg)
return msg_list
if __name__ == "__main__":
with open(os.path.join(os.path.dirname(os.path.dirname(__file__)), "config.json"), "r", encoding="utf-8") as f:
datas = json.loads(f.read())
_bilibili_cookie_list = datas.get("BILIBILI_COOKIE_LIST", [])
BiliBiliCheckIn(bilibili_cookie_list=_bilibili_cookie_list).main()

View File

@ -126,7 +126,7 @@
"times": 10
}
],
"FMAPP_ACCOUNT_LIST": [
"FMAPP_ACCOUNT_LIST": [
{
"fmapp_token": "xxxxxx",
"fmapp_cookie": "xxxxxx",
@ -137,5 +137,13 @@
{
"tieba_cookie": "xxxxxx"
}
],
"BILIBILI_COOKIE_LIST": [
{
"bilibili_cookie": "xxxxxx",
"coin_num": 0,
"coin_type": 1,
"silver2coin": true
}
]
}

View File

@ -19,6 +19,7 @@ if [[ $ONEPLUSBBS_COOKIE_LIST ]]; then echo "ONEPLUSBBS_COOKIE_LIST 变量存在
if [[ $QQREAD_ACCOUNT_LIST ]]; then echo "QQREAD_ACCOUNT_LIST 变量存在,并成功赋值" ;else QQREAD_ACCOUNT_LIST=[]; fi;
if [[ $FMAPP_ACCOUNT_LIST ]]; then echo "FMAPP_ACCOUNT_LIST 变量存在,并成功赋值" ;else FMAPP_ACCOUNT_LIST=[]; fi;
if [[ $TIEBA_COOKIE_LIST ]]; then echo "TIEBA_COOKIE_LIST 变量存在,并成功赋值" ;else TIEBA_COOKIE_LIST=[]; fi;
if [[ $BILIBILI_COOKIE_LIST ]]; then echo "BILIBILI_COOKIE_LIST 变量存在,并成功赋值" ;else BILIBILI_COOKIE_LIST=[]; fi;
JSONSTR="{
@ -41,6 +42,7 @@ JSONSTR="{
\"QQREAD_ACCOUNT_LIST\": ${QQREAD_ACCOUNT_LIST},
\"FMAPP_ACCOUNT_LIST\": ${FMAPP_ACCOUNT_LIST},
\"BAIDU_URL_SUBMIT_LIST\": ${BAIDU_URL_SUBMIT_LIST},
\"BILIBILI_COOKIE_LIST\": ${BILIBILI_COOKIE_LIST},
\"TIEBA_COOKIE_LIST\": ${TIEBA_COOKIE_LIST}
}"
echo $JSONSTR > config.json

View File

@ -126,7 +126,7 @@
"times": 10
}
],
"FMAPP_ACCOUNT_LIST": [
"FMAPP_ACCOUNT_LIST": [
{
"fmapp_token": "xxxxxx",
"fmapp_cookie": "xxxxxx",
@ -137,5 +137,13 @@
{
"tieba_cookie": "xxxxxx"
}
],
"BILIBILI_COOKIE_LIST": [
{
"bilibili_cookie": "xxxxxx",
"coin_num": 0,
"coin_type": 1,
"silver2coin": true
}
]
}

View File

@ -144,6 +144,14 @@
{
"tieba_cookie": "xxxxxx"
}
],
"BILIBILI_COOKIE_LIST": [
{
"bilibili_cookie": "xxxxxx",
"coin_num": 0,
"coin_type": 1,
"silver2coin": true
}
]
}
```
@ -185,6 +193,10 @@
|_**FMAPP_ACCOUNT_LIST**_.fmapp_cookie|Fa米家|非必须|Fa米家 APP headers 中的 cookie|
|_**FMAPP_ACCOUNT_LIST**_.fmapp_device_id|Fa米家|非必须|Fa米家 APP headers 中的 deviceId|
|_**TIEBA_COOKIE_LIST**_.tieba_cookie|百度贴吧|非必须|[百度贴吧](https://tieba.baidu.com/index.html) cookie|
|_**BILIBILI_COOKIE_LIST**_.bilibili_cookie|Bilibili|非必须|[Bilibili](https://www.bilibili.com) cookie|
|_**BILIBILI_COOKIE_LIST**_.coin_num|Bilibili|非必须|[Bilibili](https://www.bilibili.com) 每日投币数量|
|_**BILIBILI_COOKIE_LIST**_.coin_type|Bilibili|非必须|[Bilibili](https://www.bilibili.com) 投币方式 默认为 0 1: 为关注用户列表视频投币 0: 为随机投币。如果关注用户发布的视频不足配置的投币数,则剩余部分使用随机投币|
|_**BILIBILI_COOKIE_LIST**_.silver2coin|Bilibili|非必须|[Bilibili](https://www.bilibili.com) 是否开启银瓜子换硬币,默认为 True 开启|
## 参数获取方法
@ -276,6 +288,10 @@
[百度贴吧](https://tieba.baidu.com/index.html)
#### Bilibili Cookie 参数获取
[Bilibili](https://www.bilibili.com)
### APP抓包
#### 喜马拉雅极速版 Cookie 参数获取

View File

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from fmapp.fmapp import FMAPPCheckIn

View File

@ -12,17 +12,19 @@ from datetime import datetime, timedelta
import requests
from baidu_url_submit import BaiduUrlSubmit
from fmapp.fmapp import FMAPPCheckIn
from bilibili import BiliBiliCheckIn
from fmapp import FMAPPCheckIn
from iqiyi import IQIYICheckIn
from kgqq import KGQQCheckIn
from motto.motto import Motto
from motto import Motto
from music163 import Music163CheckIn
from oneplusbbs.oneplusbbs import OnePlusBBSCheckIn
from oneplusbbs import OnePlusBBSCheckIn
from pojie import PojieCheckIn
from qqread.qqread import QQReadCheckIn
from qqread import QQReadCheckIn
from tieba import TiebaCheckIn
from vqq import VQQCheckIn
from weather import Weather
from xmly.xmly import XMLYCheckIn
from xmly import XMLYCheckIn
from youdao import YouDaoCheckIn
@ -110,7 +112,12 @@ def main_handler(event, context):
fmapp_account_list = (
json.loads(os.environ.get("FMAPP_ACCOUNT_LIST", [])) if os.environ.get("FMAPP_ACCOUNT_LIST") else []
)
tieba_cookie_list = (
json.loads(os.environ.get("TIEBA_COOKIE_LIST", [])) if os.environ.get("TIEBA_COOKIE_LIST") else []
)
bilibili_cookie_list = (
json.loads(os.environ.get("BILIBILI_COOKIE_LIST", [])) if os.environ.get("BILIBILI_COOKIE_LIST") else []
)
else:
if isinstance(event, dict):
@ -138,6 +145,8 @@ def main_handler(event, context):
qqread_account_list = data.get("QQREAD_ACCOUNT_LIST", [])
baidu_url_submit_list = data.get("BAIDU_URL_SUBMIT_LIST", [])
fmapp_account_list = data.get("FMAPP_ACCOUNT_LIST", [])
tieba_cookie_list = data.get("TIEBA_COOKIE_LIST", [])
bilibili_cookie_list = data.get("BILIBILI_COOKIE_LIST", [])
content_list = [f"当前时间: {utc_time}"]
if message == "xmly":
@ -185,6 +194,14 @@ def main_handler(event, context):
msg_list = FMAPPCheckIn(fmapp_account_list=fmapp_account_list).main()
content_list += msg_list
if tieba_cookie_list:
msg_list = TiebaCheckIn(tieba_cookie_list=tieba_cookie_list).main()
content_list += msg_list
if bilibili_cookie_list:
msg_list = BiliBiliCheckIn(bilibili_cookie_list=bilibili_cookie_list).main()
content_list += msg_list
if city_name_list:
msg_list = Weather(city_name_list=city_name_list).main()
content_list += msg_list

View File

@ -1 +1,2 @@
# -*- coding: utf-8 -*-
from motto.motto import Motto

View File

@ -1 +1,2 @@
# -*- coding: utf-8 -*-
from oneplusbbs.oneplusbbs import OnePlusBBSCheckIn

View File

@ -1 +1,2 @@
# -*- coding: utf-8 -*-
from qqread.qqread import QQReadCheckIn

View File

@ -1 +1,2 @@
# -*- coding: utf-8 -*-
from tieba.tieba import TiebaCheckIn

View File

@ -1 +1,2 @@
# -*- coding: utf-8 -*-
from xmly.xmly import XMLYCheckIn