mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-05 07:28:04 +08:00
chore: try except 按块分割,移除无用的设置项
This commit is contained in:
@@ -29,7 +29,6 @@ class Config(DataClassJsonMixin):
|
|||||||
dedeuserid: str = ""
|
dedeuserid: str = ""
|
||||||
ac_time_value: str = ""
|
ac_time_value: str = ""
|
||||||
interval: int = 20 # 任务执行的间隔时间
|
interval: int = 20 # 任务执行的间隔时间
|
||||||
favorite_ids: list[int] = field(default_factory=list) # 收藏夹的 id
|
|
||||||
path_mapper: dict[int, str] = field(default_factory=dict) # 收藏夹的 id 到存储目录的映射
|
path_mapper: dict[int, str] = field(default_factory=dict) # 收藏夹的 id 到存储目录的映射
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -75,9 +74,6 @@ services:
|
|||||||
"dedeuserid": "xxxxxxxxxxxxxxxxxx",
|
"dedeuserid": "xxxxxxxxxxxxxxxxxx",
|
||||||
"ac_time_value": "xxxxxxxxxxxxxxxxxx",
|
"ac_time_value": "xxxxxxxxxxxxxxxxxx",
|
||||||
"interval": 20,
|
"interval": 20,
|
||||||
"favorite_ids": [
|
|
||||||
711322958
|
|
||||||
],
|
|
||||||
"path_mapper": {
|
"path_mapper": {
|
||||||
"711322958": "/Videos/Bilibilis/Bilibili-711322958/"
|
"711322958": "/Videos/Bilibilis/Bilibili-711322958/"
|
||||||
}
|
}
|
||||||
|
|||||||
+83
-54
@@ -91,12 +91,7 @@ async def process() -> None:
|
|||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Failed to refresh credential.")
|
logger.exception("Failed to refresh credential.")
|
||||||
return
|
return
|
||||||
for favorite_id in settings.favorite_ids:
|
for favorite_id in settings.path_mapper:
|
||||||
if favorite_id not in settings.path_mapper:
|
|
||||||
logger.warning(
|
|
||||||
f"Favorite {favorite_id} not in path mapper, ignored."
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
await process_favorite(favorite_id)
|
await process_favorite(favorite_id)
|
||||||
|
|
||||||
|
|
||||||
@@ -169,9 +164,19 @@ async def process_favorite_item(
|
|||||||
logger.warning("Media {} is not a video, skipped.", fav_item.name)
|
logger.warning("Media {} is not a video, skipped.", fav_item.name)
|
||||||
return
|
return
|
||||||
v = video.Video(fav_item.bvid, credential=credential)
|
v = video.Video(fav_item.bvid, credential=credential)
|
||||||
|
# 如果没有获取过 tags,那么尝试获取一下
|
||||||
try:
|
try:
|
||||||
if process_upper:
|
if fav_item.tags is None:
|
||||||
# 写入 up 主头像
|
fav_item.tags = [_["tag_name"] for _ in await v.get_tags()]
|
||||||
|
except Exception:
|
||||||
|
logger.exception(
|
||||||
|
"Failed to get tags of video {} {}",
|
||||||
|
fav_item.bvid,
|
||||||
|
fav_item.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
if process_upper:
|
||||||
|
try:
|
||||||
if not all(
|
if not all(
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
aexists(fav_item.upper.thumb_path),
|
aexists(fav_item.upper.thumb_path),
|
||||||
@@ -192,20 +197,16 @@ async def process_favorite_item(
|
|||||||
fav_item.upper.mid,
|
fav_item.upper.mid,
|
||||||
fav_item.upper.name,
|
fav_item.upper.name,
|
||||||
)
|
)
|
||||||
if process_nfo:
|
except Exception:
|
||||||
|
logger.exception(
|
||||||
|
"Failed to process upper {} {}",
|
||||||
|
fav_item.upper.mid,
|
||||||
|
fav_item.upper.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
if process_nfo:
|
||||||
|
try:
|
||||||
if not await aexists(fav_item.nfo_path):
|
if not await aexists(fav_item.nfo_path):
|
||||||
if fav_item.tags is None:
|
|
||||||
try:
|
|
||||||
fav_item.tags = [
|
|
||||||
_["tag_name"] for _ in await v.get_tags()
|
|
||||||
]
|
|
||||||
except Exception:
|
|
||||||
logger.exception(
|
|
||||||
"Failed to get tags of video {} {}",
|
|
||||||
fav_item.bvid,
|
|
||||||
fav_item.name,
|
|
||||||
)
|
|
||||||
# 写入 nfo
|
|
||||||
await EpisodeInfo(
|
await EpisodeInfo(
|
||||||
title=fav_item.name,
|
title=fav_item.name,
|
||||||
plot=fav_item.desc,
|
plot=fav_item.desc,
|
||||||
@@ -225,17 +226,39 @@ async def process_favorite_item(
|
|||||||
fav_item.bvid,
|
fav_item.bvid,
|
||||||
fav_item.name,
|
fav_item.name,
|
||||||
)
|
)
|
||||||
if process_poster:
|
except Exception:
|
||||||
# 写入 poster
|
logger.exception(
|
||||||
|
"Failed to process nfo of video {} {}",
|
||||||
|
fav_item.bvid,
|
||||||
|
fav_item.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
if process_poster:
|
||||||
|
try:
|
||||||
if not await aexists(fav_item.poster_path):
|
if not await aexists(fav_item.poster_path):
|
||||||
await download_content(fav_item.cover, fav_item.poster_path)
|
try:
|
||||||
|
await download_content(fav_item.cover, fav_item.poster_path)
|
||||||
|
except Exception:
|
||||||
|
logger.exception(
|
||||||
|
"Failed to download poster of video {} {}",
|
||||||
|
fav_item.bvid,
|
||||||
|
fav_item.name,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Poster of {} {} already exists, skipped.",
|
"Poster of {} {} already exists, skipped.",
|
||||||
fav_item.bvid,
|
fav_item.bvid,
|
||||||
fav_item.name,
|
fav_item.name,
|
||||||
)
|
)
|
||||||
if process_subtitle:
|
except Exception:
|
||||||
|
logger.exception(
|
||||||
|
"Failed to process poster of video {} {}",
|
||||||
|
fav_item.bvid,
|
||||||
|
fav_item.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
if process_subtitle:
|
||||||
|
try:
|
||||||
if not await aexists(fav_item.subtitle_path):
|
if not await aexists(fav_item.subtitle_path):
|
||||||
await ass.make_ass_file_danmakus_protobuf(
|
await ass.make_ass_file_danmakus_protobuf(
|
||||||
v, 0, str(fav_item.subtitle_path.resolve())
|
v, 0, str(fav_item.subtitle_path.resolve())
|
||||||
@@ -246,7 +269,14 @@ async def process_favorite_item(
|
|||||||
fav_item.bvid,
|
fav_item.bvid,
|
||||||
fav_item.name,
|
fav_item.name,
|
||||||
)
|
)
|
||||||
if process_video:
|
except Exception:
|
||||||
|
logger.exception(
|
||||||
|
"Failed to process subtitle of video {} {}",
|
||||||
|
fav_item.bvid,
|
||||||
|
fav_item.name,
|
||||||
|
)
|
||||||
|
if process_video:
|
||||||
|
try:
|
||||||
if await aexists(fav_item.video_path):
|
if await aexists(fav_item.video_path):
|
||||||
fav_item.downloaded = True
|
fav_item.downloaded = True
|
||||||
logger.info(
|
logger.info(
|
||||||
@@ -299,34 +329,33 @@ async def process_favorite_item(
|
|||||||
fav_item.tmp_video_path.unlink()
|
fav_item.tmp_video_path.unlink()
|
||||||
fav_item.tmp_audio_path.unlink()
|
fav_item.tmp_audio_path.unlink()
|
||||||
fav_item.downloaded = True
|
fav_item.downloaded = True
|
||||||
logger.info(
|
except ResponseCodeException as e:
|
||||||
"{} {} processed successfully.",
|
match e.code:
|
||||||
fav_item.bvid,
|
case 62002:
|
||||||
fav_item.name,
|
fav_item.status = MediaStatus.INVISIBLE
|
||||||
)
|
case -404:
|
||||||
except ResponseCodeException as e:
|
fav_item.status = MediaStatus.DELETED
|
||||||
match e.code:
|
case _:
|
||||||
case 62002:
|
logger.exception(
|
||||||
fav_item.status = MediaStatus.INVISIBLE
|
"Failed to process video {} {}, error_code: {}",
|
||||||
case -404:
|
fav_item.bvid,
|
||||||
fav_item.status = MediaStatus.DELETED
|
fav_item.name,
|
||||||
case _:
|
e.code,
|
||||||
logger.exception(
|
)
|
||||||
"Failed to process video {} {}, error_code: {}",
|
if fav_item.status != MediaStatus.NORMAL:
|
||||||
|
logger.error(
|
||||||
|
"Video {} {} is not available, marked as {}",
|
||||||
fav_item.bvid,
|
fav_item.bvid,
|
||||||
fav_item.name,
|
fav_item.name,
|
||||||
e.code,
|
fav_item.status.text,
|
||||||
)
|
)
|
||||||
return
|
except Exception:
|
||||||
logger.error(
|
logger.exception(
|
||||||
"Video {} {} is not available, marked as {}",
|
"Failed to process video {} {}", fav_item.bvid, fav_item.name
|
||||||
fav_item.bvid,
|
)
|
||||||
fav_item.name,
|
await fav_item.save()
|
||||||
fav_item.status.text,
|
logger.info(
|
||||||
)
|
"{} {} is processed successfully.",
|
||||||
except Exception:
|
fav_item.bvid,
|
||||||
logger.exception(
|
fav_item.name,
|
||||||
"Failed to process video {} {}", fav_item.bvid, fav_item.name
|
)
|
||||||
)
|
|
||||||
finally:
|
|
||||||
await fav_item.save()
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class Config(DataClassJsonMixin):
|
|||||||
dedeuserid: str = ""
|
dedeuserid: str = ""
|
||||||
ac_time_value: str = ""
|
ac_time_value: str = ""
|
||||||
interval: int = 20
|
interval: int = 20
|
||||||
favorite_ids: list[int] = field(default_factory=list)
|
|
||||||
path_mapper: dict[int, str] = field(default_factory=dict)
|
path_mapper: dict[int, str] = field(default_factory=dict)
|
||||||
|
|
||||||
def validate(self) -> Self:
|
def validate(self) -> Self:
|
||||||
|
|||||||
Reference in New Issue
Block a user