Code Monkey home page Code Monkey logo

bilibili-raffle-js's Introduction

bilibili-raffle-js (b站直播挂机、高能+舰长抽取)

Github license Github nodejs

Info

  • 此程序不收集任何用户信息/数据
  • 可自建服务器bilibili-live-monitor-ts, 也可以用默认的设定
  • 包括bilibili-live-monitor-ts在内的所有项目永久开源 没有闭源的打算 亦不接受打赏
  • 实力不济没能写出更多功能 代码也非常难看23333
  • 有bug请务必反馈 Issues就是用来讨论的
  • 祝各位白嫖愉快~

Features

  • 主站观看视频 (mainwatchvideo)
  • 主站分享视频 (mainsharevideo) 仅模拟 不会真实分享
  • 直播签到 (livesign)
  • 直播心跳 (liveheart)
  • 直播抽奖 (guard, gift, pk)
  • 双端观看 (doublewatch)
  • 银瓜子领取 (silverbox)
  • 友爱社签到 (idolclubsign)

Usage (普通运行)

  1. src/client/default-user-info.json 填写用户名/密码 (这个版本用到了app端的access_tokens,所以不能只提供cookies)
  2. npm install 安装依赖库
  3. node src/main.js 运行
  4. 程序自带抽奖休眠(见任务设置) 可以用pm2永久运行程序

pm2运行

  1. npm install 安装依赖库
  2. npm install -g pm2 全局安装PM2
  3. pm2 start src/main.js 运行程序
  4. pm2 ls 查看运行状态 名为main那个就是了 (如果状态是errored 用下一步看下日志 反馈issues)
  5. pm2 logs main --lines 100 查看100行日志 (CTRL-C 退出日志状态)
  6. pm2 stop main; pm2 delete main 停止+删除程序进程

Config

监听server与http任务管理设置

  • Config file /src/settings.json
  • httpServer为账号/任务管理界面设定 (未实现 我太菜了)
  • wsServer为舰长+抽奖服务器设定,支持多服务器,每个服务器可单独设置可选参数,例如下示的备用服务器设置可以用不同颜色显示,并且只显示连接和断线信息
  • receiver为抽奖监听设定
  • notifier为定时任务通知设定
  • account为一些账号任务运行杂项设置,包括每秒最大请求数,已进入房间追踪数组最大长度,在访问被拒绝的情况下小黑屋检查间隔时间(单位为小时)
{
    "httpServer": {
        "host": "127.0.0.1",
        "port": 8899
    },
    "wsServer": [
        {
            "host": "warpgate.cat.pdx.edu",        // 如果自建服务器的话请务必换成自己的ip 本机的话是127.0.0.1
            "port": 8999
        },
        {
            "host": "127.0.0.1",
            "port": 8999,
            "retries": 1,                          // 【可选设置】断线后短时间内重试次数。如果短时间内重试失败会等待一段时间后尝试重新连接。默认值为3
            "reconnectWaitTime": 60,               // 【可选设置】断线后重新连接等待时长(单位为秒)。默认值为10秒
            "healthCheckInterval": 10,             // 【可选设置】断线检测间隔(单位为秒)。默认值为5秒
            "healthCheckThreshold": 30,            // 【可选设置】断线检测阈值,从最后一次接收到ping请求算起(单位为秒)。默认值为25秒
            "enableConnectionErrorLogging": false, // 【可选设置】是否显示连接错误信息(如果备用服务器不是一直在线的话建议关闭)。默认值为true
            "enableConnectionRetryLogging": false, // 【可选设置】是否显示连接重试信息(如果备用服务器不是一直在线的话建议关闭)。默认值为true
            "infoColor": "white",                  // 【可选设置】普通连接信息显示颜色。默认值为green(绿色)
            "errorColor": "yellow"                 // 【可选设置】连接错误信息显示颜色。默认值为red(红色)
        }
    ],
    "storm": {
        "rate": 0.6                                // 风暴参与几率 (0.6 == 60%)
    },
    "receiver": {
        "janitorInterval": 1,                      // 【可选设置】已参与抽奖的礼物ID缓存清理间隔(单位为分)。默认值为1分钟
        "expiryThreshold": 5                       // 【可选设置】已参与抽奖的礼物ID在缓存内过期后的存留时长(单位为分)。默认值为5分钟
    },
    "notifier": {
        "heartbeatInterval": 5,                    // 【可选设置】双端直播心跳发送间隔(单位为分)。默认值为5分钟
        "midnightCheckInterval": 60                // 【可选设置】午夜判定检测间隔(单位为分)。默认值为60分钟。如果担心银瓜子最后领取时间(正常3轮54分钟,老爷5轮90分钟)超过心跳任务设置的时间太多(默认工作日0:45,周末2:00),可将本设置缩短,例如设为5分钟
    },
    "account": {
        "maxRequestsPerSecond": 50,                // 【可选设置】每秒最大请求数。默认值为50。设置过大容易造成412风控IP
        "maxNumRoomEntered": 30,                   // 【可选设置】已进入房间追踪数组最大长度。默认值为30。已在数组内的房间再次抽奖时不再发送进入信息。可以简单理解为同时打开n个房间的直播页面
        "blacklistCheckInterval": 24,              // 【可选设置】在访问被拒绝的情况下小黑屋检查间隔时间(单位为小时)。默认值为24小时。在检测到拒绝访问后不再参与抽奖和领取银瓜子,并且会依此设置等待一段时间后再次检测
        "stormJoinMaxInterval": 60,                // 【可选设置】节奏风暴领取请求最大间隔(单位为毫秒)。节奏风暴领取时会以快速多重请求方式发送,一般情况下在前一个请求执行完毕后才会发送下一个请求,但在网络延迟大的情况下会以不超过此设置的间隔发送。默认值为60毫秒
        "abandonStormAfter": 25                    // 【可选设置】如果节奏风暴在设定的时间段内未能成功领取,则放弃重试(单位为秒)。默认值为25秒
    }
}

