Commit 5b13696c73
Unsigned
Layout: unified · split
curd.py +22 −25
| @@ -13,7 +13,7 @@ import subprocess | ||
| 13 | 13 | import time |
| 14 | 14 | |
| 15 | 15 | from anilist import search_anime_by_title |
| 16 | from anilist import get_user_data, get_anilist_user_id | |
| 16 | from anilist import get_user_data, get_anilist_user_id, update_anime_progress | |
| 17 | 17 | from select_link import load_links |
| 18 | 18 | from start_video import start_video, send_command, get_percentage_watched, percentage_watched |
| 19 | 19 | from select_anime import load_anime_data |
| @@ -293,7 +293,7 @@ while True: | ||
| 293 | 293 | |
| 294 | 294 | # print(user_config['history_file']) |
| 295 | 295 | |
| 296 | update_anime(user_config['history_file'], str(anime_id), str(get_contents_of("id")), str(watching_ep), str(playback_time), str(duration), str(title)) | |
| 296 | update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), str(playback_time), str(duration), str(title)) | |
| 297 | 297 | # print("Playback time:", playback_time) |
| 298 | 298 | |
| 299 | 299 | watched_percentage = get_percentage_watched(mpv_socket_path) |
| @@ -322,6 +322,20 @@ while True: | ||
| 322 | 322 | print("Unknown:\n", e) |
| 323 | 323 | else: |
| 324 | 324 | killing_error = str(result.stderr) |
| 325 | # print(killing_error[-19:-1]) | |
| 326 | try: | |
| 327 | if killing_error[-19:-1] == "Connection refused": # user closed the stream | |
| 328 | if watched_percentage > mark_episode_as_completed_at: | |
| 329 | # update_anime_progress(access_token, int(media_id), int(watching_ep)) | |
| 330 | # watching_ep = int(watching_ep)+1 | |
| 331 | # update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title)) | |
| 332 | break | |
| 333 | else: | |
| 334 | print("Have a great day!") | |
| 335 | exit(0) | |
| 336 | ||
| 337 | except Exception as e: # user did not close the stream | |
| 338 | print(e) | |
| 325 | 339 | if killing_error == "property unavailable": # mpv is not started yet |
| 326 | 340 | # print("passing") |
| 327 | 341 | pass |
| @@ -339,9 +353,9 @@ while True: | ||
| 339 | 353 | # exit(0) |
| 340 | 354 | except KeyboardInterrupt: |
| 341 | 355 | if watched_percentage > mark_episode_as_completed_at: |
| 356 | update_anime_progress(access_token, int(media_id), int(watching_ep)) | |
| 342 | 357 | watching_ep = int(watching_ep)+1 |
| 343 | ||
| 344 | update_anime(user_config['history_file'], str(anime_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title)) | |
| 358 | update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title)) | |
| 345 | 359 | |
| 346 | 360 | print("bye") |
| 347 | 361 | exit(0) |
| @@ -354,40 +368,23 @@ while True: | ||
| 354 | 368 | if current_ep == last_episode: |
| 355 | 369 | print("completed anime.") |
| 356 | 370 | # TODO: Add way to rate the anime |
| 357 | delete_anime(user_config['history_file'], anime_id, get_contents_of("id")) | |
| 371 | delete_anime(user_config['history_file'], media_id, get_contents_of("id")) | |
| 358 | 372 | exit(0) |
| 359 | 373 | |
| 360 | 374 | else: |
| 361 | 375 | print(f"Next episode is here, goshujin sama progress: {current_ep} {type(current_ep)}") |
| 362 | 376 | # write_to_tmp("ep_no", str(int(current_ep)+1)) |
| 363 | 377 | |
| 364 | if watched_percentage > mark_episode_as_completed_at: | |
| 378 | if watched_percentage > mark_episode_as_completed_at: # BINGE WATCHING | |
| 365 | 379 | last_episode = int(read_tmp("episode_list").split()[-1]) |
| 380 | update_anime_progress(access_token, int(media_id), int(watching_ep)) | |
| 366 | 381 | |
| 367 | 382 | watching_ep = int(watching_ep)+1 |
| 368 | 383 | write_to_tmp("ep_no", str(watching_ep)) |
| 369 | 384 | update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title)) |
| 370 | 385 | anime_watch_history = get_all_anime(user_config['history_file']) |
| 371 | # anime_watch_history[] | |
| 372 | anime_history = find_anime(anime_watch_history, anilist_id=anime_id, allanime_id=get_contents_of("id")) | |
| 386 | anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) | |
| 373 | 387 | episode_completed = False |
| 374 | if anime_history: # if it exists in local history | |
| 375 | print(f"came in history {str(anime_history['episode'])}") | |
| 376 | print("is ahead") | |
| 377 | # write_to_tmp("ep_no", str(int(progress)+1)) | |
| 378 | # print(f"Starting anime from upstream {str(progress + 1)}") | |
| 379 | ||
| 380 | # watching_ep = progress + 1 | |
| 381 | ||
| 382 | # elif int(anime_history['episode']) == int(progress)+1: # if the upstream progress is NOT ahead | |
| 383 | # print("is equal") | |
| 384 | mpv_args.append(f"--start={anime_history['time']}") | |
| 385 | # write_to_tmp("ep_no", watching_ep) | |
| 386 | print(f"STARTING ANIME FROM EPISODE {anime_history['episode']} {anime_history['time']}") | |
| 387 | watching_ep = int(anime_history['episode']) | |
| 388 | ||
| 389 | print("watching ep", watching_ep) | |
| 390 | ||
| 391 | 388 | run_script("episode_url") |
| 392 | 389 | links = load_links("scripts/tmp/links") |
| 393 | 390 | mpv_args = [] |