Commit 5b13696c73

5b13696c73c52029bf681c4633704d266e811345

parent: ef20df4e76

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-21 23:55 UTC

bug fixes, logic improvement, refactor variable

Layout: unified · split

curd.py +22 −25
@@ -13,7 +13,7 @@ import subprocess
1313import time
1414
1515from anilist import search_anime_by_title
16from anilist import get_user_data, get_anilist_user_id
16from anilist import get_user_data, get_anilist_user_id, update_anime_progress
1717from select_link import load_links
1818from start_video import start_video, send_command, get_percentage_watched, percentage_watched
1919from select_anime import load_anime_data
@@ -293,7 +293,7 @@ while True:
293293
294294 # print(user_config['history_file'])
295295
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))
297297 # print("Playback time:", playback_time)
298298
299299 watched_percentage = get_percentage_watched(mpv_socket_path)
@@ -322,6 +322,20 @@ while True:
322322 print("Unknown:\n", e)
323323 else:
324324 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)
325339 if killing_error == "property unavailable": # mpv is not started yet
326340 # print("passing")
327341 pass
@@ -339,9 +353,9 @@ while True:
339353 # exit(0)
340354 except KeyboardInterrupt:
341355 if watched_percentage > mark_episode_as_completed_at:
356 update_anime_progress(access_token, int(media_id), int(watching_ep))
342357 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))
345359
346360 print("bye")
347361 exit(0)
@@ -354,40 +368,23 @@ while True:
354368 if current_ep == last_episode:
355369 print("completed anime.")
356370 # 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"))
358372 exit(0)
359373
360374 else:
361375 print(f"Next episode is here, goshujin sama progress: {current_ep} {type(current_ep)}")
362376 # write_to_tmp("ep_no", str(int(current_ep)+1))
363377
364 if watched_percentage > mark_episode_as_completed_at:
378 if watched_percentage > mark_episode_as_completed_at: # BINGE WATCHING
365379 last_episode = int(read_tmp("episode_list").split()[-1])
380 update_anime_progress(access_token, int(media_id), int(watching_ep))
366381
367382 watching_ep = int(watching_ep)+1
368383 write_to_tmp("ep_no", str(watching_ep))
369384 update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title))
370385 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"))
373387 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
391388 run_script("episode_url")
392389 links = load_links("scripts/tmp/links")
393390 mpv_args = []