-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 加入 recheck 功能,在本地文件被删除后重新标记为未下载
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters