Commit ab0360518e

ab0360518e67c0b141719f52595d31e1ce623886

parent: 825313f772

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-24 21:02 UTC

no more tmp folder in script

Layout: unified · split

curd.py +21 −13
@@ -27,7 +27,7 @@ from track_anime import add_anime, update_anime, get_all_anime, delete_anime, fi
27discord_client_id = "1287457464148820089" 27discord_client_id = "1287457464148820089"
28 28
29def get_contents_of(tmp_file_name): 29def 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
33def run_script(script: str): 33def run_script(script: str):
@@ -35,28 +35,34 @@ def run_script(script: str):
35 35
36def write_to_tmp(tmp_filename:str, content:str): 36def 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
48def read_tmp(tmp_filename:str): 49def 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
60def download_anilist_data(access_token, user_id): 66def 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:
184current_dir = Path(__file__).parent 190current_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)
187if not os.path.exists(f"{current_dir}/scripts/tmp/"): 193if 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)
240anime_name = read_tmp("anime") 246anime_name = read_tmp("anime")
241write_to_tmp("query", anime_name) 247write_to_tmp("query", anime_name)
242run_script("anime_list") 248run_script("anime_list")
243anime_dict = load_anime_data(f"{current_dir}/scripts/tmp/anime_list") 249anime_dict = load_anime_data(f"/tmp/curd/curd_anime_list")
244cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name 250cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name
245 251
246try: 252try:
@@ -332,7 +338,7 @@ else:
332 print("Anime not found.") 338 print("Anime not found.")
333 exit(1) 339 exit(1)
334 340
335links = load_links(f"{current_dir}/scripts/tmp/links") 341links = load_links(f"/tmp/curd/curd_links")
336 342
337if get_userconfig_value(user_config, "discord_presence") == True: 343if 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
scripts/anime_list.sh +2 −2
@@ -23,9 +23,9 @@ esac
23 23
24# Read the entire file content into a variable 24# Read the entire file content into a variable
25script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 25script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
26query=$(cat $script_dir/tmp/query) # This is a shorthand for cat "$filename" 26query=$(cat /tmp/curd/curd_query) # This is a shorthand for cat "$filename"
27 27
28# query="one piece" 28# query="one piece"
29anime_list=$(search_anime "$query") 29anime_list=$(search_anime "$query")
30 30
31echo $anime_list > $script_dir/tmp/anime_list 31echo $anime_list > /tmp/curd/curd_anime_list
scripts/episode_list.sh +2 −2
@@ -22,5 +22,5 @@ case "$(uname -a)" in
22 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS 22 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS
23esac 23esac
24script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 24script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
25id=$(cat $script_dir/tmp/id) 25id=$(cat /tmp/curd/curd_id)
26echo $(episodes_list "$id") > $script_dir/tmp/episode_list 26echo $(episodes_list "$id") > /tmp/curd/curd_episode_list
scripts/episode_url.sh +4 −4
@@ -77,7 +77,7 @@ get_episode_url() {
77 links=$(cat "$cache_dir"/* | sed 's|^Mp4-||g;/http/!d' | sort -g -r -s) 77 links=$(cat "$cache_dir"/* | sed 's|^Mp4-||g;/http/!d' | sort -g -r -s)
78 rm -r "$cache_dir" 78 rm -r "$cache_dir"
79 episode=$(select_quality "$quality") 79 episode=$(select_quality "$quality")
80 echo $links > $script_dir/tmp/links 80 echo $links > /tmp/curd/curd_links
81 [ -z "$episode" ] && die "Episode not released!" 81 [ -z "$episode" ] && die "Episode not released!"
82} 82}
83 83
@@ -86,7 +86,7 @@ agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefo
86allanime_refr="https://allanime.to" 86allanime_refr="https://allanime.to"
87allanime_base="allanime.day" 87allanime_base="allanime.day"
88allanime_api="https://api.${allanime_base}" 88allanime_api="https://api.${allanime_base}"
89sub_or_dub=$(cat $script_dir/tmp/mode) 89sub_or_dub=$(cat /tmp/curd/curd_mode)
90mode="${ANI_CLI_MODE:-$sub_or_dub}" 90mode="${ANI_CLI_MODE:-$sub_or_dub}"
91download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}" 91download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}"
92quality="${ANI_CLI_QUALITY:-best}" 92quality="${ANI_CLI_QUALITY:-best}"
@@ -98,6 +98,6 @@ case "$(uname -a)" in
98 *ish*) player_function="${ANI_CLI_PLAYER:-iSH}" ;; # iOS (iSH) 98 *ish*) player_function="${ANI_CLI_PLAYER:-iSH}" ;; # iOS (iSH)
99 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS 99 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS
100esac 100esac
101id=$(cat $script_dir/tmp/id) 101id=$(cat /tmp/curd/curd_id)
102ep_no=$(cat $script_dir/tmp/ep_no) 102ep_no=$(cat /tmp/curd/curd_ep_no)
103get_episode_url 103get_episode_url
select_anime.py +2 −2
@@ -135,10 +135,10 @@ def select_anime(anime_list):
135 135
136 # Print selected anime and its ID after exiting curses mode 136 # Print selected anime and its ID after exiting curses mode
137 # print(f"Selected Anime: {selected_anime}, ID: {selected_id}") 137 # print(f"Selected Anime: {selected_anime}, ID: {selected_id}")
138 with open(f"{current_dir}/scripts/tmp/anime", "w") as anime_name: 138 with open(f"/tmp/curd/curd_anime", "w") as anime_name:
139 anime_name.write(selected_anime) 139 anime_name.write(selected_anime)
140 140
141 with open(f"{current_dir}/scripts/tmp/id", "w") as id_file: 141 with open(f"/tmp/curd/curd_id", "w") as id_file:
142 id_file.write(str(selected_id)) 142 id_file.write(str(selected_id))
143 143
144 return True 144 return True
select_link.py +2 −2
@@ -48,7 +48,7 @@ def display_links(stdscr, links):
48 stdscr.clear() 48 stdscr.clear()
49 stdscr.addstr(0, 0, f"Selected URL: {links[selected_index][1]}") 49 stdscr.addstr(0, 0, f"Selected URL: {links[selected_index][1]}")
50 # print("done") 50 # print("done")
51 with open(f"{current_dir}/scripts/tmp/link", "w") as temp: 51 with open(f"/tmp/curd/curd_link", "w") as temp:
52 temp.write(links[selected_index][1]) 52 temp.write(links[selected_index][1])
53 stdscr.refresh() 53 stdscr.refresh()
54 # stdscr.getch() # Wait for any key press to exit 54 # stdscr.getch() # Wait for any key press to exit
@@ -58,7 +58,7 @@ def display_links(stdscr, links):
58 break 58 break
59 59
60def main(stdscr): 60def main(stdscr):
61 filename = f"{current_dir}/scripts/tmp/links" # Replace with your file name 61 filename = f"/tmp/curd/curd_links" # Replace with your file name
62 links = load_links(filename) 62 links = load_links(filename)
63 print("printed", display_links(stdscr, links)) 63 print("printed", display_links(stdscr, links))
64 print("done") 64 print("done")
start_video.py +2 −2
@@ -9,12 +9,12 @@ def start_video(link, salt:str, args:list=[]):
9 args_str = ' '.join(args) 9 args_str = ' '.join(args)
10 10
11 # Build the complete command string 11 # Build the complete command string
12 command = f"mpv {args_str} --no-terminal --really-quiet --input-ipc-server=/tmp/mpvsocket{salt} {link}" 12 command = f"mpv {args_str} --no-terminal --really-quiet --input-ipc-server=/tmp/curd/curd_mpvsocket{salt} {link}"
13 13
14 subprocess.Popen(command, shell=True) 14 subprocess.Popen(command, shell=True)
15 # os.system() 15 # os.system()
16 # Path to the MPV socket 16 # Path to the MPV socket
17 # socket_path = f'/tmp/mpvsocket{salt}' 17 # socket_path = f'/tmp/curd/mpvsocket{salt}'
18 # Connect to the MPV IPC socket 18 # Connect to the MPV IPC socket
19 # client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 19 # client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
20 # client.connect(socket_path) 20 # client.connect(socket_path)