commit
96700f7d03
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 241 KiB |
@ -0,0 +1,12 @@
|
||||
# 是否使用后端?
|
||||
REACT_APP_USE_BACKEND=true
|
||||
# 预设的直播间号
|
||||
REACT_APP_ROOM_ID=196
|
||||
# B站API的链接
|
||||
REACT_APP_BILIBILI_LIVE_INFO_API=https://api.live.bilibili.com/room/v1/Room/get_info_by_id?ids[]={ROOM_ID}
|
||||
# 后端端口
|
||||
REACT_APP_BACKEND_PORT=3001
|
||||
# 前端端口
|
||||
PORT=3000
|
||||
# 浏览器
|
||||
BROWSER=none
|
||||
@ -0,0 +1,26 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# Sample file
|
||||
__sample/
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 YUKARI FAN CLUB
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "bilibili-live-info",
|
||||
"version": "1.0.0",
|
||||
"author": "YUKARI FAN CLUB <admin@yukari.top> (https://yukari.top)",
|
||||
"license": "MIT",
|
||||
"repository": "github:YUKARI-FAN-CLUB/bilibili-live-info",
|
||||
"private": false,
|
||||
"dependencies": {
|
||||
"@types/node": "^16.7.13",
|
||||
"@types/react": "^18.0.0",
|
||||
"@types/react-dom": "^18.0.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"typescript": "^4.4.2"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject",
|
||||
"backend": "node src/backend/main.js",
|
||||
"build-backend": "tsc src/backend/main.ts --module 'node16'"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"sass": "^1.57.1"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 3.8 KiB |
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-hans">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="referrer" content="no-referrer"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#00A0D0" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Bilibili 直播间信息 API 演示"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<title>B站直播间信息</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>请启用 JavaScript 来打开本页面。</noscript>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 9.4 KiB |
@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "B站直播间信息",
|
||||
"name": "Bilibili 直播间信息 API 演示",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#00A0D0",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
@ -0,0 +1,116 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const http_1 = __importDefault(require("http"));
|
||||
const https_1 = __importDefault(require("https"));
|
||||
const url_1 = __importDefault(require("url"));
|
||||
const dotenv = __importStar(require("dotenv"));
|
||||
dotenv.config();
|
||||
const setRoomId = (roomId, url) => {
|
||||
return url.replace(/\{ROOM_ID\}/g, roomId.toString() ?? '196');
|
||||
};
|
||||
const getLiveInfo = async (room) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!process.env.REACT_APP_BILIBILI_LIVE_INFO_API) {
|
||||
return { message: '请先设置 Bilibili API URL' };
|
||||
}
|
||||
const url = setRoomId(room, process.env.REACT_APP_BILIBILI_LIVE_INFO_API);
|
||||
let req = https_1.default.get(url, (res) => {
|
||||
console.log(`正在请求: ${url}`);
|
||||
let data = '';
|
||||
res.on('error', (err) => {
|
||||
console.error(err);
|
||||
reject(err);
|
||||
});
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
res.on('end', () => {
|
||||
try {
|
||||
let result;
|
||||
if (res.statusCode === 200) {
|
||||
result = JSON.parse(data);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
req.on('timeout', () => {
|
||||
console.error('请求超时');
|
||||
reject();
|
||||
});
|
||||
req.on('uncaughtException', (err) => {
|
||||
console.error('错误:' + err);
|
||||
reject(err);
|
||||
});
|
||||
req.on('error', (err) => {
|
||||
console.error('错误:' + err.message);
|
||||
reject(err);
|
||||
});
|
||||
req.end();
|
||||
});
|
||||
};
|
||||
const server = http_1.default.createServer(async (req, res) => {
|
||||
if (req.headers.origin) {
|
||||
res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
|
||||
}
|
||||
else {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
res.setHeader('Access-Control-Request-Method', '*');
|
||||
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
|
||||
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET, POST, PUT');
|
||||
if (req.method === 'GET') {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
let query;
|
||||
if (req.url) {
|
||||
query = url_1.default.parse(req.url, true).query ?? undefined;
|
||||
}
|
||||
let result = await getLiveInfo(query?.room ?? '196');
|
||||
res.write(JSON.stringify(result));
|
||||
res.end();
|
||||
}
|
||||
else if (req.method === 'OPTIONS') {
|
||||
res.writeHead(200);
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
res.writeHead(404, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ message: '错误' }));
|
||||
}
|
||||
});
|
||||
(() => {
|
||||
server.listen(parseInt(process.env.REACT_APP_BACKEND_PORT ?? '3001'), () => {
|
||||
console.log(`后端服务器已启动! (HTTP 端口: ${process.env.REACT_APP_BACKEND_PORT ?? '3001'})`);
|
||||
});
|
||||
})();
|
||||
@ -0,0 +1,100 @@
|
||||
import http from 'http';
|
||||
import https from 'https';
|
||||
import url from 'url';
|
||||
import * as dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const setRoomId = (roomId: string, url: string) => {
|
||||
return url.replace(/\{ROOM_ID\}/g, roomId.toString() ?? '196');
|
||||
};
|
||||
|
||||
const getLiveInfo = async (room: string) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!process.env.REACT_APP_BILIBILI_LIVE_INFO_API) {
|
||||
return { message: '请先设置 Bilibili API URL' };
|
||||
}
|
||||
|
||||
const url = setRoomId(room, process.env.REACT_APP_BILIBILI_LIVE_INFO_API);
|
||||
|
||||
let req = https.get(url, (res) => {
|
||||
console.log(`正在请求: ${url}`);
|
||||
|
||||
let data = '';
|
||||
|
||||
res.on('error', (err) => {
|
||||
console.error(err);
|
||||
reject(err);
|
||||
});
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
try {
|
||||
let result;
|
||||
if (res.statusCode === 200) {
|
||||
result = JSON.parse(data);
|
||||
}
|
||||
resolve(result);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('timeout', () => {
|
||||
console.error('请求超时');
|
||||
reject();
|
||||
});
|
||||
|
||||
req.on('uncaughtException', (err) => {
|
||||
console.error('错误:' + err);
|
||||
reject(err);
|
||||
});
|
||||
|
||||
req.on('error', (err) => {
|
||||
console.error('错误:' + err.message);
|
||||
reject(err);
|
||||
});
|
||||
|
||||
req.end();
|
||||
});
|
||||
};
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
if (req.headers.origin) {
|
||||
res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
|
||||
} else {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
res.setHeader('Access-Control-Request-Method', '*');
|
||||
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
|
||||
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET, POST, PUT');
|
||||
|
||||
if (req.method === 'GET') {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
let query: { room?: string } | undefined;
|
||||
if (req.url) {
|
||||
query = url.parse(req.url, true).query ?? undefined;
|
||||
}
|
||||
let result = await getLiveInfo(query?.room ?? '196');
|
||||
res.write(JSON.stringify(result));
|
||||
res.end();
|
||||
} else if (req.method === 'OPTIONS') {
|
||||
res.writeHead(200);
|
||||
res.end();
|
||||
return;
|
||||
} else {
|
||||
res.writeHead(404, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ message: '错误' }));
|
||||
}
|
||||
});
|
||||
|
||||
(() => {
|
||||
server.listen(parseInt(process.env.REACT_APP_BACKEND_PORT ?? '3001'), () => {
|
||||
console.log(`后端服务器已启动! (HTTP 端口: ${process.env.REACT_APP_BACKEND_PORT ?? '3001'})`);
|
||||
});
|
||||
})();
|
||||
@ -0,0 +1,33 @@
|
||||
import CardData from '../interface/CardData';
|
||||
import '../styles/smallCard.scss';
|
||||
|
||||
const liveStatus = (status: number | string) => {
|
||||
if (typeof status === 'string') {
|
||||
status = parseInt(status);
|
||||
}
|
||||
switch (status) {
|
||||
case 0:
|
||||
return <span className='status off'><span>●</span> 未开播</span>;
|
||||
case 1:
|
||||
return <span className='status on'><span>●</span> 直播中</span>;
|
||||
case 2:
|
||||
return <span className='status play'><span>●</span> 轮播中</span>;
|
||||
default:
|
||||
return <span className='status unknown'><span>●</span> 未知</span>;
|
||||
}
|
||||
};
|
||||
|
||||
const SmallCard = ({ roomId, title, uname, cover, status }: CardData) => {
|
||||
return (
|
||||
<div className='small-card'>
|
||||
<div className='small-card-body small-card-cover'><img src={cover} alt='直播间封面' /></div>
|
||||
<div className='small-card-body'>
|
||||
<div className='small-card-caption'><span>{uname} │ {roomId}</span></div>
|
||||
<h3>{title}</h3>
|
||||
<div className='small-card-status'>{liveStatus(status)}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default SmallCard;
|
||||
@ -0,0 +1,13 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import './styles/index.css';
|
||||
import App from './App';
|
||||
|
||||
const root = ReactDOM.createRoot(
|
||||
document.getElementById('root') as HTMLElement
|
||||
);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
@ -0,0 +1,11 @@
|
||||
interface CardData {
|
||||
roomId: string,
|
||||
title: string,
|
||||
uname?: string,
|
||||
cover: string,
|
||||
status: number,
|
||||
startTime?: string
|
||||
}
|
||||
|
||||
export default CardData;
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
interface LiveInfo {
|
||||
roomid: string | number;
|
||||
uid: string | number;
|
||||
uname: string;
|
||||
cover: string;
|
||||
title: string;
|
||||
live_status: number | string;
|
||||
tags?: string;
|
||||
user_cover?: string;
|
||||
short_id?: string | number;
|
||||
online?: string | number;
|
||||
area_v2_name?: string;
|
||||
live_time?: string;
|
||||
first_live_time?: number;
|
||||
room_cover?: string;
|
||||
[key: string]: string | Number | undefined;
|
||||
}
|
||||
|
||||
export default LiveInfo;
|
||||
@ -0,0 +1,20 @@
|
||||
.input {
|
||||
display: inline-block;
|
||||
padding: 0.5rem;
|
||||
background: #ccc;
|
||||
border-radius: 5px;
|
||||
|
||||
input {
|
||||
font-size: 110%;
|
||||
}
|
||||
|
||||
button {
|
||||
background: #06f;
|
||||
color: #fff;
|
||||
border: none;
|
||||
padding: 8px 20px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border-radius: 8px;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
.card {
|
||||
display: inline-block;
|
||||
padding: 0;
|
||||
background: #f5f5f5;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
text-align: center;
|
||||
|
||||
img {
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.card-content {
|
||||
padding: 0 1rem 1.5rem 1rem;
|
||||
}
|
||||
|
||||
.card-bottom {
|
||||
display: flex;
|
||||
background: rgba(0, 0, 0, 0.05);
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
padding: 0.3rem 1rem;
|
||||
|
||||
div {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.card-status {
|
||||
text-align: left;
|
||||
|
||||
.status {
|
||||
display: inline-block;
|
||||
padding: 0.5rem;
|
||||
border-radius: 50%;
|
||||
margin-right: 5px;
|
||||
vertical-align: middle;
|
||||
|
||||
&.on {
|
||||
background: #090;
|
||||
}
|
||||
&.off {
|
||||
background: #aaa;
|
||||
}
|
||||
&.play {
|
||||
background: #f90;
|
||||
}
|
||||
&.unknown {
|
||||
background: #c00;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 10px;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
background: #E5E5E5;
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
.table {
|
||||
margin: 2rem;
|
||||
display: table;
|
||||
div {
|
||||
display: table-row;
|
||||
padding: 0.5rem;
|
||||
div {
|
||||
display: table-cell;
|
||||
border: 1px solid #000;
|
||||
&:first-child {
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
|
||||
span {
|
||||
display: inline-block;
|
||||
padding: 8px;
|
||||
background: #CCC;
|
||||
border-radius: 3rem;
|
||||
margin-left: 5px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 50vw;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
.small-card {
|
||||
display: flex;
|
||||
width: 700px;
|
||||
padding: 0;
|
||||
background: #f5f5f5;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
text-align: center;
|
||||
margin: 15px 0;
|
||||
|
||||
.small-card-body {
|
||||
flex: 1;
|
||||
|
||||
h3 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
}
|
||||
|
||||
.small-card-cover {
|
||||
flex: none;
|
||||
text-align: left;
|
||||
padding: 0;
|
||||
width: 30%;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height:100%;
|
||||
}
|
||||
}
|
||||
|
||||
.small-card-caption {
|
||||
color: #666;
|
||||
text-align: right;
|
||||
span {
|
||||
display: inline-block;
|
||||
background: #ddd;
|
||||
padding: 3px 12px;
|
||||
border-bottom-left-radius: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.small-card-status {
|
||||
.status {
|
||||
span {
|
||||
font-size: 200%;
|
||||
vertical-align: sub;
|
||||
}
|
||||
|
||||
&.on {
|
||||
color: #090;
|
||||
}
|
||||
&.off {
|
||||
color: #aaa;
|
||||
}
|
||||
&.play {
|
||||
color: #f90;
|
||||
}
|
||||
&.unknown {
|
||||
color: #c00;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2020",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in new issue