Skip to content

Commit

Permalink
✨ new features
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow403 committed Jan 5, 2025
1 parent 036f999 commit 033a49c
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 35 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ BiliListener
- `v0.1.8` 🛠️ 支持更多配置项 🐍 修复数据库 `commit.handle` `Bugs`
- `v0.1.9-b1` 🌐 添加前端
- `v0.1.9-b2` 📦 添加打包图标 `(ico)`
- `v0.1.9` 🛠️ 支持更多配置项 ✨ 添加重置直播状态 `24h` ✨ 添加 `api` 版本区分
8 changes: 5 additions & 3 deletions app/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, config_data):
self.port = config_data["api"]["port"]
self.appver: str = __version__
self.perfix: str = "/api"
self.tags: list = ["API 💾"]
self.appname: str = "BiliListener"
self._c_404: dict = {"code": 404, "message": "notfound", "data": {}}
self._c_422: dict = {"code": 422, "message": "parm error | method not allowed", "data": {}}
Expand Down Expand Up @@ -47,18 +48,19 @@ def __init__(self, config_data):
}
self.auth: str = config_data["auth"]
self.live_push_url: str = "https://api.live.bilibili.com/room/v1/Room/get_status_info_by_uids"
self.push_query_delay: int = config_data["query_delay"]
self.push_query_delay: int = config_data["live_query_delay"]
self.live_clear_delay: int = config_data["live_clear_delay"]

self.data_path: str = f"{__PATH__}/{config_data['data']['path']}"
self.hide_console: bool = config_data["hide_console"]

self.debug: bool = config_data["debug"]

config: BaseConfig = BaseConfig(read_config())


class Router:
api_tags: list = ["API 💾"]
api_perfix: list = "/api"
v1_root: str = f"{config.perfix}/v1"

stats_tags: list = ["STATS 📈"]
stats_perfix: str = "/stats"
Expand Down
7 changes: 4 additions & 3 deletions app/config/utils/_func_init_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ def init_config():
data = {
"api": {
"host": "127.0.0.1",
"port": 5000
"port": 5700
},
"query_delay": 30,
"live_query_delay": 30,
"live_clear_delay": 86400,
"data": {
"path": "data"
},
"auth": {
"sessdata": ""
},
"debug": False,
"console": False
"hide_console": True
}

if not os.path.exists(path):
Expand Down
9 changes: 5 additions & 4 deletions app/pusher/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

from .utils import *
from .base_return import *
from config import config
from .router import MRouter
from config import config, Router
from .router.model._model_api import get_api
from .utils.tasks import live_status_inspectors
from .router.model.v1._model_api import get_api
from .utils.tasks import live_status_inspectors, live_clear_inspectors


scheduler = BackgroundScheduler()
scheduler.add_job(live_status_inspectors, "interval", seconds=config.push_query_delay)
scheduler.add_job(live_clear_inspectors, "interval", seconds=config.live_clear_delay)
scheduler.start()

_openapi = FastAPI.openapi
Expand Down Expand Up @@ -60,7 +61,7 @@ async def custom_swagger_ui_html():
swagger_ui_parameters={"defaultModelsExpandDepth": -1}
)

