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
25mark_episode_as_completed_at = 85 25mark_episode_as_completed_at = 85
26 26
27def get_contents_of(tmp_file_name): 27def 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:
29 return temp_file.read() 29 return temp_file.read()
30 30
31def run_script(script: str): 31def run_script(script: str):
32 os.system(f"./scripts/{script}.sh") 32 os.system(f"{current_dir}/scripts/{script}.sh")
33 33
34def write_to_tmp(tmp_filename:str, content:str): 34def write_to_tmp(tmp_filename:str, content:str):
35 try: 35 try:
36 with open(f"scripts/tmp/{tmp_filename}", "w") as _: 36 with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "w") as _:
37 _.write(content) 37 _.write(content)
38 return True 38 return True
39 except FileNotFoundError: 39 except FileNotFoundError:
40 with open(f"./scripts/tmp/tmp_filename", "w") as _: 40 with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "w") as _:
41 _.write(content) 41 _.write(content)
42 return True 42 return True
43 except: 43 except:
@@ -45,11 +45,11 @@ def write_to_tmp(tmp_filename:str, content:str):
45 45
46def read_tmp(tmp_filename:str): 46def read_tmp(tmp_filename:str):
47 try: 47 try:
48 with open(f"scripts/tmp/{tmp_filename}", "r") as _: 48 with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "r") as _:
49 content = _.read() 49 content = _.read()
50 return content 50 return content
51 except FileNotFoundError: 51 except FileNotFoundError:
52 with open(f"./scripts/tmp/tmp_filename", "w") as _: 52 with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "w") as _:
53 _.write("") 53 _.write("")
54 return "" 54 return ""
55 except: 55 except:
@@ -167,9 +167,11 @@ def load_config() -> dict:
167 167
168# START OF SCRIPT 168# START OF SCRIPT
169 169
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/"):
171 try: 173 try:
172 os.makedirs(os.path.dirname("./scripts/tmp/")) 174 os.makedirs(os.path.dirname(f"{current_dir}/scripts/tmp/"))
173 except: 175 except:
174 pass 176 pass
175 177
@@ -192,7 +194,7 @@ if os.path.exists(access_token_path):
192 with open(access_token_path, "r") as token_file: 194 with open(access_token_path, "r") as token_file:
193 access_token = token_file.read().strip() 195 access_token = token_file.read().strip()
194 # print(f"Token found: {access_token}") 196 # print(f"Token found: {access_token}")
195 197
196else: 198else:
197 print("Generate the token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token ") 199 print("Generate the token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token ")
198 access_token = input("Token file not found. Please generate and enter your token: ") 200 access_token = input("Token file not found. Please generate and enter your token: ")
@@ -222,7 +224,7 @@ select_anime(anime_dict)
222anime_name = read_tmp("anime") 224anime_name = read_tmp("anime")
223write_to_tmp("query", anime_name) 225write_to_tmp("query", anime_name)
224run_script("anime_list") 226run_script("anime_list")
225anime_dict = load_anime_data("scripts/tmp/anime_list") 227anime_dict = load_anime_data(f"{current_dir}/scripts/tmp/anime_list")
226cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name 228cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name
227 229
228try: 230try:
@@ -303,7 +305,7 @@ else: # if history does not exist
303 watching_ep = int(progress)+1 305 watching_ep = int(progress)+1
304 write_to_tmp("ep_no", str(watching_ep)) 306 write_to_tmp("ep_no", str(watching_ep))
305 307
306# os.system("./scripts/episode_url.sh") 308# os.system("{current_dir}/scripts/episode_url.sh")
307run_script("episode_url") 309run_script("episode_url")
308 310
309# Print the result 311# Print the result
@@ -314,7 +316,7 @@ else:
314 print("Anime not found.") 316 print("Anime not found.")
315 exit(1) 317 exit(1)
316 318
317links = load_links("scripts/tmp/links") 319links = load_links(f"{current_dir}/scripts/tmp/links")
318 320
319while True: 321while True:
320 322
@@ -434,7 +436,7 @@ while True:
434 anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) 436 anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id"))
435 episode_completed = False 437 episode_completed = False
436 run_script("episode_url") 438 run_script("episode_url")
437 links = load_links("scripts/tmp/links") 439 links = load_links(f"{current_dir}/scripts/tmp/links")
438 mpv_args = [] 440 mpv_args = []
439 watched_percentage = 0 441 watched_percentage = 0
440 442
scripts/anime_list.sh +3 −2
@@ -22,9 +22,10 @@ case "$(uname -a)" in
22esac 22esac
23 23
24# Read the entire file content into a variable 24# 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"
26 27
27# query="one piece" 28# query="one piece"
28anime_list=$(search_anime "$query") 29anime_list=$(search_anime "$query")
29 30
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
21 *ish*) player_function="${ANI_CLI_PLAYER:-iSH}" ;; # iOS (iSH) 21 *ish*) player_function="${ANI_CLI_PLAYER:-iSH}" ;; # iOS (iSH)
22 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS 22 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS
23esac 23esac
24 24script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
25id=$(cat ./scripts/tmp/id) 25id=$(cat $script_dir/tmp/id)
26echo $(episodes_list "$id") > ./scripts/tmp/episode_list 26echo $(episodes_list "$id") > $script_dir/tmp/episode_list
scripts/episode_url.sh +5 −5
@@ -57,6 +57,7 @@ select_quality() {
57 printf "%s" "$result" | cut -d'>' -f2 57 printf "%s" "$result" | cut -d'>' -f2
58} 58}
59 59
60script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
60# # gets embed urls, collects direct links into provider files, selects one with desired quality into $episode 61# # gets embed urls, collects direct links into provider files, selects one with desired quality into $episode
61get_episode_url() { 62get_episode_url() {
62 # get the embed urls of the selected episode 63 # get the embed urls of the selected episode
@@ -75,7 +76,7 @@ get_episode_url() {
75 links=$(cat "$cache_dir"/* | sed 's|^Mp4-||g;/http/!d' | sort -g -r -s) 76 links=$(cat "$cache_dir"/* | sed 's|^Mp4-||g;/http/!d' | sort -g -r -s)
76 rm -r "$cache_dir" 77 rm -r "$cache_dir"
77 episode=$(select_quality "$quality") 78 episode=$(select_quality "$quality")
78 echo $links > ./scripts/tmp/links 79 echo $links > $script_dir/tmp/links
79 [ -z "$episode" ] && die "Episode not released!" 80 [ -z "$episode" ] && die "Episode not released!"
80} 81}
81 82
@@ -84,7 +85,7 @@ agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefo
84allanime_refr="https://allanime.to" 85allanime_refr="https://allanime.to"
85allanime_base="allanime.day" 86allanime_base="allanime.day"
86allanime_api="https://api.${allanime_base}" 87allanime_api="https://api.${allanime_base}"
87sub_or_dub=$(cat ./scripts/tmp/mode) 88sub_or_dub=$(cat $script_dir/tmp/mode)
88mode="${ANI_CLI_MODE:-$sub_or_dub}" 89mode="${ANI_CLI_MODE:-$sub_or_dub}"
89download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}" 90download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}"
90quality="${ANI_CLI_QUALITY:-best}" 91quality="${ANI_CLI_QUALITY:-best}"
@@ -96,7 +97,6 @@ case "$(uname -a)" in
96 *ish*) player_function="${ANI_CLI_PLAYER:-iSH}" ;; # iOS (iSH) 97 *ish*) player_function="${ANI_CLI_PLAYER:-iSH}" ;; # iOS (iSH)
97 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS 98 *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS
98esac 99esac
99 100id=$(cat $script_dir/tmp/id)
100id=$(cat ./scripts/tmp/id) 101ep_no=$(cat $script_dir/tmp/ep_no)
101ep_no=$(cat ./scripts/tmp/ep_no)
102get_episode_url 102get_episode_url
select_anime.py +4 −3
@@ -1,7 +1,8 @@
1
2import curses 1import curses
2import os
3 3
4# Sample dictionary of anime names and their IDs 4# Sample dictionary of anime names and their IDs
5current_dir = os.path.dirname(os.path.abspath(__file__))
5 6
6def load_anime_data(filename): 7def load_anime_data(filename):
7 anime_list = {} 8 anime_list = {}
@@ -134,10 +135,10 @@ def select_anime(anime_list):
134 135
135 # Print selected anime and its ID after exiting curses mode 136 # Print selected anime and its ID after exiting curses mode
136 print(f"Selected Anime: {selected_anime}, ID: {selected_id}") 137 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:
138 anime_name.write(selected_anime) 139 anime_name.write(selected_anime)
139 140
140 with open("scripts/tmp/id", "w") as id_file: 141 with open(f"{current_dir}/scripts/tmp/id", "w") as id_file:
141 id_file.write(str(selected_id)) 142 id_file.write(str(selected_id))
142 143
143 return True 144 return True
select_link.py +5 −2
@@ -1,5 +1,8 @@
1import curses 1import curses
2import re 2import re
3import os
4
5current_dir = os.path.dirname(os.path.abspath(__file__))
3 6
4def load_links(filename): 7def load_links(filename):
5 links = [] 8 links = []
@@ -45,7 +48,7 @@ def display_links(stdscr, links):
45 stdscr.clear() 48 stdscr.clear()
46 stdscr.addstr(0, 0, f"Selected URL: {links[selected_index][1]}") 49 stdscr.addstr(0, 0, f"Selected URL: {links[selected_index][1]}")
47 # print("done") 50 # print("done")
48 with open("scripts/tmp/link", "w") as temp: 51 with open(f"{current_dir}/scripts/tmp/link", "w") as temp:
49 temp.write(links[selected_index][1]) 52 temp.write(links[selected_index][1])
50 stdscr.refresh() 53 stdscr.refresh()
51 # stdscr.getch() # Wait for any key press to exit 54 # stdscr.getch() # Wait for any key press to exit
@@ -55,7 +58,7 @@ def display_links(stdscr, links):
55 break 58 break
56 59
57def main(stdscr): 60def 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
59 links = load_links(filename) 62 links = load_links(filename)
60 print("printed", display_links(stdscr, links)) 63 print("printed", display_links(stdscr, links))
61 print("done") 64 print("done")
start_video.py +1 −1
@@ -11,7 +11,7 @@ def start_video(link, salt:str, args:list=[]):
11 # Build the complete command string 11 # Build the complete command string
12 command = f"mpv {args_str} --input-ipc-server=/tmp/mpvsocket{salt} {link}" 12 command = f"mpv {args_str} --input-ipc-server=/tmp/mpvsocket{salt} {link}"
13 13
14 subprocess.Popen(['alacritty', '-e', 'bash', '-c', command]) 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/mpvsocket{salt}'