Commit ab0360518e
Unsigned
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 | ||
| 27 | 27 | discord_client_id = "1287457464148820089" |
| 28 | 28 | |
| 29 | 29 | def 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: | |
| 31 | 31 | return temp_file.read() |
| 32 | 32 | |
| 33 | 33 | def run_script(script: str): |
| @@ -35,28 +35,34 @@ def run_script(script: str): | ||
| 35 | 35 | |
| 36 | 36 | def write_to_tmp(tmp_filename:str, content:str): |
| 37 | 37 | try: |
| 38 | with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "w") as _: | |
| 38 | with open(f"/tmp/curd/curd_{tmp_filename}", "w") as _: | |
| 39 | 39 | _.write(content) |
| 40 | 40 | return True |
| 41 | 41 | 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 _: | |
| 43 | 43 | _.write(content) |
| 44 | 44 | return True |
| 45 | 45 | except: |
| 46 | print("fuck") | |
| 46 | 47 | return False |
| 47 | 48 | |
| 48 | 49 | def read_tmp(tmp_filename:str): |
| 49 | 50 | try: |
| 50 | with open(f"{current_dir}/scripts/tmp/{tmp_filename}", "r") as _: | |
| 51 | with open(f"/tmp/curd/curd_{tmp_filename}", "r") as _: | |
| 51 | 52 | content = _.read() |
| 52 | 53 | return content |
| 53 | 54 | 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 _: | |
| 55 | 56 | _.write("") |
| 56 | 57 | return "" |
| 57 | 58 | except: |
| 59 | print("fuck") | |
| 58 | 60 | return False |
| 59 | 61 | |
| 62 | # write_to_tmp("id", "this") | |
| 63 | # print(read_tmp("id")) | |
| 64 | # exit(0) | |
| 65 | ||
| 60 | 66 | def download_anilist_data(access_token, user_id): |
| 61 | 67 | ''' dowlnoad anilist user data''' |
| 62 | 68 | # print("downloading user data") |
| @@ -184,9 +190,9 @@ def load_config() -> dict: | ||
| 184 | 190 | current_dir = Path(__file__).parent |
| 185 | 191 | # current_dir = os.path.dirname(os.path.abspath(__file__)) |
| 186 | 192 | # print(current_dir) |
| 187 | if not os.path.exists(f"{current_dir}/scripts/tmp/"): | |
| 193 | if not os.path.exists(f"/tmp/curd/"): | |
| 188 | 194 | try: |
| 189 | os.makedirs(os.path.dirname(f"{current_dir}/scripts/tmp/")) | |
| 195 | os.makedirs(os.path.dirname(f"/tmp/curd/")) | |
| 190 | 196 | except: |
| 191 | 197 | pass |
| 192 | 198 | |
| @@ -240,7 +246,7 @@ select_anime(anime_dict) | ||
| 240 | 246 | anime_name = read_tmp("anime") |
| 241 | 247 | write_to_tmp("query", anime_name) |
| 242 | 248 | run_script("anime_list") |
| 243 | anime_dict = load_anime_data(f"{current_dir}/scripts/tmp/anime_list") | |
| 249 | anime_dict = load_anime_data(f"/tmp/curd/curd_anime_list") | |
| 244 | 250 | cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() # clean anime name |
| 245 | 251 | |
| 246 | 252 | try: |
| @@ -332,7 +338,7 @@ else: | ||
| 332 | 338 | print("Anime not found.") |
| 333 | 339 | exit(1) |
| 334 | 340 | |
| 335 | links = load_links(f"{current_dir}/scripts/tmp/links") | |
| 341 | links = load_links(f"/tmp/curd/curd_links") | |
| 336 | 342 | |
| 337 | 343 | if get_userconfig_value(user_config, "discord_presence") == True: |
| 338 | 344 | from pypresence import Presence |
| @@ -347,11 +353,11 @@ while True: | ||
| 347 | 353 | salt = random.randint(0,1500) |
| 348 | 354 | # print("SALT IS:"+str(salt)) |
| 349 | 355 | 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) | |
| 351 | 357 | connect_mpv_command = """echo '{ "command": ["get_property", "playback-time"] }' | socat - """+mpv_socket_path |
| 352 | 358 | is_paused = False |
| 353 | 359 | while True: |
| 354 | time.sleep(2) | |
| 360 | time.sleep(1) | |
| 355 | 361 | result = subprocess.run(connect_mpv_command, shell=True, capture_output=True, text=True) |
| 356 | 362 | # print(result) |
| 357 | 363 | if result.returncode == 0: |
| @@ -359,6 +365,7 @@ while True: | ||
| 359 | 365 | if not output: # Check if output is empty |
| 360 | 366 | print("No data received. Retrying...") |
| 361 | 367 | try: |
| 368 | time.sleep(1) | |
| 362 | 369 | data = json.loads(output) |
| 363 | 370 | if data["error"] == "success": |
| 364 | 371 | playback_time = round(int(data["data"]), 2) |
| @@ -481,7 +488,7 @@ while True: | ||
| 481 | 488 | anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) |
| 482 | 489 | episode_completed = False |
| 483 | 490 | run_script("episode_url") |
| 484 | links = load_links(f"{current_dir}/scripts/tmp/links") | |
| 491 | links = load_links(f"/tmp/curd/curd_links") | |
| 485 | 492 | mpv_args = [] |
| 486 | 493 | watched_percentage = 0 |
| 487 | 494 | |
| @@ -496,4 +503,5 @@ while True: | ||
| 496 | 503 | else: |
| 497 | 504 | exit(0) |
| 498 | 505 | 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 | ||
| 23 | 23 | |
| 24 | 24 | # Read the entire file content into a variable |
| 25 | 25 | script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 26 | query=$(cat $script_dir/tmp/query) # This is a shorthand for cat "$filename" | |
| 26 | query=$(cat /tmp/curd/curd_query) # This is a shorthand for cat "$filename" | |
| 27 | 27 | |
| 28 | 28 | # query="one piece" |
| 29 | 29 | anime_list=$(search_anime "$query") |
| 30 | 30 | |
| 31 | echo $anime_list > $script_dir/tmp/anime_list | |
| 31 | echo $anime_list > /tmp/curd/curd_anime_list | |
scripts/episode_list.sh +2 −2
| @@ -22,5 +22,5 @@ case "$(uname -a)" in | ||
| 22 | 22 | *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS |
| 23 | 23 | esac |
| 24 | 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 | |
| 25 | id=$(cat /tmp/curd/curd_id) | |
| 26 | echo $(episodes_list "$id") > /tmp/curd/curd_episode_list | |
scripts/episode_url.sh +4 −4
| @@ -77,7 +77,7 @@ get_episode_url() { | ||
| 77 | 77 | links=$(cat "$cache_dir"/* | sed 's|^Mp4-||g;/http/!d' | sort -g -r -s) |
| 78 | 78 | rm -r "$cache_dir" |
| 79 | 79 | episode=$(select_quality "$quality") |
| 80 | echo $links > $script_dir/tmp/links | |
| 80 | echo $links > /tmp/curd/curd_links | |
| 81 | 81 | [ -z "$episode" ] && die "Episode not released!" |
| 82 | 82 | } |
| 83 | 83 | |
| @@ -86,7 +86,7 @@ agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefo | ||
| 86 | 86 | allanime_refr="https://allanime.to" |
| 87 | 87 | allanime_base="allanime.day" |
| 88 | 88 | allanime_api="https://api.${allanime_base}" |
| 89 | sub_or_dub=$(cat $script_dir/tmp/mode) | |
| 89 | sub_or_dub=$(cat /tmp/curd/curd_mode) | |
| 90 | 90 | mode="${ANI_CLI_MODE:-$sub_or_dub}" |
| 91 | 91 | download_dir="${ANI_CLI_DOWNLOAD_DIR:-.}" |
| 92 | 92 | quality="${ANI_CLI_QUALITY:-best}" |
| @@ -98,6 +98,6 @@ case "$(uname -a)" in | ||
| 98 | 98 | *ish*) player_function="${ANI_CLI_PLAYER:-iSH}" ;; # iOS (iSH) |
| 99 | 99 | *) player_function="${ANI_CLI_PLAYER:-mpv}" ;; # Linux OS |
| 100 | 100 | esac |
| 101 | id=$(cat $script_dir/tmp/id) | |
| 102 | ep_no=$(cat $script_dir/tmp/ep_no) | |
| 101 | id=$(cat /tmp/curd/curd_id) | |
| 102 | ep_no=$(cat /tmp/curd/curd_ep_no) | |
| 103 | 103 | get_episode_url |
select_anime.py +2 −2
| @@ -135,10 +135,10 @@ def select_anime(anime_list): | ||
| 135 | 135 | |
| 136 | 136 | # Print selected anime and its ID after exiting curses mode |
| 137 | 137 | # 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: | |
| 139 | 139 | anime_name.write(selected_anime) |
| 140 | 140 | |
| 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: | |
| 142 | 142 | id_file.write(str(selected_id)) |
| 143 | 143 | |
| 144 | 144 | return True |
select_link.py +2 −2
| @@ -48,7 +48,7 @@ def display_links(stdscr, links): | ||
| 48 | 48 | stdscr.clear() |
| 49 | 49 | stdscr.addstr(0, 0, f"Selected URL: {links[selected_index][1]}") |
| 50 | 50 | # 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: | |
| 52 | 52 | temp.write(links[selected_index][1]) |
| 53 | 53 | stdscr.refresh() |
| 54 | 54 | # stdscr.getch() # Wait for any key press to exit |
| @@ -58,7 +58,7 @@ def display_links(stdscr, links): | ||
| 58 | 58 | break |
| 59 | 59 | |
| 60 | 60 | def 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 | |
| 62 | 62 | links = load_links(filename) |
| 63 | 63 | print("printed", display_links(stdscr, links)) |
| 64 | 64 | print("done") |
start_video.py +2 −2
| @@ -9,12 +9,12 @@ def start_video(link, salt:str, args:list=[]): | ||
| 9 | 9 | args_str = ' '.join(args) |
| 10 | 10 | |
| 11 | 11 | # 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}" | |
| 13 | 13 | |
| 14 | 14 | subprocess.Popen(command, shell=True) |
| 15 | 15 | # os.system() |
| 16 | 16 | # Path to the MPV socket |
| 17 | # socket_path = f'/tmp/mpvsocket{salt}' | |
| 17 | # socket_path = f'/tmp/curd/mpvsocket{salt}' | |
| 18 | 18 | # Connect to the MPV IPC socket |
| 19 | 19 | # client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
| 20 | 20 | # client.connect(socket_path) |