@app.get(Router.api_perfix, tags=Router.api_tags, response_model=get_api)
@app.get(config.perfix, tags=config.tags, response_model=get_api)
async def read_root():
return ret_200(data={
"server_time": func_time(info=True),
Expand Down
2 changes: 1 addition & 1 deletion app/pusher/router/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .main_router import MRouter
from .v1.main_router import MRouter
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from fastapi import APIRouter

from config import Router
from ..base_return import *
from ...base_return import *

from database import *
from database.model import *
from database.connector import get_db_config_session, get_db_worker_session

from .model._model_db2json_data import get_data_db2json
from .model._model_db2json_config import get_config_db2json
from ..model.v1._model_db2json_data import get_data_db2json
from ..model.v1._model_db2json_config import get_config_db2json


router = APIRouter(prefix=Router.livelogs_perfix, tags=Router.livelogs_tags)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from fastapi import APIRouter

from config import Router
from ..base_return import *
from ...base_return import *

from database import *
from database.model import UIDS
from database.connector import get_db_config_session

from .model._model_listening import get_listening
from .model._model_uids import get_uids
from ..model.v1._model_listening import get_listening
from ..model.v1._model_uids import get_uids


router = APIRouter(prefix=Router.info_perfix, tags=Router.info_tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from fastapi import APIRouter

from config import Router
from ..base_return import *
from ...base_return import *

from database import *
from database.model import *
from database.connector import get_db_config_session

from .model._model_total import get_total
from ..model.v1._model_total import get_total

router = APIRouter(prefix=Router.stats_perfix, tags=Router.stats_tags)

Expand Down Expand Up @@ -37,4 +37,3 @@ async def get_total_():
}

return ret_200(full_data)

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from fastapi import APIRouter

from config import Router
from ..base_return import *
from ...base_return import *

from database import *
from database.model import UIDS
from database.connector import get_db_config_session

from .model._model_edit_add import put_add_uid
from .model._model_del_uid import put_delete_uid
from ..model.v1._model_edit_add import put_add_uid
from ..model.v1._model_del_uid import put_delete_uid


router = APIRouter(prefix=Router.edit_perfix, tags=Router.edit_tags)
Expand All @@ -25,8 +25,8 @@ async def put_add_uid_(
else:
new_uid = UIDS(
uid=uid,
is_live = 0,
is_ban = 0
is_live=False,
is_ban=False
)
session.add(new_uid)
session.commit()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from config import config
from config import Router
from fastapi import APIRouter

from ._get_info import router as get_info_router
from ._put_edit import router as put_edit_router
from ._get_stats import router as get_stats_router
from ._get_db2json import router as get_db2json_router

MRouter = APIRouter(prefix=config.perfix)
MRouter = APIRouter(prefix=Router.v1_root)

MRouter.include_router(get_info_router)
MRouter.include_router(put_edit_router)
Expand Down
1 change: 1 addition & 0 deletions app/pusher/utils/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from ._task_livestatus import live_status_inspectors
from ._task_liveclear import live_clear_inspectors
22 changes: 22 additions & 0 deletions app/pusher/utils/tasks/_task_liveclear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from blivedm import logger

from .utils import func_get_live_status

from database.model import UIDS
from database.connector import get_db_config_session


def live_clear_inspectors():
with get_db_config_session() as config_db_session:
uid_query_list = config_db_session.query(UIDS.uid).filter(UIDS.is_live == True).all()
uid_list = [uid[0] for uid in uid_query_list]
uid_dict = {"uids": uid_list}
live_config = func_get_live_status(uid_dict, False)

for x in live_config:
uid = x["uid"]
live_status_update = config_db_session.query(UIDS).filter(UIDS.uid == uid).first()
live_status_update.is_live = False

config_db_session.commit()
logger.info(f"PREPARING LISTENING {uid}")
6 changes: 2 additions & 4 deletions app/pusher/utils/tasks/_task_livestatus.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import subprocess
from fastapi.logger import logger

from .utils import func_get_live_status
from blivedm import logger

from config import config

from .utils import func_get_live_status
from database.model import UIDS, LIVE_DATA
from database.utils import func_generate_uuid
from database.connector import get_db_config_session
Expand Down
22 changes: 18 additions & 4 deletions app/pusher/utils/tasks/utils/_func_livestatus.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
from blivedm import logger

from .api import api_query_live_status

def func_get_live_status(uid_list):
def func_get_live_status(
uid_list: list = [],
check_live_code: bool = True,
):
live_list = []
if check_live_code:
live_status = 1
else:
live_status = 0

ret_json = api_query_live_status(uid_list)
if ret_json["code"] != 0:
return live_list

for x, c in ret_json["data"].items():
if c["live_status"] == 1:
live_list.append(c)
try:
for x, c in ret_json["data"].items():
if c["live_status"] == live_status:
live_list.append(c)
except:
# logger.error("UID错误 {}")
return []

return live_list
4 changes: 4 additions & 0 deletions app/worker.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import sys
import ctypes

from config import ASCII_LOGO
from worker.app import worker_initializer


kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-10), (0x4|0x80|0x20|0x2|0x10|0x1|0x00|0x100))

def main():
print(ASCII_LOGO.worker)

Expand Down

0 comments on commit 033a49c

Please sign in to comment.