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
2727discord_client_id = "1287457464148820089"
2828
2929def 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:
3131 return temp_file.read()
3232
3333def run_script(script: str):
@@ -35,28 +35,34 @@ def run_script(script: str):
3535
3636def write_to_tmp(tmp_filename:str, content:str):
3737 try:
38 with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "w") as _:
38 with open(f"/tmp/curd/curd_{tmp_filename}", "w") as _:
3939 _.write(content)
4040 return True
4141 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 _:
4343 _.write(content)
4444 return True
4545 except:
46 print("fuck")
4647 return False
4748
4849def read_tmp(tmp_filename:str):
4950 try:
50 with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "r") as _:
51 with open(f"/tmp/curd/curd_{tmp_filename}", "r") as _:
5152 content = _.read()
5253 return content
5354 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 _:
5556 _.write("")
5657 return ""
5758 except:
59 print("fuck")
5860 return False
5961
62# write_to_tmp("id", "this")
63# print(read_tmp("id"))
64# exit(0)
65
6066def download_anilist_data(access_token, user_id):
6167 ''' dowlnoad anilist user data'''
6268 # print("downloading user data")
@@ -184,9 +190,9 @@ def load_config() -> dict:
184190current_dir = Path(__file__).parent
185191# current_dir = os.path.dirname(os.path.abspath(__file__))
186192# print(current_dir)
187if not os.path.exists(f"{current_dir}/scripts/tmp/"):
193if not os.path.exists(f"/tmp/curd/"):
188194 try:
189 os.makedirs(os.path.dirname(f"{current_dir}/scripts/tmp/"))
195 os.makedirs(os.path.dirname(f"/tmp/curd/"))
190196 except:
191197 pass
192198
@@ -240,7 +246,7 @@ select_anime(anime_dict)
240246anime_name = read_tmp("anime")
241247write_to_tmp("query", anime_name)
242248run_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")
244250cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name
245251
246252try:
@@ -332,7 +338,7 @@ else:
332338 print("Anime not found.")
333339 exit(1)
334340
335links = load_links(f"{current_dir}/scripts/tmp/links")
341links = load_links(f"/tmp/curd/curd_links")
336342
337343if get_userconfig_value(user_config, "discord_presence") == True:
338344 from pypresence import Presence
@@ -347,11 +353,11 @@ while True:
347353 salt = random.randint(0,1500)
348354 # print("SALT IS:"+str(salt))
349355 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)
351357 connect_mpv_command = """echo '{ "command": ["get_property", "playback-time"] }' | socat - """+mpv_socket_path
352358 is_paused = False
353359 while True:
354 time.sleep(2)
360 time.sleep(1)
355361 result = subprocess.run(connect_mpv_command, shell=True, capture_output=True, text=True)
356362 # print(result)
357363 if result.returncode == 0:
@@ -359,6 +365,7 @@ while True:
359365 if not output: # Check if output is empty
360366 print("No data received. Retrying...")
361367 try:
368 time.sleep(1)
362369 data = json.loads(output)
363370 if data["error"] == "success":
364371 playback_time = round(int(data["data"]), 2)
@@ -481,7 +488,7 @@ while True:
481488 anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id"))
482489 episode_completed = False
483490 run_script("episode_url")
484 links = load_links(f"{current_dir}/scripts/tmp/links")
491 links = load_links(f"/tmp/curd/curd_links")
485492 mpv_args = []
486493 watched_percentage = 0
487494
@@ -496,4 +503,5 @@ while True:
496503 else:
497504 exit(0)
498505 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
2323
2424# Read the entire file content into a variable
2525script_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"
2727
2828# query="one piece"
2929anime_list=$(search_anime "$query")
3030
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
2222 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS
2323esac
2424script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
25id=$(cat $script_dir/tmp/id)
26echo $(episodes_list "$id") > $script_dir/tmp/episode_list
25id=$(cat /tmp/curd/curd_id)
26echo $(episodes_list "$id") > /tmp/curd/curd_episode_list
scripts/episode_url.sh +4 −4
@@ -77,7 +77,7 @@ get_episode_url() {
7777 links=$(cat "$cache_dir"/* | sed 's|^Mp4-||g;/http/!d' | sort -g -r -s)
7878 rm -r "$cache_dir"
7979 episode=$(select_quality "$quality")
80 echo $links > $script_dir/tmp/links
80 echo $links > /tmp/curd/curd_links
8181 [ -z "$episode" ] && die "Episode not released!"
8282}
8383
@@ -86,7 +86,7 @@ agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefo
8686allanime_refr="https://allanime.to"
8787allanime_base="allanime.day"
8888allanime_api="https://api.${allanime_base}"
89sub_or_dub=$(cat $script_dir/tmp/mode)
89sub_or_dub=$(cat /tmp/curd/curd_mode)
9090mode="${ANI_CLI_MODE:-$sub_or_dub}"
9191download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}"
9292quality="${ANI_CLI_QUALITY:-best}"
@@ -98,6 +98,6 @@ case "$(uname -a)" in
9898 *ish*) player_function="${ANI_CLI_PLAYER:-iSH}" ;; # iOS (iSH)
9999 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS
100100esac
101id=$(cat $script_dir/tmp/id)
102ep_no=$(cat $script_dir/tmp/ep_no)
101id=$(cat /tmp/curd/curd_id)
102ep_no=$(cat /tmp/curd/curd_ep_no)
103103get_episode_url
select_anime.py +2 −2
@@ -135,10 +135,10 @@ def select_anime(anime_list):
135135
136136 # Print selected anime and its ID after exiting curses mode
137137 # 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:
139139 anime_name.write(selected_anime)
140140
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:
142142 id_file.write(str(selected_id))
143143
144144 return True
select_link.py +2 −2
@@ -48,7 +48,7 @@ def display_links(stdscr, links):
4848 stdscr.clear()
4949 stdscr.addstr(0, 0, f"Selected URL: {links[selected_index][1]}")
5050 # 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:
5252 temp.write(links[selected_index][1])
5353 stdscr.refresh()
5454 # stdscr.getch() # Wait for any key press to exit
@@ -58,7 +58,7 @@ def display_links(stdscr, links):
5858 break
5959
6060def 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
6262 links = load_links(filename)
6363 print("printed", display_links(stdscr, links))
6464 print("done")
start_video.py +2 −2
@@ -9,12 +9,12 @@ def start_video(link, salt:str, args:list=[]):
99 args_str = ' '.join(args)
1010
1111 # 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}"
1313
1414 subprocess.Popen(command, shell=True)
1515 # os.system()
1616 # Path to the MPV socket
17 # socket_path = f'/tmp/mpvsocket{salt}'
17 # socket_path = f'/tmp/curd/mpvsocket{salt}'
1818 # Connect to the MPV IPC socket
1919 # client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
2020 # client.connect(socket_path)