Commit efb6ebd6c9

efb6ebd6c9ff8323ee1a13b702171666c32326f2

parent: d1665c0628

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-25 13:06 UTC

minor changes

Layout: unified · split

curd.py +27 −15
@@ -606,15 +606,21 @@ def mpv_send_command(ipc_socket_path, command):
606606 return None
607607 return None
608608
609def seek_mpv(ipc_socket_path, time):
610 """Seek MPV to a specific time."""
611 command = ["seek", time, "absolute"]
612 return mpv_send_command(ipc_socket_path, command)
613
614
609615def get_mpv_paused_status(ipc_socket_path):
610 status = send_command(ipc_socket_path, ["get_property", "pause"])
616 status = mpv_send_command(ipc_socket_path, ["get_property", "pause"])
611617 if status is not None:
612618 return status
613619 else:
614620 return False
615621
616622def get_mpv_playback_speed(ipc_socket_path):
617 current_speed = send_command(ipc_socket_path, ["get_property", "speed"])
623 current_speed = mpv_send_command(ipc_socket_path, ["get_property", "speed"])
618624 if current_speed is not None:
619625 return current_speed
620626 else:
@@ -625,13 +631,13 @@ def get_percentage_watched(ipc_socket_path):
625631 Calculates the percentage watched of the currently playing video.
626632 """
627633 # Get current playback time and total duration
628 current_time = send_command(ipc_socket_path, ["get_property", "time-pos"])
629 duration = send_command(ipc_socket_path, ["get_property", "duration"])
634 current_time = mpv_send_command(ipc_socket_path, ["get_property", "time-pos"])
635 duration = mpv_send_command(ipc_socket_path, ["get_property", "duration"])
630636
631637 if current_time is not None and duration is not None and duration > 0:
632638 percentage_watched = (current_time / duration) * 100
633639 return percentage_watched
634 return None
640 return 0
635641
636642def percentage_watched(playback_time:int, duration:int):
637643 if playback_time is not None and duration is not None and duration > 0:
@@ -867,7 +873,8 @@ def load_config() -> dict:
867873
868874 try:
869875 value = int(value)
870 except:
876 except Exception as e:
877 # print_error("878: {e}")
871878 pass
872879
873880 # Store in the dictionary
@@ -876,8 +883,8 @@ def load_config() -> dict:
876883 if not os.path.exists(config_dict['history_file']):
877884 try:
878885 os.makedirs(os.path.dirname(config_dict['history_file']))
879 except:
880 pass
886 except Exception as e:
887 print_error("888: {e}")
881888 print("creating history file")
882889 with open(config_dict["history_file"], "w") as history_file:
883890 history_file.write("")
@@ -1130,7 +1137,7 @@ write_to_tmp("query", anime_name)
11301137run_script("anime_list")
11311138anime_dict = load_anime_data(f"/tmp/curd/curd_anime_list")
11321139cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name
1133
1140# print(cleaned_text)
11341141try:
11351142 result = search_anime_by_title(anilist_user_data, cleaned_text)[0]
11361143 # print(result)
@@ -1150,7 +1157,7 @@ try:
11501157 finding_anime = find_anime(get_all_anime(get_userconfig_value(user_config, "history_file")), anilist_id=str(media_id))
11511158 # print(finding_anime)
11521159 if finding_anime:
1153 print("Found anime in history")
1160 print("Found anime in local history")
11541161 write_to_tmp("id", finding_anime['allanime_id'])
11551162 write_to_tmp("anime", finding_anime['name'])
11561163 else:
@@ -1160,7 +1167,8 @@ try:
11601167except KeyboardInterrupt:
11611168 print("bye")
11621169 exit(0)
1163except:
1170except Exception as e:
1171 # print_error(e)
11641172 print("Please select anime")
11651173 select_anime(anime_dict)
11661174
@@ -1300,6 +1308,7 @@ while True:
13001308 print("bye")
13011309 exit(0)
13021310 except Exception as e:
1311 print_error(f"Unknown:\n {e}")
13031312 print("Unknown:\n", e)
13041313 else:
13051314 killing_error = str(result.stderr)
@@ -1328,7 +1337,7 @@ while True:
13281337 # print("fuck")
13291338 # print(f"Exception: {e}")
13301339 break
1331 except ConnectionRefusedError: # doesnt work ig
1340 except ConnectionRefusedError: # execption is never reached ig
13321341 print("Player Closed")
13331342 # print("have a great")
13341343 # exit(0)
@@ -1343,7 +1352,7 @@ while True:
13431352 finally:
13441353 binge_watching=True
13451354 try:
1346 print("binge watching")
1355 # print("binge watching")
13471356 current_ep = int(read_tmp("ep_no"))
13481357
13491358 if current_ep == last_episode:
@@ -1356,7 +1365,7 @@ while True:
13561365 exit(0)
13571366
13581367 else:
1359 print(f"Starting next episode: {current_ep}")
1368 print(f"Starting next episode: {watching_ep}")
13601369 # write_to_tmp("ep_no", str(int(current_ep)+1))
13611370
13621371 if watched_percentage > mark_episode_as_completed_at: # IF BINGE WATCHING
@@ -1369,6 +1378,7 @@ while True:
13691378 anime_watch_history = get_all_anime(get_userconfig_value(user_config, 'history_file'))
13701379 anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id"))
13711380 episode_completed = False
1381 print("Fetching anime")
13721382 run_script("episode_url")
13731383 links = load_links(f"/tmp/curd/curd_links")
13741384 mpv_args = []
@@ -1385,5 +1395,7 @@ while True:
13851395 else:
13861396 exit(0)
13871397 except Exception as e:
1388 print(f"error:{e}\nMaybe try running again!")
1398 # print(f"error:{e}\nMaybe try running again!")
1399 print_error(f"{e}")
1400 print("Maybe try running again!")
13891401 exit(1)
\ No newline at end of file