Commit 808a08fa67

808a08fa67a2ba72ef82da0a461a3de47a1ca328

parent: 9d4781a0a7

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-22 00:32 UTC

rewatching logic added

Layout: unified · split

curd.py +12 −9
@@ -219,6 +219,7 @@ anime_watch_history = get_all_anime(user_config['history_file'])
219# anime_watch_history[] 219# anime_watch_history[]
220anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) 220anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id"))
221episode_completed = False 221episode_completed = False
222rewatching = False
222if anime_history: # if it exists in local history 223if anime_history: # if it exists in local history
223 # print(f"came in history {str(progress)}") 224 # print(f"came in history {str(progress)}")
224 if int(anime_history['episode']) != progress+1: # if the upstream progress is ahead 225 if int(anime_history['episode']) != progress+1: # if the upstream progress is ahead
@@ -234,14 +235,11 @@ if anime_history: # if it exists in local history
234 235
235 watching_ep = int(anime_history['episode']) 236 watching_ep = int(anime_history['episode'])
236else: # if there is no history 237else: # if there is no history
237 # print("no history found")
238
239 # print("First time watch")
240
241 if progress == last_episode: 238 if progress == last_episode:
242 user_input = input("Do you want to start this anime from beginning? (y/n):") 239 user_input = input("Do you want to start this anime from beginning? (y/n):")
243 if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "": 240 if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "":
244 progress = 0 241 progress = 0
242 rewatching = True
245 else: 243 else:
246 print("Starting last episode of anime") 244 print("Starting last episode of anime")
247 progress = last_episode - 1 245 progress = last_episode - 1
@@ -353,7 +351,7 @@ while True:
353 # print("have a great") 351 # print("have a great")
354 # exit(0) 352 # exit(0)
355 except KeyboardInterrupt: 353 except KeyboardInterrupt:
356 if watched_percentage > mark_episode_as_completed_at: 354 if watched_percentage > mark_episode_as_completed_at and not rewatching:
357 update_anime_progress(access_token, int(media_id), int(watching_ep)) 355 update_anime_progress(access_token, int(media_id), int(watching_ep))
358 watching_ep = int(watching_ep)+1 356 watching_ep = int(watching_ep)+1
359 update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title)) 357 update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title))
@@ -367,19 +365,24 @@ while True:
367 current_ep = int(read_tmp("ep_no")) 365 current_ep = int(read_tmp("ep_no"))
368 366
369 if current_ep == last_episode: 367 if current_ep == last_episode:
368 if binge_watching == True and not rewatching and user_config['score_on_completion'] == True: # Completed anime
369 anime_rating_by_user = input("Rate this anime:\n")
370 update_anime_progress(access_token, int(media_id), int(watching_ep))
371 rate_anime(access_token, media_id, anime_rating_by_user)
370 print("completed anime.") 372 print("completed anime.")
371 # TODO: Add way to rate the anime 373 # TODO: Add way to rate the anime
372 delete_anime(user_config['history_file'], media_id, get_contents_of("id")) 374 delete_anime(user_config['history_file'], media_id, get_contents_of("id"))
373 exit(0) 375 exit(0)
374 376
375 else: 377 else:
376 print(f"Next episode is here, goshujin sama progress: {current_ep} {type(current_ep)}") 378 print(f"Starting next episode: {current_ep}")
377 # write_to_tmp("ep_no", str(int(current_ep)+1)) 379 # write_to_tmp("ep_no", str(int(current_ep)+1))
378 380
379 if watched_percentage > mark_episode_as_completed_at: # BINGE WATCHING 381 if watched_percentage > mark_episode_as_completed_at: # IF BINGE WATCHING
380 last_episode = int(read_tmp("episode_list").split()[-1]) 382 last_episode = int(read_tmp("episode_list").split()[-1])
381 update_anime_progress(access_token, int(media_id), int(watching_ep)) 383 if not rewatching:
382 384 update_anime_progress(access_token, int(media_id), int(watching_ep))
385 else:
383 watching_ep = int(watching_ep)+1 386 watching_ep = int(watching_ep)+1
384 write_to_tmp("ep_no", str(watching_ep)) 387 write_to_tmp("ep_no", str(watching_ep))
385 update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title)) 388 update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title))