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