mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-05-08 01:02:49 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ad977e41d4 | ||
|
|
dc612ec6f1 | ||
|
|
eee99d9fda | ||
|
|
e977f12568 |
@@ -55,6 +55,7 @@ services:
|
||||
bili-sync:
|
||||
image: amtoaer/bili-sync:latest
|
||||
user: 1000:1000 # 此处可以指定以哪个用户的权限运行,不填写的话默认 root,推荐填写。
|
||||
tty: true # 加上这一行可以让日志变成彩色
|
||||
volumes:
|
||||
- /home/amtoaer/Videos/Bilibilis/:/Videos/Bilibilis/ # 视频文件
|
||||
- /home/amtoaer/.config/nas/bili-sync/config/:/app/config/ # 配置文件
|
||||
|
||||
38
commands.py
Normal file
38
commands.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import asyncio
|
||||
|
||||
from aiofiles.os import path
|
||||
from loguru import logger
|
||||
|
||||
from constants import MediaStatus, MediaType
|
||||
from models import FavoriteItem
|
||||
|
||||
|
||||
async def recheck():
|
||||
"""刷新数据库中视频的状态,如果发现文件不存在则标记未下载,以便在下次任务重新下载,在自己手动删除文件后调用"""
|
||||
items = await FavoriteItem.filter(
|
||||
type=MediaType.VIDEO,
|
||||
status=MediaStatus.NORMAL,
|
||||
downloaded=True,
|
||||
)
|
||||
exists = await asyncio.gather(
|
||||
*[path.exists(item.video_path) for item in items]
|
||||
)
|
||||
for item, exist in zip(items, exists):
|
||||
if isinstance(exist, Exception):
|
||||
logger.error(
|
||||
"Error when checking file {} {}: {}",
|
||||
item.bvid,
|
||||
item.name,
|
||||
exist,
|
||||
)
|
||||
continue
|
||||
if not exist:
|
||||
logger.info(
|
||||
"File {} {} not exists, mark as not downloaded.",
|
||||
item.bvid,
|
||||
item.name,
|
||||
)
|
||||
item.downloaded = False
|
||||
logger.info("Updating database...")
|
||||
await FavoriteItem.bulk_update(items, fields=["downloaded"])
|
||||
logger.info("Database updated.")
|
||||
6
entry.py
6
entry.py
@@ -4,6 +4,7 @@ import sys
|
||||
import uvloop
|
||||
from loguru import logger
|
||||
|
||||
from commands import recheck
|
||||
from models import init_model
|
||||
from processor import cleanup, process
|
||||
from settings import settings
|
||||
@@ -18,6 +19,11 @@ async def entry() -> None:
|
||||
logger.info("Running once...")
|
||||
await process()
|
||||
return
|
||||
if any("recheck" in _ for _ in sys.argv):
|
||||
# 重新检查
|
||||
logger.info("Rechecking...")
|
||||
await recheck()
|
||||
return
|
||||
logger.info("Running daemon...")
|
||||
while True:
|
||||
await process()
|
||||
|
||||
11
processor.py
11
processor.py
@@ -17,8 +17,6 @@ from models import FavoriteItem, FavoriteList, Upper
|
||||
from nfo import Actor, EpisodeInfo
|
||||
from settings import settings
|
||||
|
||||
anchor = datetime.datetime.today()
|
||||
|
||||
client = httpx.AsyncClient(headers=HEADERS)
|
||||
|
||||
|
||||
@@ -95,11 +93,12 @@ async def manage_model(medias: list[dict], fav_list: FavoriteList) -> None:
|
||||
|
||||
async def process() -> None:
|
||||
global anchor
|
||||
if (datetime.datetime.now() - anchor).days >= 3:
|
||||
# 暂定三天刷新一次凭据,具体看情况调整
|
||||
if not await credential.check_valid():
|
||||
logger.error("Credential is invalid, skipped.")
|
||||
return
|
||||
if await credential.check_refresh():
|
||||
try:
|
||||
credential.refresh()
|
||||
anchor = datetime.datetime.today()
|
||||
await credential.refresh()
|
||||
logger.info("Credential refreshed.")
|
||||
except Exception:
|
||||
logger.exception("Failed to refresh credential.")
|
||||
|
||||
Reference in New Issue
Block a user