账号设置

  • Config file /src/client/default-user-info.json
  • 填入账号信息并成功登录后,程序自动以相同的格式写入 src/client/user.json,此后都从src/client/user.json读取账号和登录信息
  • 与Python版的区别:JS实现包括但不限于主站任务、双端观看功能,因此app的两项也必须填上 (仅填cookies不执行任何任务)
{
    "user": {
        "username": "",
        "password": ""
    },
    "app": {
        "access_token": "",
        "refresh_token": ""
    },
    "web": {
        "bili_jct": "",
        "DedeUserID": "",
        "DedeUserID__ckMd5": "",
        "sid": "",
        "SESSDATA": ""
    }
}

任务设置

  • Config file /src/client/default-task-settings.json
  • "taskschedules" 定义任务执行时间段,可以定义多个不同的时间段并给予不同的名字
  • "tasks" 定义任务。每个任务 "enabled": true 为开启, false 为关闭。
  • 任务的 "schedule" 可以引用一个在 "taskschedules" 里定义的时间段(必须存在)
  • 默认所有任务开启,所有抽奖、心跳任务于北京时间工作日 08:00 - 0:45 ,周末 09:00 - 02:00 时间段执行
  • 修改from、to的hours、minutes数值可以自定义抽奖时间段
  • weekdays允许值为0-6,对应星期日,一到六。可用逗号分隔,且可以用连接号定义区间,比如0-2,4,6代表周日到周二,加周四和周六
  • 还请不要修改type ~
{
    "taskschedules": {
        "normal": [
            {
                "from": {
                    "hours": 8,
                    "minutes": 0
                },
                "to": {
                    "hours": 0,
                    "minutes": 45
                },
                "weekdays": "1-4"
            },
            {
                "from": {
                    "hours": 8,
                    "minutes": 0
                },
                "to": {
                    "hours": 2,
                    "minutes": 0
                },
                "weekdays": "5"
            },
            {
                "from": {
                    "hours": 9,
                    "minutes": 0
                },
                "to": {
                    "hours": 2,
                    "minutes": 0
                },
                "weekdays": "6"
            },
            {
                "from": {
                    "hours": 9,
                    "minutes": 0
                },
                "to": {
                    "hours": 0,
                    "minutes": 45
                },
                "weekdays": "0"
            }
        ],
        "always": [
            {
                "from": {
                    "hours": 0,
                    "minutes": 0
                },
                "to": {
                    "hours": 0,
                    "minutes": 0
                },
                "weekdays": "0-6"
            }
        ]
    },
    "tasks": {
        "pk": {
            "type": "scheduled",
            "enabled": true,
            "schedule": "normal"
        },
        "gift": {
            "type": "scheduled",
            "enabled": true,
            "schedule": "normal"
        },
        "guard": {
            "type": "scheduled",
            "enabled": true,
            "schedule": "normal"
        },
        "storm": {
            "type": "scheduled",
            "enabled": true,
            "schedule": "normal"
        },
        "liveheart": {
            "type": "scheduled",
            "enabled": true,
            "schedule": "normal"
        },
        "livesign": {
            "type": "daily",
            "enabled": true
        },
        "idolclubsign": {
            "type": "daily",
            "enabled": true
        },
        "mainsharevideo": {
            "type": "daily",
            "enabled": true
        },
        "mainwatchvideo": {
            "type": "daily",
            "enabled": true
        },
        "silverbox": {
            "type": "daily",
            "enabled": true
        },
        "doublewatch": {
            "type": "daily",
            "enabled": true
        }
    }
}

