| @@ -87,10 +87,12 @@ default_config = { |
| 87 | "presence_script_path":"curddiscordpresence.py" |
87 | "presence_script_path":"curddiscordpresence.py" |
| 88 | } |
88 | } |
| 89 | |
89 | |
| 90 | def convert_seconds_to_minutes(seconds): |
90 | def convert_seconds_to_minutes(seconds) -> str: |
| 91 | minutes = seconds // 60 |
91 | minutes = seconds // 60 |
| 92 | remaining_seconds = seconds % 60 |
92 | remaining_seconds = seconds % 60 |
| 93 | return minutes, remaining_seconds |
93 | if remaining_seconds < 10: |
| |
94 | return f"{minutes}:0{remaining_seconds}" |
| |
95 | return f"{minutes}:{remaining_seconds}" |
| 94 | |
96 | |
| 95 | def get_userconfig_value(userconfig:dict, key:str): |
97 | def get_userconfig_value(userconfig:dict, key:str): |
| 96 | return userconfig.get(key, default_config.get(key)) |
98 | return userconfig.get(key, default_config.get(key)) |
| @@ -363,12 +365,11 @@ while True: |
| 363 | |
365 | |
| 364 | # print("mpv_status", mpv_status) |
366 | # print("mpv_status", mpv_status) |
| 365 | # print("is_paused", is_paused) |
367 | # print("is_paused", is_paused) |
| 366 | playback_time_minutes = convert_seconds_to_minutes(playback_time) |
| |
| 367 | if is_paused: |
368 | if is_paused: |
| 368 | # Update presence with paused status |
369 | # Update presence with paused status |
| 369 | rpc.update( |
370 | rpc.update( |
| 370 | details=f"Watching {title}", |
371 | details=f"Watching {title}", |
| 371 | state=f"Episode {watching_ep} - {"{}:{}".format(playback_time_minutes[0], playback_time_minutes[1])} (Paused)", |
372 | state=f"Episode {watching_ep} - {convert_seconds_to_minutes(playback_time)} (Paused)", |
| 372 | large_image=anime_image_url, |
373 | large_image=anime_image_url, |
| 373 | large_text=title, |
374 | large_text=title, |
| 374 | ) |
375 | ) |
| @@ -376,7 +377,7 @@ while True: |
| 376 | # Update presence with playback time |
377 | # Update presence with playback time |
| 377 | rpc.update( |
378 | rpc.update( |
| 378 | details=f"Watching {title}", |
379 | details=f"Watching {title}", |
| 379 | state=f"Episode {watching_ep} - {playback_time_minutes[0]}:{playback_time_minutes[1]}/{duration}:00", |
380 | state=f"Episode {watching_ep} - {convert_seconds_to_minutes(playback_time)}/{duration}:00", |
| 380 | large_image=anime_image_url, |
381 | large_image=anime_image_url, |
| 381 | large_text=title, |
382 | large_text=title, |
| 382 | ) |
383 | ) |
| @@ -446,45 +447,47 @@ while True: |
| 446 | exit(0) |
447 | exit(0) |
| 447 | finally: |
448 | finally: |
| 448 | binge_watching=True |
449 | binge_watching=True |
| |
450 | try: |
| |
451 | print("binge watching") |
| |
452 | current_ep = int(read_tmp("ep_no")) |
| |
453 | |
| |
454 | if current_ep == last_episode: |
| |
455 | if binge_watching == True and not rewatching and get_userconfig_value(user_config, 'score_on_completion') == True: # Completed anime |
| |
456 | anime_rating_by_user = input("Rate this anime:\n") |
| |
457 | update_anime_progress(access_token, int(media_id), int(watching_ep)) |
| |
458 | rate_anime(access_token, media_id, anime_rating_by_user) |
| |
459 | print("completed anime.") |
| |
460 | delete_anime(get_userconfig_value(user_config, 'history_file'), media_id, get_contents_of("id")) |
| |
461 | exit(0) |
| 449 | |
462 | |
| 450 | print("binge watching") |
463 | else: |
| 451 | current_ep = int(read_tmp("ep_no")) |
464 | print(f"Starting next episode: {current_ep}") |
| 452 | |
465 | # write_to_tmp("ep_no", str(int(current_ep)+1)) |
| 453 | if current_ep == last_episode: |
466 | |
| 454 | if binge_watching == True and not rewatching and get_userconfig_value(user_config, 'score_on_completion') == True: # Completed anime |
467 | if watched_percentage > mark_episode_as_completed_at: # IF BINGE WATCHING |
| 455 | anime_rating_by_user = input("Rate this anime:\n") |
468 | last_episode = int(read_tmp("episode_list").split()[-1]) |
| 456 | update_anime_progress(access_token, int(media_id), int(watching_ep)) |
469 | if not rewatching: |
| 457 | rate_anime(access_token, media_id, anime_rating_by_user) |
470 | update_anime_progress(access_token, int(media_id), int(watching_ep)) |
| 458 | print("completed anime.") |
471 | watching_ep = int(watching_ep)+1 |
| 459 | delete_anime(get_userconfig_value(user_config, 'history_file'), media_id, get_contents_of("id")) |
472 | write_to_tmp("ep_no", str(watching_ep)) |
| 460 | exit(0) |
473 | update_anime(get_userconfig_value(user_config, 'history_file'), str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title)) |
| 461 | |
474 | anime_watch_history = get_all_anime(get_userconfig_value(user_config, 'history_file')) |
| 462 | else: |
475 | anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) |
| 463 | print(f"Starting next episode: {current_ep}") |
476 | episode_completed = False |
| 464 | # write_to_tmp("ep_no", str(int(current_ep)+1)) |
477 | run_script("episode_url") |
| 465 | |
478 | links = load_links(f"{current_dir}/scripts/tmp/links") |
| 466 | if watched_percentage > mark_episode_as_completed_at: # IF BINGE WATCHING |
479 | mpv_args = [] |
| 467 | last_episode = int(read_tmp("episode_list").split()[-1]) |
480 | watched_percentage = 0 |
| 468 | if not rewatching: |
481 | |
| 469 | update_anime_progress(access_token, int(media_id), int(watching_ep)) |
482 | if get_userconfig_value(user_config, 'save_mpv_speed') ==True: |
| 470 | watching_ep = int(watching_ep)+1 |
483 | mpv_args.append(f'--speed={mpv_playback_speed}') |
| 471 | write_to_tmp("ep_no", str(watching_ep)) |
484 | |
| 472 | update_anime(get_userconfig_value(user_config, 'history_file'), str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title)) |
485 | # watching_ep = current_ep+1 |
| 473 | anime_watch_history = get_all_anime(get_userconfig_value(user_config, 'history_file')) |
486 | if get_userconfig_value(user_config, 'next_episode_prompt') == True: |
| 474 | anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) |
487 | to_continue_or_not_to_continue = input("Continue? (y/n)\n") |
| 475 | episode_completed = False |
488 | if to_continue_or_not_to_continue.lower() == "yes" or to_continue_or_not_to_continue.lower() == "y" or to_continue_or_not_to_continue == "": |
| 476 | run_script("episode_url") |
489 | binge_watching = True |
| 477 | links = load_links(f"{current_dir}/scripts/tmp/links") |
490 | else: |
| 478 | mpv_args = [] |
491 | exit(0) |
| 479 | watched_percentage = 0 |
492 | except Exception as e: |
| 480 | |
493 | print(f"error:{e}\nMaybe try running again!")\ No newline at end of file |
| 481 | if get_userconfig_value(user_config, 'save_mpv_speed') ==True: |
| |
| 482 | mpv_args.append(f'--speed={mpv_playback_speed}') |
| |
| 483 | |
| |
| 484 | # watching_ep = current_ep+1 |
| |
| 485 | if get_userconfig_value(user_config, 'next_episode_prompt') == True: |
| |
| 486 | to_continue_or_not_to_continue = input("Continue? (y/n)\n") |
| |
| 487 | if to_continue_or_not_to_continue.lower() == "yes" or to_continue_or_not_to_continue.lower() == "y" or to_continue_or_not_to_continue == "": |
| |
| 488 | binge_watching = True |
| |
| 489 | else: |
| |
| 490 | exit(0)\ No newline at end of file |
| |