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'])
219219# anime_watch_history[]
220220anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id"))
221221episode_completed = False
222rewatching = False
222223if anime_history: # if it exists in local history
223224 # print(f"came in history {str(progress)}")
224225 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
234235
235236 watching_ep = int(anime_history['episode'])
236237else: # if there is no history
237 # print("no history found")
238
239 # print("First time watch")
240
241238 if progress == last_episode:
242239 user_input = input("Do you want to start this anime from beginning? (y/n):")
243240 if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "":
244241 progress = 0
242 rewatching = True
245243 else:
246244 print("Starting last episode of anime")
247245 progress = last_episode - 1
@@ -353,7 +351,7 @@ while True:
353351 # print("have a great")
354352 # exit(0)
355353 except KeyboardInterrupt:
356 if watched_percentage > mark_episode_as_completed_at:
354 if watched_percentage > mark_episode_as_completed_at and not rewatching:
357355 update_anime_progress(access_token, int(media_id), int(watching_ep))
358356 watching_ep = int(watching_ep)+1
359357 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:
367365 current_ep = int(read_tmp("ep_no"))
368366
369367 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)
370372 print("completed anime.")
371373 # TODO: Add way to rate the anime
372374 delete_anime(user_config['history_file'], media_id, get_contents_of("id"))
373375 exit(0)
374376
375377 else:
376 print(f"Next episode is here, goshujin sama progress: {current_ep} {type(current_ep)}")
378 print(f"Starting next episode: {current_ep}")
377379 # write_to_tmp("ep_no", str(int(current_ep)+1))
378380
379 if watched_percentage > mark_episode_as_completed_at: # BINGE WATCHING
381 if watched_percentage > mark_episode_as_completed_at: # IF BINGE WATCHING
380382 last_episode = int(read_tmp("episode_list").split()[-1])
381 update_anime_progress(access_token, int(media_id), int(watching_ep))
382
383 if not rewatching:
384 update_anime_progress(access_token, int(media_id), int(watching_ep))
385 else:
383386 watching_ep = int(watching_ep)+1
384387 write_to_tmp("ep_no", str(watching_ep))
385388 update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title))