Skip to content

Commit

Permalink
Merge branch 'release/1.0.15' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
RayWangQvQ committed Dec 7, 2020
2 parents a9cd3f0 + b8eb4a1 commit d23e87e
Show file tree
Hide file tree
Showing 30 changed files with 587 additions and 135 deletions.
15 changes: 15 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# .dockerignore

.git
.gitattributes
.gitignore
.github

.editorconfig

README.md

Dockerfile

[b|B]in
[O|o]bj
5 changes: 2 additions & 3 deletions .github/workflows/bilibili-daily-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: bilibili-daily-task

on:

push: # push触发
branches: [ main ]
workflow_dispatch: # 手动触发
schedule: # 计划任务触发
- cron: '5 15 * * *'
Expand Down Expand Up @@ -65,5 +63,6 @@ jobs:
Ray_DailyTaskConfig:DayOfReceiveVipPrivilege: ${{secrets.DAYOFRECEIVEVIPPRIVILEGE}}
Ray_DailyTaskConfig:DevicePlatform: ${{secrets.DEVICEPLATFORM}}
Ray_Serilog:WriteTo:0:Args:restrictedToMinimumLevel: ${{secrets.CONSOLELOGLEVEL}}
Ray_Serilog:WriteTo:0:Args:outputTemplate: ${{secrets.CONSOLELOGTEMPLATE}}
Ray_Serilog:WriteTo:0:Args:outputTemplate: ${{secrets.CONSOLELOGTEMPLATE}}
ASPNETCORE_ENVIRONMENT: ${{secrets.ENV}} # 方便切换不同的appsettings文件 也可以在不同的action yml文件中配置来同时运行多个任务
run: dotnet run -p ./src/Ray.BiliBiliTool.Console -closeConsoleWhenEnd=1 ${{secrets.OTHERCONFIGS}}
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Dockerfile
## build
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
WORKDIR ./

COPY . .

RUN dotnet restore
RUN dotnet build --configuration Release --no-restore -o out


## runtime
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /bilibili

