| @@ -27,7 +27,7 @@ from track_anime import add_anime, update_anime, get_all_anime, delete_anime, fi |
| 27 | discord_client_id = "1287457464148820089" |
27 | discord_client_id = "1287457464148820089" |
| 28 | |
28 | |
| 29 | def get_contents_of(tmp_file_name): |
29 | def get_contents_of(tmp_file_name): |
| 30 | with open(f"{current_dir}/scripts/tmp/{tmp_file_name}", "r") as temp_file: |
30 | with open(f"/tmp/curd/curd_{tmp_file_name}", "r") as temp_file: |
| 31 | return temp_file.read() |
31 | return temp_file.read() |
| 32 | |
32 | |
| 33 | def run_script(script: str): |
33 | def run_script(script: str): |
| @@ -35,28 +35,34 @@ def run_script(script: str): |
| 35 | |
35 | |
| 36 | def write_to_tmp(tmp_filename:str, content:str): |
36 | def write_to_tmp(tmp_filename:str, content:str): |
| 37 | try: |
37 | try: |
| 38 | with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "w") as _: |
38 | with open(f"/tmp/curd/curd_{tmp_filename}", "w") as _: |
| 39 | _.write(content) |
39 | _.write(content) |
| 40 | return True |
40 | return True |
| 41 | except FileNotFoundError: |
41 | except FileNotFoundError: |
| 42 | with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "w") as _: |
42 | with open(f"/tmp/curd/curd_{tmp_filename}", "w") as _: |
| 43 | _.write(content) |
43 | _.write(content) |
| 44 | return True |
44 | return True |
| 45 | except: |
45 | except: |
| |
46 | print("fuck") |
| 46 | return False |
47 | return False |
| 47 | |
48 | |
| 48 | def read_tmp(tmp_filename:str): |
49 | def read_tmp(tmp_filename:str): |
| 49 | try: |
50 | try: |
| 50 | with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "r") as _: |
51 | with open(f"/tmp/curd/curd_{tmp_filename}", "r") as _: |
| 51 | content = _.read() |
52 | content = _.read() |
| 52 | return content |
53 | return content |
| 53 | except FileNotFoundError: |
54 | except FileNotFoundError: |
| 54 | with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "w") as _: |
55 | with open(f"/tmp/curd/curd_{tmp_filename}", "w") as _: |
| 55 | _.write("") |
56 | _.write("") |
| 56 | return "" |
57 | return "" |
| 57 | except: |
58 | except: |
| |
59 | print("fuck") |
| 58 | return False |
60 | return False |
| 59 | |
61 | |
| |
62 | # write_to_tmp("id", "this") |
| |
63 | # print(read_tmp("id")) |
| |
64 | # exit(0) |
| |
65 | |
| 60 | def download_anilist_data(access_token, user_id): |
66 | def download_anilist_data(access_token, user_id): |
| 61 | ''' dowlnoad anilist user data''' |
67 | ''' dowlnoad anilist user data''' |
| 62 | # print("downloading user data") |
68 | # print("downloading user data") |
| @@ -184,9 +190,9 @@ def load_config() -> dict: |
| 184 | current_dir = Path(__file__).parent |
190 | current_dir = Path(__file__).parent |
| 185 | # current_dir = os.path.dirname(os.path.abspath(__file__)) |
191 | # current_dir = os.path.dirname(os.path.abspath(__file__)) |
| 186 | # print(current_dir) |
192 | # print(current_dir) |
| 187 | if not os.path.exists(f"{current_dir}/scripts/tmp/"): |
193 | if not os.path.exists(f"/tmp/curd/"): |
| 188 | try: |
194 | try: |
| 189 | os.makedirs(os.path.dirname(f"{current_dir}/scripts/tmp/")) |
195 | os.makedirs(os.path.dirname(f"/tmp/curd/")) |
| 190 | except: |
196 | except: |
| 191 | pass |
197 | pass |
| 192 | |
198 | |
| @@ -240,7 +246,7 @@ select_anime(anime_dict) |
| 240 | anime_name = read_tmp("anime") |
246 | anime_name = read_tmp("anime") |
| 241 | write_to_tmp("query", anime_name) |
247 | write_to_tmp("query", anime_name) |
| 242 | run_script("anime_list") |
248 | run_script("anime_list") |
| 243 | anime_dict = load_anime_data(f"{current_dir}/scripts/tmp/anime_list") |
249 | anime_dict = load_anime_data(f"/tmp/curd/curd_anime_list") |
| 244 | cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name |
250 | cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name |
| 245 | |
251 | |
| 246 | try: |
252 | try: |
| @@ -332,7 +338,7 @@ else: |
| 332 | print("Anime not found.") |
338 | print("Anime not found.") |
| 333 | exit(1) |
339 | exit(1) |
| 334 | |
340 | |
| 335 | links = load_links(f"{current_dir}/scripts/tmp/links") |
341 | links = load_links(f"/tmp/curd/curd_links") |
| 336 | |
342 | |
| 337 | if get_userconfig_value(user_config, "discord_presence") == True: |
343 | if get_userconfig_value(user_config, "discord_presence") == True: |
| 338 | from pypresence import Presence |
344 | from pypresence import Presence |
| @@ -347,11 +353,11 @@ while True: |
| 347 | salt = random.randint(0,1500) |
353 | salt = random.randint(0,1500) |
| 348 | # print("SALT IS:"+str(salt)) |
354 | # print("SALT IS:"+str(salt)) |
| 349 | start_video(links[0][1], salt, mpv_args) |
355 | start_video(links[0][1], salt, mpv_args) |
| 350 | mpv_socket_path = "/tmp/mpvsocket"+str(salt) |
356 | mpv_socket_path = "/tmp/curd/curd_mpvsocket"+str(salt) |
| 351 | connect_mpv_command = """echo '{ "command": ["get_property", "playback-time"] }' | socat - """+mpv_socket_path |
357 | connect_mpv_command = """echo '{ "command": ["get_property", "playback-time"] }' | socat - """+mpv_socket_path |
| 352 | is_paused = False |
358 | is_paused = False |
| 353 | while True: |
359 | while True: |
| 354 | time.sleep(2) |
360 | time.sleep(1) |
| 355 | result = subprocess.run(connect_mpv_command, shell=True, capture_output=True, text=True) |
361 | result = subprocess.run(connect_mpv_command, shell=True, capture_output=True, text=True) |
| 356 | # print(result) |
362 | # print(result) |
| 357 | if result.returncode == 0: |
363 | if result.returncode == 0: |
| @@ -359,6 +365,7 @@ while True: |
| 359 | if not output: # Check if output is empty |
365 | if not output: # Check if output is empty |
| 360 | print("No data received. Retrying...") |
366 | print("No data received. Retrying...") |
| 361 | try: |
367 | try: |
| |
368 | time.sleep(1) |
| 362 | data = json.loads(output) |
369 | data = json.loads(output) |
| 363 | if data["error"] == "success": |
370 | if data["error"] == "success": |
| 364 | playback_time = round(int(data["data"]), 2) |
371 | playback_time = round(int(data["data"]), 2) |
| @@ -481,7 +488,7 @@ while True: |
| 481 | anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) |
488 | anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) |
| 482 | episode_completed = False |
489 | episode_completed = False |
| 483 | run_script("episode_url") |
490 | run_script("episode_url") |
| 484 | links = load_links(f"{current_dir}/scripts/tmp/links") |
491 | links = load_links(f"/tmp/curd/curd_links") |
| 485 | mpv_args = [] |
492 | mpv_args = [] |
| 486 | watched_percentage = 0 |
493 | watched_percentage = 0 |
| 487 | |
494 | |
| @@ -496,4 +503,5 @@ while True: |
| 496 | else: |
503 | else: |
| 497 | exit(0) |
504 | exit(0) |
| 498 | except Exception as e: |
505 | except Exception as e: |
| 499 | print(f"error:{e}\nMaybe try running again!")\ No newline at end of file |
506 | print(f"error:{e}\nMaybe try running again!") |
| |
507 | exit(1)\ No newline at end of file |