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
13import time 13import time
14 14
15from anilist import search_anime_by_title 15from 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
17from select_link import load_links 17from select_link import load_links
18from start_video import start_video, send_command, get_percentage_watched, percentage_watched 18from start_video import start_video, send_command, get_percentage_watched, percentage_watched
19from select_anime import load_anime_data 19from select_anime import load_anime_data
@@ -293,7 +293,7 @@ while True:
293 293
294 # print(user_config['history_file']) 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 # print("Playback time:", playback_time) 297 # print("Playback time:", playback_time)
298 298
299 watched_percentage = get_percentage_watched(mpv_socket_path) 299 watched_percentage = get_percentage_watched(mpv_socket_path)
@@ -322,6 +322,20 @@ while True:
322 print("Unknown:\n", e) 322 print("Unknown:\n", e)
323 else: 323 else:
324 killing_error = str(result.stderr) 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 if killing_error == "property unavailable": # mpv is not started yet 339 if killing_error == "property unavailable": # mpv is not started yet
326 # print("passing") 340 # print("passing")
327 pass 341 pass
@@ -339,9 +353,9 @@ while True:
339 # exit(0) 353 # exit(0)
340 except KeyboardInterrupt: 354 except KeyboardInterrupt:
341 if watched_percentage > mark_episode_as_completed_at: 355 if watched_percentage > mark_episode_as_completed_at:
356 update_anime_progress(access_token, int(media_id), int(watching_ep))
342 watching_ep = int(watching_ep)+1 357 watching_ep = int(watching_ep)+1
343 358 update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title))
344 update_anime(user_config['history_file'], str(anime_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title))
345 359
346 print("bye") 360 print("bye")
347 exit(0) 361 exit(0)
@@ -354,40 +368,23 @@ while True:
354 if current_ep == last_episode: 368 if current_ep == last_episode:
355 print("completed anime.") 369 print("completed anime.")
356 # TODO: Add way to rate the anime 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 exit(0) 372 exit(0)
359 373
360 else: 374 else:
361 print(f"Next episode is here, goshujin sama progress: {current_ep} {type(current_ep)}") 375 print(f"Next episode is here, goshujin sama progress: {current_ep} {type(current_ep)}")
362 # write_to_tmp("ep_no", str(int(current_ep)+1)) 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 last_episode = int(read_tmp("episode_list").split()[-1]) 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 watching_ep = int(watching_ep)+1 382 watching_ep = int(watching_ep)+1
368 write_to_tmp("ep_no", str(watching_ep)) 383 write_to_tmp("ep_no", str(watching_ep))
369 update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title)) 384 update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title))
370 anime_watch_history = get_all_anime(user_config['history_file']) 385 anime_watch_history = get_all_anime(user_config['history_file'])
371 # anime_watch_history[] 386 anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id"))
372 anime_history = find_anime(anime_watch_history, anilist_id=anime_id, allanime_id=get_contents_of("id"))
373 episode_completed = False 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 run_script("episode_url") 388 run_script("episode_url")
392 links = load_links("scripts/tmp/links") 389 links = load_links("scripts/tmp/links")
393 mpv_args = [] 390 mpv_args = []