Commit aba2e74c2f

aba2e74c2ffe6e65cb2ee88851e2d5e50096af4a

parent: 07288a1246

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-22 03:54 UTC

run from anywhere

Layout: unified · split

curd.py +15 −13
@@ -25,19 +25,19 @@ from track_anime import add_anime, update_anime, get_all_anime, delete_anime, fi
2525mark_episode_as_completed_at = 85
2626
2727def get_contents_of(tmp_file_name):
28 with open(f"scripts/tmp/{tmp_file_name}", "r") as temp_file:
28 with open(f"{current_dir}/scripts/tmp/{tmp_file_name}", "r") as temp_file:
2929 return temp_file.read()
3030
3131def run_script(script: str):
32 os.system(f"./scripts/{script}.sh")
32 os.system(f"{current_dir}/scripts/{script}.sh")
3333
3434def write_to_tmp(tmp_filename:str, content:str):
3535 try:
36 with open(f"scripts/tmp/{tmp_filename}", "w") as _:
36 with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "w") as _:
3737 _.write(content)
3838 return True
3939 except FileNotFoundError:
40 with open(f"./scripts/tmp/tmp_filename", "w") as _:
40 with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "w") as _:
4141 _.write(content)
4242 return True
4343 except:
@@ -45,11 +45,11 @@ def write_to_tmp(tmp_filename:str, content:str):
4545
4646def read_tmp(tmp_filename:str):
4747 try:
48 with open(f"scripts/tmp/{tmp_filename}", "r") as _:
48 with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "r") as _:
4949 content = _.read()
5050 return content
5151 except FileNotFoundError:
52 with open(f"./scripts/tmp/tmp_filename", "w") as _:
52 with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "w") as _:
5353 _.write("")
5454 return ""
5555 except:
@@ -167,9 +167,11 @@ def load_config() -> dict:
167167
168168# START OF SCRIPT
169169
170if not os.path.exists("./scripts/tmp/"):
170current_dir = os.path.dirname(os.path.abspath(__file__))
171# print(current_dir)
172if not os.path.exists(f"{current_dir}/scripts/tmp/"):
171173 try:
172 os.makedirs(os.path.dirname("./scripts/tmp/"))
174 os.makedirs(os.path.dirname(f"{current_dir}/scripts/tmp/"))
173175 except:
174176 pass
175177
@@ -192,7 +194,7 @@ if os.path.exists(access_token_path):
192194 with open(access_token_path, "r") as token_file:
193195 access_token = token_file.read().strip()
194196 # print(f"Token found: {access_token}")
195
197
196198else:
197199 print("Generate the token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token ")
198200 access_token = input("Token file not found. Please generate and enter your token: ")
@@ -222,7 +224,7 @@ select_anime(anime_dict)
222224anime_name = read_tmp("anime")
223225write_to_tmp("query", anime_name)
224226run_script("anime_list")
225anime_dict = load_anime_data("scripts/tmp/anime_list")
227anime_dict = load_anime_data(f"{current_dir}/scripts/tmp/anime_list")
226228cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name
227229
228230try:
@@ -303,7 +305,7 @@ else: # if history does not exist
303305 watching_ep = int(progress)+1
304306 write_to_tmp("ep_no", str(watching_ep))
305307
306# os.system("./scripts/episode_url.sh")
308# os.system("{current_dir}/scripts/episode_url.sh")
307309run_script("episode_url")
308310
309311# Print the result
@@ -314,7 +316,7 @@ else:
314316 print("Anime not found.")
315317 exit(1)
316318
317links = load_links("scripts/tmp/links")
319links = load_links(f"{current_dir}/scripts/tmp/links")
318320
319321while True:
320322
@@ -434,7 +436,7 @@ while True:
434436 anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id"))
435437 episode_completed = False
436438 run_script("episode_url")
437 links = load_links("scripts/tmp/links")
439 links = load_links(f"{current_dir}/scripts/tmp/links")
438440 mpv_args = []
439441 watched_percentage = 0
440442
scripts/anime_list.sh +3 −2
@@ -22,9 +22,10 @@ case "$(uname -a)" in
2222esac
2323
2424# Read the entire file content into a variable
25query=$(cat ./scripts/tmp/query) # This is a shorthand for cat "$filename"
25script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
26query=$(cat $script_dir/tmp/query) # This is a shorthand for cat "$filename"
2627
2728# query="one piece"
2829anime_list=$(search_anime "$query")
2930
30echo $anime_list > ./scripts/tmp/anime_list
31echo $anime_list > $script_dir/tmp/anime_list
scripts/episode_list.sh +3 −3
@@ -21,6 +21,6 @@ case "$(uname -a)" in
2121 *ish*) player_function="${ANI_CLI_PLAYER:-iSH}" ;; # iOS (iSH)
2222 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS
2323esac
24
25id=$(cat ./scripts/tmp/id)
26echo $(episodes_list "$id") > ./scripts/tmp/episode_list
24script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
25id=$(cat $script_dir/tmp/id)
26echo $(episodes_list "$id") > $script_dir/tmp/episode_list
scripts/episode_url.sh +5 −5
@@ -57,6 +57,7 @@ select_quality() {
5757 printf "%s" "$result" | cut -d'>' -f2
5858}
5959
60script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6061# # gets embed urls, collects direct links into provider files, selects one with desired quality into $episode
6162get_episode_url() {
6263 # get the embed urls of the selected episode
@@ -75,7 +76,7 @@ get_episode_url() {
7576 links=$(cat "$cache_dir"/* | sed 's|^Mp4-||g;/http/!d' | sort -g -r -s)
7677 rm -r "$cache_dir"
7778 episode=$(select_quality "$quality")
78 echo $links > ./scripts/tmp/links
79 echo $links > $script_dir/tmp/links
7980 [ -z "$episode" ] && die "Episode not released!"
8081}
8182
@@ -84,7 +85,7 @@ agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefo
8485allanime_refr="https://allanime.to"
8586allanime_base="allanime.day"
8687allanime_api="https://api.${allanime_base}"
87sub_or_dub=$(cat ./scripts/tmp/mode)
88sub_or_dub=$(cat $script_dir/tmp/mode)
8889mode="${ANI_CLI_MODE:-$sub_or_dub}"
8990download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}"
9091quality="${ANI_CLI_QUALITY:-best}"
@@ -96,7 +97,6 @@ case "$(uname -a)" in
9697 *ish*) player_function="${ANI_CLI_PLAYER:-iSH}" ;; # iOS (iSH)
9798 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS
9899esac
99
100id=$(cat ./scripts/tmp/id)
101ep_no=$(cat ./scripts/tmp/ep_no)
100id=$(cat $script_dir/tmp/id)
101ep_no=$(cat $script_dir/tmp/ep_no)
102102get_episode_url
select_anime.py +4 −3
@@ -1,7 +1,8 @@
1
21import curses
2import os
33
44# Sample dictionary of anime names and their IDs
5current_dir = os.path.dirname(os.path.abspath(__file__))
56
67def load_anime_data(filename):
78 anime_list = {}
@@ -134,10 +135,10 @@ def select_anime(anime_list):
134135
135136 # Print selected anime and its ID after exiting curses mode
136137 print(f"Selected Anime: {selected_anime}, ID: {selected_id}")
137 with open("scripts/tmp/anime", "w") as anime_name:
138 with open(f"{current_dir}/scripts/tmp/anime", "w") as anime_name:
138139 anime_name.write(selected_anime)
139140
140 with open("scripts/tmp/id", "w") as id_file:
141 with open(f"{current_dir}/scripts/tmp/id", "w") as id_file:
141142 id_file.write(str(selected_id))
142143
143144 return True
select_link.py +5 −2
@@ -1,5 +1,8 @@
11import curses
22import re
3import os
4
5current_dir = os.path.dirname(os.path.abspath(__file__))
36
47def load_links(filename):
58 links = []
@@ -45,7 +48,7 @@ def display_links(stdscr, links):
4548 stdscr.clear()
4649 stdscr.addstr(0, 0, f"Selected URL: {links[selected_index][1]}")
4750 # print("done")
48 with open("scripts/tmp/link", "w") as temp:
51 with open(f"{current_dir}/scripts/tmp/link", "w") as temp:
4952 temp.write(links[selected_index][1])
5053 stdscr.refresh()
5154 # stdscr.getch() # Wait for any key press to exit
@@ -55,7 +58,7 @@ def display_links(stdscr, links):
5558 break
5659
5760def main(stdscr):
58 filename = 'scripts/tmp/links' # Replace with your file name
61 filename = f"{current_dir}/scripts/tmp/links" # Replace with your file name
5962 links = load_links(filename)
6063 print("printed", display_links(stdscr, links))
6164 print("done")
start_video.py +1 −1
@@ -11,7 +11,7 @@ def start_video(link, salt:str, args:list=[]):
1111 # Build the complete command string
1212 command = f"mpv {args_str} --input-ipc-server=/tmp/mpvsocket{salt} {link}"
1313
14 subprocess.Popen(['alacritty', '-e', 'bash', '-c', command])
14 subprocess.Popen(command, shell=True)
1515 # os.system()
1616 # Path to the MPV socket
1717 # socket_path = f'/tmp/mpvsocket{salt}'