# install cron and nano
RUN apt update && apt-get install -y\
cron \
nano \
&& rm -rf /var/lib/apt/lists/*

# make mount point
RUN mkdir /bilibili/config

# copy files from build
COPY --from=build-env ./out .

# copy scripts
COPY ./docker/entry.sh ./docker/job.sh ./docker/template.json /bilibili/

# setup cron
COPY ./docker/crontab /etc/cron.d/bilicron
RUN chmod 0644 /etc/cron.d/bilicron \
&& crontab /etc/cron.d/bilicron \
&& touch /var/log/cron.log


VOLUME ["/bilibili/config"]
ENTRYPOINT ["/bin/bash", "-c", "/bilibili/entry.sh"]
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,17 @@ _如果是发现 bug,可以提交 issue,我会尽快确认并解决。(如

Ⅰ. **下载应用文件**

点击 [BiliBiliTool/release](https://github.com/RayWangQvQ/BiliBiliTool/releases),下载已发布的最新版本
点击 [BiliBiliTool/release](https://github.com/RayWangQvQ/BiliBiliTool/releases),下载已发布的最新版本

本地如果已经安装了 DotNet 5 的环境,推荐下载 net-dependent.zip 文件,因为依赖了本地库(runtime-dependent),所以文件包很小;
应用需要的运行环境包括`ASP.NET Core Runtime 5.0.0``.NET Runtime 5.0.0`

没有环境或不确定有没有的,可以根据操作系统下载对应的 zip 文件(window 是 win-x86-x64.zip),因为是自包含的(self-contained),文件会大些(Github 服务器在国外,下载可能比较慢),但是好处是不需要额外安装 NetCore 的运行时或 SDK。
对于不希望安装或不知如何安装运行环境的用户,应当选择根据操作系统下载对应的 zip 文件(x64 Windows 对应 win-x86-x64.zip);此文件已自包含(self-contained)运行环境,但相较不包含运行时的文件略大(Github 服务器在国外,下载可能比较慢)。

对于本地已安装所需运行环境及希望使用共享运行环境以便同时使用其他 .NET 5.0 应用者,推荐下载 net-dependent.zip 文件;本文件依赖本地运行库(runtime-dependent),所以文件包很小。

若需手动安装运行环境,请点击 ![Download .NET 5.0 (Linux, macOS, and Windows)](https://dotnet.microsoft.com/download/dotnet/5.0),分别选择相应平台的`ASP.NET Core Runtime 5.0.0``.NET Runtime 5.0.0`的安装包(Installers)进行安装;亦可下载.NET SDK 5.0.100的安装包(上述二者已包含于其中)。

注:若已从 ![.NET官网下载入口](https://dotnet.microsoft.com/download) 的“Download .NET Runtime”选项进行了下载安装,则仍需根据上述方法补充安装`ASP.NET Core Runtime 5.0.0`(由于该选项仅提供了`.NET Runtime 5.0.0`的安装包)。

Ⅱ. **解压并填写配置**

Expand All @@ -138,6 +144,8 @@ _如果是发现 bug,可以提交 issue,我会尽快确认并解决。(如

![运行图示](https://cdn.jsdelivr.net/gh/RayWangQvQ/BiliBiliTool.Docs@main/imgs/run-exe.png)

对于使用 net-dependent 用户的运行方式为,在终端中执行:`dotnet Ray.BiliBiliTool.Console.dll`

_P.S.如果自己有服务器,也可以将程序发布到自己的服务器,利用自己的任务系统实现每天自动运行。(有服务器的大佬应该就不需要我多 BB 了)_

## 2.个性化自定义配置
Expand Down
40 changes: 40 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Docker 使用说明

### 1

在有Dockerfile的目录运行

`docker build -t TARGET_NAME .`

`TARGET_NAME`为镜像名称和版本 自己起个名字

### 2

完成后

`docker run -d IMAGE_NAME -v PATH_TO_CONFIGS:/bilibili/config`

`IMAGE_NAME`为刚才镜像的名字

`PATH_TO_CONFIGS`为任意目录

Window系统推荐使用Docker gui

* 如果目录中含有.json后缀的文件则会以该文件运行BilibiliTool
* 可以放置多个.json文件来实现多账号
* 如果目录为空则会生成一个模板文件方便配置
* 也可以使用`docker volume` 如果没有映射目录则自动生成volume
* 默认每天15点自动运行一次,每次容器启动也会运行一次
* 更改运行时间/频率用`docker exec -it CONTAINER_NAME crontab -e` 默认编辑器是nano

### 3

运行`docker logs CONTAINER_NAME` 查看运行记录

##

构建环境: mcr.microsoft.com/dotnet/sdk:5.0

运行环境: mcr.microsoft.com/dotnet/aspnet:5.0

大概不支持arm
1 change: 1 addition & 0 deletions docker/crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 15 * * *root /bin/bash /bilibili/job.sh >> /var/log/cron.log
16 changes: 16 additions & 0 deletions docker/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
#https://stackoverflow.com/questions/3856747/check-whether-a-certain-file-type-extension-exists-in-directory

# if no configs are found, copy the template to configs directory
configs=(`find /bilibili/config -maxdepth 1 -name "*.json"`)
if [ ${#configs[@]} -eq 0 ]; then
cp /bilibili/template.json /bilibili/config
fi

echo Starting first run
/bin/bash /bilibili/job.sh

echo By default, Bilibilitool will run at 15:00 every day for each config file
echo To configure scheduling, run \'docker exec -it CONTAINER_NAME crontab -e\' and edit

cron && tail -f /var/log/cron.log
15 changes: 15 additions & 0 deletions docker/job.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
configs=(`find /bilibili/config -maxdepth 1 -name "*.json"`)
if [ ${#configs[@]} -gt 0 ]; then
for ((idx=0; idx<${#configs[@]}; ++idx))
do
:
echo Copying config file $idx
cp ${configs[idx]} /bilibili/appsettings.json
/bilibili/Ray.BiliBiliTool.Console -closeConsoleWhenEnd=1
echo Execution finished
done
else
echo No config files found in /bilibili/config
exit 0
fi
54 changes: 54 additions & 0 deletions docker/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
//Cookie信息,取自浏览器,必填,优先级低于命令行中的配置值
"BiliBiliCookie": {
"UserId": "", //请填入你的DEDEUSERID(重要!!!)
"SessData": "", //请填入你的SESSDATA(重要!!!)
"BiliJct": "" //请填入你的BILI_JCT(重要!!!)
},

//程序自定义个性化配置
"DailyTaskConfig": {
"NumberOfCoins": 5, //每日设定的投币数 [0,5]
"SelectLike": false, //投币时是否同时点赞[false,true]
"SupportUpIds": "", //优先选择支持的up主Id集合,多个以英文逗号分隔,如:"123,456"。配置后会优先从指定的up主下挑选视频进行观看、分享和投币,不配置则从排行耪随机获取支持视频
"DayOfAutoCharge": -1, //每月几号自动充电的[-1,31],-1表示不指定,默认月底最后一天;0表示不充电
"DayOfReceiveVipPrivilege": 1, //每月几号自动领取会员权益的[-1,31],-1表示不指定,默认每月1号;0表示不自动领取
"DevicePlatform": "ios" //执行客户端操作时的平台 [ios,android]
},

//安全相关配置
"Security": {
"IntervalSecondsBetweenRequestApi": 3, //两次调用api之间间隔的秒数[0,+]。因为有人担心在几秒内连续调用api会被b站安全机制发现,所以为不放心的朋友添加了间隔秒数配置,两次连续调用Api之间会大于该秒数
"IntervalMethodTypes": "POST" //间隔秒数所针对的HttpMethod,多个用英文逗号隔开,当前有GET和POST两种,可配置如“GET,POST”。服务器一般对GET请求不是很敏感,建议只针对POST请求做间隔就可以了
},

//微信推送
"Push": {
"PushScKey": "" //请填入你的Server酱微信推送的SCKEY(http://sc.ftqq.com/3.version)
},

//日志
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Debug", "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning",
"Microsoft.AspNetCore": "Warning"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": { "restrictedToMinimumLevel": "Information" }
},
{ "Name": "Debug" },
{
"Name": "File",
"Args": { "path": "Logs/log.txt" }
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using System.Collections.Generic;
using System.Text;
using MethodBoundaryAspect.Fody.Attributes;
using Microsoft.Extensions.Logging;
using Ray.BiliBiliTool.Agent.ServerChanAgent;
using Serilog;
using Ray.BiliBiliTool.Infrastructure;

namespace Ray.BiliBiliTool.Application.Attributes
{
Expand All @@ -21,34 +22,35 @@ public TaskInterceptorAttribute(string taskName = null, bool rethrowWhenExceptio
_taskName = taskName;
_rethrowWhenException = rethrowWhenException;

_logger = Log.Logger;//todo:暂时没想到从容器注入ILogger的方法,这里直接用了Serilog的静态Log
// _logger = Log.Logger;
_logger = RayContainer.GetLogger<TaskInterceptorAttribute>();
}

public override void OnEntry(MethodExecutionArgs arg)
{
if (_taskName == null) return;

PushService.PushStringWriter.WriteLine("#### >\r\n");
_logger.Information("---开始【{taskName}】---", _taskName);
_logger.LogInformation("---开始【{taskName}】---", _taskName);
}

public override void OnExit(MethodExecutionArgs arg)
{
if (_taskName == null) return;

_logger.Information("---结束---\r\n", _taskName);
_logger.LogInformation("---结束---\r\n", _taskName);
}

public override void OnException(MethodExecutionArgs arg)
{
if (_rethrowWhenException)
{
_logger.Fatal("程序发生异常:{msg}", arg.Exception.Message);
_logger.LogError("程序发生异常:{msg}", arg.Exception.Message);
base.OnException(arg);
return;
}

_logger.Fatal("{task}失败,继续其他任务。Msg:{msg}\r\n", _taskName, arg.Exception.Message);
_logger.LogError("{task}失败,继续其他任务。失败信息:{msg}\r\n", _taskName, arg.Exception.Message);
arg.FlowBehavior = FlowBehavior.Continue;
}
}
Expand Down
Loading

0 comments on commit d23e87e

Please sign in to comment.