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