Skip to content

Commit

Permalink
bgm.tv 下一季排除剧场版
Browse files Browse the repository at this point in the history
  • Loading branch information
kjtsune committed Sep 11, 2023
1 parent 555e3e0 commit e4b99f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
41 changes: 19 additions & 22 deletions utils/bangumi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,49 +85,46 @@ def get_target_season_episode_id(self, subject_id, target_season: int, target_ep
ep_num_list = target_ep if isinstance(target_ep, list) else None
target_ep = ep_num_list[0] if isinstance(target_ep, list) else target_ep

if target_season >= 5:
if target_ep:
return None, None
return None
if target_ep and target_ep > 50:
return None, None
if target_season >= 5 or (target_ep and target_ep > 99):
return None, None if target_ep else None

if target_season == 1:
fist_part = True
while True:
if not target_ep:
return current_id
ep_info = self.get_episodes(current_id)['data']
_target_ep = [i for i in ep_info if i['sort'] == target_ep]
if _target_ep:
if ep_num_list:
return current_id, [i['id'] for i in ep_info if i['sort'] in ep_num_list]
return current_id, _target_ep[0]['id']
is_new_season = True if ep_info[0]['sort'] <= 1 else False
if not fist_part and is_new_season:
episodes = self.get_episodes(current_id)
ep_info = episodes['data']
normal_season = True if episodes['total'] > 3 and ep_info[0]['sort'] <= 1 else False
if normal_season:
_target_ep = [i for i in ep_info if i['sort'] == target_ep]
if _target_ep:
if ep_num_list:
return current_id, [i['id'] for i in ep_info if i['sort'] in ep_num_list]
return current_id, _target_ep[0]['id']
if not fist_part and normal_season:
break
related = self.get_related_subjects(current_id)
next_id = [i for i in related if i['relation'] == '续集']
if not next_id:
break
current_id = next_id[0]['id']
fist_part = False
raise ValueError(f'{subject_id=} {target_season=} {target_ep=} not found')
return None, None if target_ep else None

while True:
related = self.get_related_subjects(current_id)
next_id = [i for i in related if i['relation'] == '续集']
if not next_id:
break
current_id = next_id[0]['id']
ep_info = self.get_episodes(current_id)['data']
is_new_season = True if ep_info[0]['sort'] <= 1 else False
episodes = self.get_episodes(current_id)
ep_info = episodes['data']
normal_season = True if episodes['total'] > 3 and ep_info[0]['sort'] <= 1 else False
_target_ep = [i for i in ep_info if i['sort'] == target_ep]
need_next_part = False if target_ep and _target_ep else True
if is_new_season:
if normal_season and not need_next_part:
season_num += 1
if is_new_season and need_next_part:
season_num -= 1
if season_num == target_season:
if not target_ep:
return current_id
Expand All @@ -138,7 +135,7 @@ def get_target_season_episode_id(self, subject_id, target_season: int, target_ep
if need_next_part:
continue
break
raise ValueError(f'{subject_id=} {target_season=} {target_ep=} not found')
return None, None if target_ep else None

def get_subject_collection(self, subject_id):
res = self.get(f'users/{self.username}/collections/{subject_id}')
Expand All @@ -165,7 +162,7 @@ def add_collection_subject(self, subject_id, private=None, state=3):
def change_episode_state(self, ep_id, state=2):
res = self.put(f'users/-/collections/-/episodes/{ep_id}',
_json={'type': state})
if res.status_code > 333:
if 333 < res.status_code < 444:
raise ValueError(f'{res.status_code=} {res.text}')
return res

Expand Down
6 changes: 3 additions & 3 deletions utils/bangumi_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def bangumi_sync(emby, bgm, emby_eps: list = None, emby_ids: list = None):
if bgm.title_diff_ratio(title=emby_title, ori_title=ori_title, bgm_data=bgm_data) < 0.5:
logger.error('bgm: bgm_data not match, skip')
return

subject_id = bgm_data['id']
bgm_se_id, bgm_ep_ids = bgm.get_target_season_episode_id(
subject_id=bgm_data['id'], target_season=season_num, target_ep=ep_nums)
subject_id=subject_id, target_season=season_num, target_ep=ep_nums)
if not bgm_ep_ids:
logger.info(f'bgm: {season_num=} {ep_nums=}, too big, not support')
logger.info(f'bgm: {subject_id=} {season_num=} {ep_nums=}, not exists or too big, skip')
return
logger.info(f'bgm: get {bgm_data["name"]} S0{season_num}E{ep_nums} https://bgm.tv/subject/{bgm_se_id}')
for bgm_ep_id, ep_num in zip(bgm_ep_ids, ep_nums):
Expand Down

0 comments on commit e4b99f1

Please sign in to comment.