Commit aba2e74c2f
Unsigned
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 | |||
| 25 | mark_episode_as_completed_at = 85 | 25 | mark_episode_as_completed_at = 85 |
| 26 | 26 | ||
| 27 | def get_contents_of(tmp_file_name): | 27 | def 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 | ||
| 31 | def run_script(script: str): | 31 | def run_script(script: str): |
| 32 | os.system(f"./scripts/{script}.sh") | 32 | os.system(f"{current_dir}/scripts/{script}.sh") |
| 33 | 33 | ||
| 34 | def write_to_tmp(tmp_filename:str, content:str): | 34 | def 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 | ||
| 46 | def read_tmp(tmp_filename:str): | 46 | def 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 | ||
| 170 | if not os.path.exists("./scripts/tmp/"): | 170 | current_dir = os.path.dirname(os.path.abspath(__file__)) |
| 171 | # print(current_dir) | ||
| 172 | if 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 | ||
| 196 | else: | 198 | else: |
| 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) | |||
| 222 | anime_name = read_tmp("anime") | 224 | anime_name = read_tmp("anime") |
| 223 | write_to_tmp("query", anime_name) | 225 | write_to_tmp("query", anime_name) |
| 224 | run_script("anime_list") | 226 | run_script("anime_list") |
| 225 | anime_dict = load_anime_data("scripts/tmp/anime_list") | 227 | anime_dict = load_anime_data(f"{current_dir}/scripts/tmp/anime_list") |
| 226 | cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name | 228 | cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name |
| 227 | 229 | ||
| 228 | try: | 230 | try: |
| @@ -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") |
| 307 | run_script("episode_url") | 309 | run_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 | ||
| 317 | links = load_links("scripts/tmp/links") | 319 | links = load_links(f"{current_dir}/scripts/tmp/links") |
| 318 | 320 | ||
| 319 | while True: | 321 | while 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 | |||
| 22 | esac | 22 | esac |
| 23 | 23 | ||
| 24 | # Read the entire file content into a variable | 24 | # Read the entire file content into a variable |
| 25 | query=$(cat ./scripts/tmp/query) # This is a shorthand for cat "$filename" | 25 | script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 26 | query=$(cat $script_dir/tmp/query) # This is a shorthand for cat "$filename" | ||
| 26 | 27 | ||
| 27 | # query="one piece" | 28 | # query="one piece" |
| 28 | anime_list=$(search_anime "$query") | 29 | anime_list=$(search_anime "$query") |
| 29 | 30 | ||
| 30 | echo $anime_list > ./scripts/tmp/anime_list | 31 | echo $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 |
| 23 | esac | 23 | esac |
| 24 | 24 | script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| 25 | id=$(cat ./scripts/tmp/id) | 25 | id=$(cat $script_dir/tmp/id) |
| 26 | echo $(episodes_list "$id") > ./scripts/tmp/episode_list | 26 | echo $(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 | ||
| 60 | script_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 |
| 61 | get_episode_url() { | 62 | get_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 | |||
| 84 | allanime_refr="https://allanime.to" | 85 | allanime_refr="https://allanime.to" |
| 85 | allanime_base="allanime.day" | 86 | allanime_base="allanime.day" |
| 86 | allanime_api="https://api.${allanime_base}" | 87 | allanime_api="https://api.${allanime_base}" |
| 87 | sub_or_dub=$(cat ./scripts/tmp/mode) | 88 | sub_or_dub=$(cat $script_dir/tmp/mode) |
| 88 | mode="${ANI_CLI_MODE:-$sub_or_dub}" | 89 | mode="${ANI_CLI_MODE:-$sub_or_dub}" |
| 89 | download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}" | 90 | download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}" |
| 90 | quality="${ANI_CLI_QUALITY:-best}" | 91 | quality="${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 |
| 98 | esac | 99 | esac |
| 99 | 100 | id=$(cat $script_dir/tmp/id) | |
| 100 | id=$(cat ./scripts/tmp/id) | 101 | ep_no=$(cat $script_dir/tmp/ep_no) |
| 101 | ep_no=$(cat ./scripts/tmp/ep_no) | ||
| 102 | get_episode_url | 102 | get_episode_url |
select_anime.py +4 −3
| @@ -1,7 +1,8 @@ | |||
| 1 | |||
| 2 | import curses | 1 | import curses |
| 2 | import os | ||
| 3 | 3 | ||
| 4 | # Sample dictionary of anime names and their IDs | 4 | # Sample dictionary of anime names and their IDs |
| 5 | current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
| 5 | 6 | ||
| 6 | def load_anime_data(filename): | 7 | def 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 @@ | |||
| 1 | import curses | 1 | import curses |
| 2 | import re | 2 | import re |
| 3 | import os | ||
| 4 | |||
| 5 | current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
| 3 | 6 | ||
| 4 | def load_links(filename): | 7 | def 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 | ||
| 57 | def main(stdscr): | 60 | def 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}' |