Commit 5d7f5e9617
Unsigned
Layout: unified · split
curd.py +50 −12
| @@ -6,6 +6,11 @@ | |||
| 6 | import re | 6 | import re |
| 7 | import os | 7 | import os |
| 8 | import json | 8 | import json |
| 9 | import socket | ||
| 10 | import random | ||
| 11 | import subprocess | ||
| 12 | import time | ||
| 13 | |||
| 9 | from anilist import search_anime_by_title | 14 | from anilist import search_anime_by_title |
| 10 | from anilist import get_user_data | 15 | from anilist import get_user_data |
| 11 | from select_link import load_links | 16 | from select_link import load_links |
| @@ -14,19 +19,16 @@ from select_anime import load_anime_data | |||
| 14 | from select_anime import extract_anime_info | 19 | from select_anime import extract_anime_info |
| 15 | from select_anime import select_anime | 20 | from select_anime import select_anime |
| 16 | 21 | ||
| 22 | |||
| 17 | access_token = os.environ.get('ANILIST_ACCESS_TOKEN') | 23 | access_token = os.environ.get('ANILIST_ACCESS_TOKEN') |
| 18 | user_id = os.environ.get('ANILIST_USER_ID') | 24 | user_id = os.environ.get('ANILIST_USER_ID') |
| 19 | 25 | ||
| 20 | # print(access_token) | 26 | # print(access_token) |
| 21 | # print(user_id) | 27 | # print(user_id) |
| 22 | 28 | ||
| 23 | |||
| 24 | def run_script(script): | 29 | def run_script(script): |
| 25 | os.system(f"./scripts/{script}.sh") | 30 | os.system(f"./scripts/{script}.sh") |
| 26 | 31 | ||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | print("downloading user data") | 32 | print("downloading user data") |
| 31 | anilist_user_data = get_user_data(access_token, user_id) | 33 | anilist_user_data = get_user_data(access_token, user_id) |
| 32 | with open("response.json", "w") as response: | 34 | with open("response.json", "w") as response: |
| @@ -54,7 +56,6 @@ except: | |||
| 54 | # print(type(data['data'])) | 56 | # print(type(data['data'])) |
| 55 | 57 | ||
| 56 | 58 | ||
| 57 | |||
| 58 | anime_dict = extract_anime_info(anilist_user_data)[0] | 59 | anime_dict = extract_anime_info(anilist_user_data)[0] |
| 59 | # print(anime_dict) | 60 | # print(anime_dict) |
| 60 | # anime_dict = load_anime_data("scripts/tmp/anime_list") | 61 | # anime_dict = load_anime_data("scripts/tmp/anime_list") |
| @@ -115,14 +116,14 @@ while True: | |||
| 115 | temp = ep_list.read() | 116 | temp = ep_list.read() |
| 116 | temp = temp.split() | 117 | temp = temp.split() |
| 117 | last_episode = int(temp[-1]) | 118 | last_episode = int(temp[-1]) |
| 118 | 119 | ||
| 119 | if progress == last_episode: | 120 | if progress == last_episode: |
| 120 | user_input = input("Do you want to start this anime from beginning?") | 121 | user_input = input("Do you want to start this anime from beginning? (y/n):") |
| 121 | if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "": | 122 | if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "": |
| 122 | progress = 0 | 123 | progress = 0 |
| 123 | else: | 124 | else: |
| 124 | progress = last_episode - 1 | 125 | progress = last_episode - 1 |
| 125 | 126 | ||
| 126 | # print(progress) | 127 | # print(progress) |
| 127 | ep_no_file.write(str(progress+1)) | 128 | ep_no_file.write(str(progress+1)) |
| 128 | 129 | ||
| @@ -138,15 +139,52 @@ while True: | |||
| 138 | # link = links.read() | 139 | # link = links.read() |
| 139 | 140 | ||
| 140 | links = load_links("scripts/tmp/links") | 141 | links = load_links("scripts/tmp/links") |
| 141 | 142 | ||
| 142 | try: | 143 | try: |
| 143 | start_video(links[0][1]) | 144 | salt = random.randint(0,500) |
| 145 | print("SALT IS:"+str(salt)) | ||
| 146 | start_video(links[0][1], salt) | ||
| 147 | # print('test') | ||
| 148 | command = """echo '{ "command": ["get_property", "playback-time"] }' | socat - /tmp/mpvsocket"""+str(salt) | ||
| 149 | while True: | ||
| 150 | time.sleep(2) | ||
| 151 | |||
| 152 | result = subprocess.run(command, shell=True, capture_output=True, text=True) | ||
| 153 | # print(result) | ||
| 154 | if result.returncode == 0: | ||
| 155 | output = result.stdout.strip() | ||
| 156 | |||
| 157 | if not output: # Check if output is empty | ||
| 158 | print("No data received. Retrying...") | ||
| 159 | try: | ||
| 160 | data = json.loads(output) | ||
| 161 | if data["error"] == "success": | ||
| 162 | playback_time = round(int(data["data"])) | ||
| 163 | print("Playback time:", playback_time) | ||
| 164 | else: | ||
| 165 | print("Error:", data["error"]) | ||
| 166 | break | ||
| 167 | |||
| 168 | except json.decoder.JSONDecodeError as e: | ||
| 169 | print("Error decoding JSON:", e) | ||
| 170 | break # Exit the loop on unexpected JSON error | ||
| 171 | else: | ||
| 172 | print("Error:", result.stderr) | ||
| 173 | break | ||
| 174 | |||
| 175 | # break | ||
| 176 | # Define the command to run | ||
| 177 | |||
| 178 | # Execute the command and capture the output | ||
| 179 | # result = subprocess.run(command, capture_output=True, text=True) | ||
| 180 | |||
| 144 | except ConnectionRefusedError: | 181 | except ConnectionRefusedError: |
| 145 | print("Player Closed") | 182 | print("Player Closed") |
| 183 | finally: | ||
| 146 | to_continue_or_not_to_continue = input("Continue? (y/n)\n") | 184 | to_continue_or_not_to_continue = input("Continue? (y/n)\n") |
| 147 | if to_continue_or_not_to_continue.lower() == "yes" or to_continue_or_not_to_continue.lower() == "y" or to_continue_or_not_to_continue == "": | 185 | if to_continue_or_not_to_continue.lower() == "yes" or to_continue_or_not_to_continue.lower() == "y" or to_continue_or_not_to_continue == "": |
| 148 | pass | 186 | pass |
| 149 | else: | 187 | else: |
| 150 | break | 188 | break |
| 151 | # except: | 189 | # except: |
| 152 | # pass\ No newline at end of file | 190 | # pass\ No newline at end of file |