Commit 5d7f5e9617

5d7f5e9617b2797043c0b4007497f38e8607987f

parent: be0622f544

Unsigned

Wraient <wraient.911@gmail.com> · 2024-08-25 20:56 UTC

playback time fetched

Layout: unified · split

curd.py +50 −12
@@ -6,6 +6,11 @@
66import re
77import os
88import json
9import socket
10import random
11import subprocess
12import time
13
914from anilist import search_anime_by_title
1015from anilist import get_user_data
1116from select_link import load_links
@@ -14,19 +19,16 @@ from select_anime import load_anime_data
1419from select_anime import extract_anime_info
1520from select_anime import select_anime
1621
22
1723access_token = os.environ.get('ANILIST_ACCESS_TOKEN')
1824user_id = os.environ.get('ANILIST_USER_ID')
1925
2026# print(access_token)
2127# print(user_id)
2228
23
2429def run_script(script):
2530 os.system(f"./scripts/{script}.sh")
2631
27
28
29
3032print("downloading user data")
3133anilist_user_data = get_user_data(access_token, user_id)
3234with open("response.json", "w") as response:
@@ -54,7 +56,6 @@ except:
5456# print(type(data['data']))
5557
5658
57
5859anime_dict = extract_anime_info(anilist_user_data)[0]
5960# print(anime_dict)
6061# anime_dict = load_anime_data("scripts/tmp/anime_list")
@@ -115,14 +116,14 @@ while True:
115116 temp = ep_list.read()
116117 temp = temp.split()
117118 last_episode = int(temp[-1])
118
119
119120 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):")
121122 if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "":
122123 progress = 0
123124 else:
124125 progress = last_episode - 1
125
126
126127 # print(progress)
127128 ep_no_file.write(str(progress+1))
128129
@@ -138,15 +139,52 @@ while True:
138139 # link = links.read()
139140
140141 links = load_links("scripts/tmp/links")
141
142
142143 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
144181 except ConnectionRefusedError:
145182 print("Player Closed")
183 finally:
146184 to_continue_or_not_to_continue = input("Continue? (y/n)\n")
147185 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 == "":
148186 pass
149187 else:
150188 break
151 # except:
152 # pass
\ No newline at end of file
189# except:
190# pass
\ No newline at end of file