Issues

有Bug请务必立刻反馈 (有使用方式的疑问或者任何功能方面的建议 也欢迎讨论)
炸我邮箱[email protected]

bilibili-raffle-js's People

Contributors

blu3mania avatar billyzou0741326 avatar

Stargazers

 avatar JimiTiao avatar Yuyue Zhang avatar  avatar are you hungry avatar AmazingFatter avatar 結花 avatar ous50 | ousfifty | 欧式fifty avatar Cloud avatar NorthCity1984 avatar  avatar ANON avatar  avatar Nasir Ali avatar drive in kindergarten avatar 雨辰 avatar  avatar  avatar Lin avatar Elf avatar Jinxi Li avatar zhihaofans avatar 花生瓜子大杏仁 avatar 笑靥如花 avatar superqun avatar MoeCG avatar MoeHero avatar  avatar  avatar 一般通过吃瓜群众 avatar  avatar Sui酱今天也很小 avatar Vincente avatar Sanker avatar molehzy avatar  avatar  avatar  avatar Yuban10703 avatar  avatar Zhang Minghao avatar 神楽坂白泠 avatar  avatar Vc2333 avatar 胡敏 avatar Sin avatar Siubeng avatar 远哥制造 avatar Fei Ju avatar LiangXiang Shen avatar Mouse avatar  avatar Usagi Ryu avatar 853 avatar Callery avatar 是甜食哇 avatar  avatar miku avatar seeYou avatar  avatar Rikka avatar

Watchers

James Cloos avatar Rikka avatar wangergou avatar

bilibili-raffle-js's Issues

登录出问题了

TypeError: Cannot read property 'cookies' of undefined
会显示这个

监控挂了吗

14:44之前还是正常的,之后就没有一点儿动静了,无论怎么重开脚本,都只有
[ Server ] Established connection with ws://bili.minamiktr.com/ws
这样一条成功连接的提示,之后就没有任何动静了

风暴全错过

风暴全错过,尝试时间设在90秒,其他参数全为默认,一个上午一个都没中,全是尝试时间超过90秒放弃。昨天还是一切正常的,不清楚是我账户问题还是网络问题还是bilibili又改了什么东西

cmd error

pm2命令格式有误,应为 pm2 start src/main.js

Clock is not using Beijing Time

Clock class is using local time instead of converting to Beijing Time. Also Notifier is not using Clock class. Proposed changes:

diff --git a/src/client/notifier.js b/src/client/notifier.js
index 32b9b49..945d721 100644
--- a/src/client/notifier.js
+++ b/src/client/notifier.js
@@ -2,6 +2,7 @@
 
     'use strict';
 
+    const Clock = require('./tasks/clock.js');
     const EventEmitter = require('events').EventEmitter;
 
     class Notifier extends EventEmitter {
@@ -13,7 +14,7 @@
                 'liveHeart': null,
                 'midnight': null,
             };
