Commit 5d7f5e9617
Unsigned
Layout: unified · split
curd.py +50 −12
| @@ -6,6 +6,11 @@ | ||
| 6 | 6 | import re |
| 7 | 7 | import os |
| 8 | 8 | import json |
| 9 | import socket | |
| 10 | import random | |
| 11 | import subprocess | |
| 12 | import time | |
| 13 | ||
| 9 | 14 | from anilist import search_anime_by_title |
| 10 | 15 | from anilist import get_user_data |
| 11 | 16 | from select_link import load_links |
| @@ -14,19 +19,16 @@ from select_anime import load_anime_data | ||
| 14 | 19 | from select_anime import extract_anime_info |
| 15 | 20 | from select_anime import select_anime |
| 16 | 21 | |
| 22 | ||
| 17 | 23 | access_token = os.environ.get('ANILIST_ACCESS_TOKEN') |
| 18 | 24 | user_id = os.environ.get('ANILIST_USER_ID') |
| 19 | 25 | |
| 20 | 26 | # print(access_token) |
| 21 | 27 | # print(user_id) |
| 22 | 28 | |
| 23 | ||
| 24 | 29 | def run_script(script): |
| 25 | 30 | os.system(f"./scripts/{script}.sh") |
| 26 | 31 | |
| 27 | ||
| 28 | ||
| 29 | ||
| 30 | 32 | print("downloading user data") |
| 31 | 33 | anilist_user_data = get_user_data(access_token, user_id) |
| 32 | 34 | with open("response.json", "w") as response: |
| @@ -54,7 +56,6 @@ except: | ||
| 54 | 56 | # print(type(data['data'])) |
| 55 | 57 | |
| 56 | 58 | |
| 57 | ||
| 58 | 59 | anime_dict = extract_anime_info(anilist_user_data)[0] |
| 59 | 60 | # print(anime_dict) |
| 60 | 61 | # anime_dict = load_anime_data("scripts/tmp/anime_list") |
| @@ -115,14 +116,14 @@ while True: | ||
| 115 | 116 | temp = ep_list.read() |
| 116 | 117 | temp = temp.split() |
| 117 | 118 | last_episode = int(temp[-1]) |
| 118 | ||
| 119 | ||
| 119 | 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 | 122 | if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "": |
| 122 | 123 | progress = 0 |
| 123 | 124 | else: |
| 124 | 125 | progress = last_episode - 1 |
| 125 | ||
| 126 | ||
| 126 | 127 | # print(progress) |
| 127 | 128 | ep_no_file.write(str(progress+1)) |
| 128 | 129 | |
| @@ -138,15 +139,52 @@ while True: | ||
| 138 | 139 | # link = links.read() |
| 139 | 140 | |
| 140 | 141 | links = load_links("scripts/tmp/links") |
| 141 | ||
| 142 | ||
| 142 | 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 | 181 | except ConnectionRefusedError: |
| 145 | 182 | print("Player Closed") |
| 183 | finally: | |
| 146 | 184 | to_continue_or_not_to_continue = input("Continue? (y/n)\n") |
| 147 | 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 | 186 | pass |
| 149 | 187 | else: |
| 150 | 188 | break |
| 151 | # except: | |
| 152 | # pass | |
| \ No newline at end of file | ||
| 189 | # except: | |
| 190 | # pass | |
| \ No newline at end of file | ||