Commit efb6ebd6c9
Unsigned
Layout: unified · split
curd.py +27 −15
| @@ -606,15 +606,21 @@ def mpv_send_command(ipc_socket_path, command): | |||
| 606 | return None | 606 | return None |
| 607 | return None | 607 | return None |
| 608 | 608 | ||
| 609 | def 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 | |||
| 609 | def get_mpv_paused_status(ipc_socket_path): | 615 | def 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"]) |
| 611 | if status is not None: | 617 | if status is not None: |
| 612 | return status | 618 | return status |
| 613 | else: | 619 | else: |
| 614 | return False | 620 | return False |
| 615 | 621 | ||
| 616 | def get_mpv_playback_speed(ipc_socket_path): | 622 | def 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"]) |
| 618 | if current_speed is not None: | 624 | if current_speed is not None: |
| 619 | return current_speed | 625 | return current_speed |
| 620 | else: | 626 | else: |
| @@ -625,13 +631,13 @@ def get_percentage_watched(ipc_socket_path): | |||
| 625 | Calculates the percentage watched of the currently playing video. | 631 | Calculates the percentage watched of the currently playing video. |
| 626 | """ | 632 | """ |
| 627 | # Get current playback time and total duration | 633 | # Get current playback time and total duration |
| 628 | current_time = send_command(ipc_socket_path, ["get_property", "time-pos"]) | 634 | current_time = mpv_send_command(ipc_socket_path, ["get_property", "time-pos"]) |
| 629 | duration = send_command(ipc_socket_path, ["get_property", "duration"]) | 635 | duration = mpv_send_command(ipc_socket_path, ["get_property", "duration"]) |
| 630 | 636 | ||
| 631 | if current_time is not None and duration is not None and duration > 0: | 637 | if current_time is not None and duration is not None and duration > 0: |
| 632 | percentage_watched = (current_time / duration) * 100 | 638 | percentage_watched = (current_time / duration) * 100 |
| 633 | return percentage_watched | 639 | return percentage_watched |
| 634 | return None | 640 | return 0 |
| 635 | 641 | ||
| 636 | def percentage_watched(playback_time:int, duration:int): | 642 | def percentage_watched(playback_time:int, duration:int): |
| 637 | if playback_time is not None and duration is not None and duration > 0: | 643 | if playback_time is not None and duration is not None and duration > 0: |
| @@ -867,7 +873,8 @@ def load_config() -> dict: | |||
| 867 | 873 | ||
| 868 | try: | 874 | try: |
| 869 | value = int(value) | 875 | value = int(value) |
| 870 | except: | 876 | except Exception as e: |
| 877 | # print_error("878: {e}") | ||
| 871 | pass | 878 | pass |
| 872 | 879 | ||
| 873 | # Store in the dictionary | 880 | # Store in the dictionary |
| @@ -876,8 +883,8 @@ def load_config() -> dict: | |||
| 876 | if not os.path.exists(config_dict['history_file']): | 883 | if not os.path.exists(config_dict['history_file']): |
| 877 | try: | 884 | try: |
| 878 | os.makedirs(os.path.dirname(config_dict['history_file'])) | 885 | os.makedirs(os.path.dirname(config_dict['history_file'])) |
| 879 | except: | 886 | except Exception as e: |
| 880 | pass | 887 | print_error("888: {e}") |
| 881 | print("creating history file") | 888 | print("creating history file") |
| 882 | with open(config_dict["history_file"], "w") as history_file: | 889 | with open(config_dict["history_file"], "w") as history_file: |
| 883 | history_file.write("") | 890 | history_file.write("") |
| @@ -1130,7 +1137,7 @@ write_to_tmp("query", anime_name) | |||
| 1130 | run_script("anime_list") | 1137 | run_script("anime_list") |
| 1131 | anime_dict = load_anime_data(f"/tmp/curd/curd_anime_list") | 1138 | anime_dict = load_anime_data(f"/tmp/curd/curd_anime_list") |
| 1132 | cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name | 1139 | cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name |
| 1133 | 1140 | # print(cleaned_text) | |
| 1134 | try: | 1141 | try: |
| 1135 | result = search_anime_by_title(anilist_user_data, cleaned_text)[0] | 1142 | result = search_anime_by_title(anilist_user_data, cleaned_text)[0] |
| 1136 | # print(result) | 1143 | # print(result) |
| @@ -1150,7 +1157,7 @@ try: | |||
| 1150 | finding_anime = find_anime(get_all_anime(get_userconfig_value(user_config, "history_file")), anilist_id=str(media_id)) | 1157 | finding_anime = find_anime(get_all_anime(get_userconfig_value(user_config, "history_file")), anilist_id=str(media_id)) |
| 1151 | # print(finding_anime) | 1158 | # print(finding_anime) |
| 1152 | if finding_anime: | 1159 | if finding_anime: |
| 1153 | print("Found anime in history") | 1160 | print("Found anime in local history") |
| 1154 | write_to_tmp("id", finding_anime['allanime_id']) | 1161 | write_to_tmp("id", finding_anime['allanime_id']) |
| 1155 | write_to_tmp("anime", finding_anime['name']) | 1162 | write_to_tmp("anime", finding_anime['name']) |
| 1156 | else: | 1163 | else: |
| @@ -1160,7 +1167,8 @@ try: | |||
| 1160 | except KeyboardInterrupt: | 1167 | except KeyboardInterrupt: |
| 1161 | print("bye") | 1168 | print("bye") |
| 1162 | exit(0) | 1169 | exit(0) |
| 1163 | except: | 1170 | except Exception as e: |
| 1171 | # print_error(e) | ||
| 1164 | print("Please select anime") | 1172 | print("Please select anime") |
| 1165 | select_anime(anime_dict) | 1173 | select_anime(anime_dict) |
| 1166 | 1174 | ||
| @@ -1300,6 +1308,7 @@ while True: | |||
| 1300 | print("bye") | 1308 | print("bye") |
| 1301 | exit(0) | 1309 | exit(0) |
| 1302 | except Exception as e: | 1310 | except Exception as e: |
| 1311 | print_error(f"Unknown:\n {e}") | ||
| 1303 | print("Unknown:\n", e) | 1312 | print("Unknown:\n", e) |
| 1304 | else: | 1313 | else: |
| 1305 | killing_error = str(result.stderr) | 1314 | killing_error = str(result.stderr) |
| @@ -1328,7 +1337,7 @@ while True: | |||
| 1328 | # print("fuck") | 1337 | # print("fuck") |
| 1329 | # print(f"Exception: {e}") | 1338 | # print(f"Exception: {e}") |
| 1330 | break | 1339 | break |
| 1331 | except ConnectionRefusedError: # doesnt work ig | 1340 | except ConnectionRefusedError: # execption is never reached ig |
| 1332 | print("Player Closed") | 1341 | print("Player Closed") |
| 1333 | # print("have a great") | 1342 | # print("have a great") |
| 1334 | # exit(0) | 1343 | # exit(0) |
| @@ -1343,7 +1352,7 @@ while True: | |||
| 1343 | finally: | 1352 | finally: |
| 1344 | binge_watching=True | 1353 | binge_watching=True |
| 1345 | try: | 1354 | try: |
| 1346 | print("binge watching") | 1355 | # print("binge watching") |
| 1347 | current_ep = int(read_tmp("ep_no")) | 1356 | current_ep = int(read_tmp("ep_no")) |
| 1348 | 1357 | ||
| 1349 | if current_ep == last_episode: | 1358 | if current_ep == last_episode: |
| @@ -1356,7 +1365,7 @@ while True: | |||
| 1356 | exit(0) | 1365 | exit(0) |
| 1357 | 1366 | ||
| 1358 | else: | 1367 | else: |
| 1359 | print(f"Starting next episode: {current_ep}") | 1368 | print(f"Starting next episode: {watching_ep}") |
| 1360 | # write_to_tmp("ep_no", str(int(current_ep)+1)) | 1369 | # write_to_tmp("ep_no", str(int(current_ep)+1)) |
| 1361 | 1370 | ||
| 1362 | if watched_percentage > mark_episode_as_completed_at: # IF BINGE WATCHING | 1371 | if watched_percentage > mark_episode_as_completed_at: # IF BINGE WATCHING |
| @@ -1369,6 +1378,7 @@ while True: | |||
| 1369 | anime_watch_history = get_all_anime(get_userconfig_value(user_config, 'history_file')) | 1378 | anime_watch_history = get_all_anime(get_userconfig_value(user_config, 'history_file')) |
| 1370 | anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) | 1379 | anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) |
| 1371 | episode_completed = False | 1380 | episode_completed = False |
| 1381 | print("Fetching anime") | ||
| 1372 | run_script("episode_url") | 1382 | run_script("episode_url") |
| 1373 | links = load_links(f"/tmp/curd/curd_links") | 1383 | links = load_links(f"/tmp/curd/curd_links") |
| 1374 | mpv_args = [] | 1384 | mpv_args = [] |
| @@ -1385,5 +1395,7 @@ while True: | |||
| 1385 | else: | 1395 | else: |
| 1386 | exit(0) | 1396 | exit(0) |
| 1387 | except Exception as e: | 1397 | 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!") | ||
| 1389 | exit(1)\ No newline at end of file | 1401 | exit(1)\ No newline at end of file |