-            this.day = new Date().getDay();
+            this.day = new Clock().getDay();
         }
 
         run() {
@@ -24,7 +25,7 @@
             }
             if (this.tasks['midnight'] === null) {
                 this.tasks['midnight'] = setInterval(() => {
-                    const day = new Date().getDay();
+                    const day = new Clock().getDay();
                     if (this.day !== day) {
                         this.emit('midnight');
                         this.day = day;

diff --git a/src/client/tasks/clock.js b/src/client/tasks/clock.js
index 4ba92c0..4438d8d 100644
--- a/src/client/tasks/clock.js
+++ b/src/client/tasks/clock.js
@@ -14,7 +14,9 @@
         }
 
         constructor(...args) {
-            super(...args);
+            // Convert date to Beijing Time
+            const chinaTime = new Date(...args).toLocaleString("en-US", {timeZone: "Asia/Shanghai"});
+            super(chinaTime);
         }
 
     }

b站好像有了新的封禁措施

最近莫名其妙主站不能评论发弹幕,点赞收藏都不行,显示账号封禁,但是可以投币,直播也没任何问题。找客服解封以后说账号风险过高,改了密码重新挂上程序又被封了,现在很郁闷。

Enhancement: Storm with "Parallel" Async for slower internet

求建议2333

// client/account-runner.js
joinStorm(storm): void {
    const start = new Date().valueOf();
    const interval = 60;              // 60 ms per `join` request, if internet is slower than that
    const tasks = [];                 // An array of `join` promises
    let quitAfter = 25000;            // 25 seconds later, if not successful, quit.
    let quit = false;
    let i = 0;
    let message = '';
    let color = colors.green;

    const join = async () => {
        while (!quit) {
            const t = Bilibili.appJoinStorm(this.session, storm);
            tasks.push(t);
            ++i;
            await Promise.race( [ t.catch(), sleep(interval) ] );       // whichever is done first, 60 ms or `join` request
        }
    };
    const isDone = (resp): boolean => {
        const msg = resp['msg'] || resp['message'] || '';
        let good = false;
        if (resp['code'] === 0) {
            const giftName = resp['data']['gift_name'];
            const giftNum = resp['data']['gift_num'];
            const awardText = `${giftName}+${giftNum}`;
            message = awardText;
            good = true;
        }
        else if (msg.includes('已经领取')) {
            message = '亿圆已领取';
            good = true;
        }
        return good;
    };
    const setQuitFlag = async () => {
        try {
            while (!quit) {
                const results = await Promise.all(tasks);
                quit = quit || results.some(response => isDone(response));
                quit = quit || (new Date().valueOf() - start > quitAfter);
                message = message || `风暴 ${storm.id} 领取失败`;
            }
        }
        catch (error) {
            quit = true;
            message = `(Storm) - ${error}`;
            color = colors.red;
        }
    };

    const execute = async () => {
        await Promise.all( [ join(), setQuitFlag() ] );
        cprint(message, color);
        cprint(`Executed ${i} times`, colors.green);
    };

    execute();
}

频繁出现Http request errored

 [2020-02-26 11:39:28]   
 Error: Http request errored
    at ClientRequest.xhr.request.on.on.on (/data/bilibili-raffle-js/src/net/xhr.js:38:51)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at Socket.socketErrorListener (_http_client.js:401:9)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:66:8)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickCallback (internal/process/next_tick.js:181:9)

最近经常这样报错。
另外可能会出现卡在重连这里没触发任何事件。

 [2020-02-25 23:43:41]   2097142034574   @5148           storm           节奏风暴
 [2020-02-25 23:44:25]   [ Server ] Trying to reconnect to ws://bili.minamiktr.com/ws:8999 ...
 [2020-02-26 00:00:09]   视频观看成功
 [2020-02-26 00:00:09]   双端观看未完成

百分百错过节奏风暴

前段时间还好好的,可是不知道为什么从今天起百分百出现:风暴 2156415873195 已经超过25秒,放弃领取

无法登录

无法登录,
红条提示: TypeError: Cannot read property 'cookies' of undefined

Info:412风控可能性

请求限制放得很宽 (1秒50个)
所以 http response status 412 的概率还是有的
即便如此也比不限制、Python版的1秒15个好很多了

Python版的请求限制会导致高峰期漏掉数千辣条
无请求限制版会412风控ip大概一个小时

折中了一下就1秒50吧 就算3000连也是领得完的

登录信息过期后无法重新登录

image
这之后就一直获取失败

然后重启程序也无法重新登录
image

应该是cookie满一个月过期了,手动删了user.json,可以正常登录,自动重新生成user.json。

新年快乐!

client端设计问题

TS implementation overview

任务全放进account里有些难看了 这里分类出来各自形成class

raffle-handler/

  • storm.ts
  • smalltv.ts
  • pk.ts
  • guard.ts
  • ? anchor.ts ?

live-daily.ts

  • live-sign
  • heartbeat
  • silverbox
  • fan-group-sign
  • ? exchange-coin ?
  • ? send-gift ?

main-daily.ts

  • watch-video
  • share-video
  • ? send-coin ?
  • ? judge-case ?

Schedule Format

每个任务都要改一遍时间太麻烦了 直接上模板 简略休眠复杂度(精确到小时而非分钟)

task-config.json

{
    "task-schedule-1": {
        "tv_pk_guard": {
            "on": true,
            "sleep": [1,2,3,4,5,6]
        },
        "storm": {
            "on": true,
            "sleep": [1,2,3,4,5,6]
        }
    }
}

user-config.json

{
    "username": "",
    "password": "",
    "sleep-schedule": "task-schedule-1"
}

结果不想写了233333

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.