Commit c2de159869
Unsigned
Layout: unified · split
curd.py +79 −40
| @@ -20,11 +20,17 @@ user_id = os.environ.get('ANILIST_USER_ID') | ||
| 20 | 20 | # print(access_token) |
| 21 | 21 | # print(user_id) |
| 22 | 22 | |
| 23 | ||
| 23 | 24 | def run_script(script): |
| 24 | 25 | os.system(f"./scripts/{script}.sh") |
| 25 | 26 | |
| 27 | ||
| 28 | ||
| 29 | ||
| 26 | 30 | print("downloading user data") |
| 27 | 31 | anilist_user_data = get_user_data(access_token, user_id) |
| 32 | with open("response.json", "w") as response: | |
| 33 | response.write(str(anilist_user_data)) | |
| 28 | 34 | try: |
| 29 | 35 | if anilist_user_data['data'] == None: |
| 30 | 36 | print("Cannot process user data.") |
| @@ -33,30 +39,40 @@ try: | ||
| 33 | 39 | except: |
| 34 | 40 | pass |
| 35 | 41 | |
| 36 | with open("scripts/tmp/query", "w") as file: | |
| 37 | file.write(input("Enter the anime you want:\n")) | |
| 42 | # Searching for anime | |
| 38 | 43 | |
| 39 | # os.system("./scripts/anime_list.sh" | |
| 44 | # with open("scripts/tmp/query", "w") as file: | |
| 45 | # file.write(input("Enter the anime you want:\n")) | |
| 46 | ||
| 47 | # os.system("./scripts/anime_list.sh") | |
| 40 | 48 | |
| 41 | run_script("anime_list") | |
| 42 | 49 | |
| 43 | with open('response.json', 'r') as file: | |
| 44 | data = json.load(file) | |
| 50 | # with open('response.json', 'r') as file: | |
| 51 | # data = json.load(file) | |
| 45 | 52 | |
| 46 | 53 | # print(data) |
| 47 | 54 | # print(type(data['data'])) |
| 48 | 55 | |
| 49 | # anime_dict = extract_anime_info(anilist_user_data)[0] | |
| 56 | ||
| 57 | ||
| 58 | anime_dict = extract_anime_info(anilist_user_data)[0] | |
| 59 | # print(anime_dict) | |
| 60 | # anime_dict = load_anime_data("scripts/tmp/anime_list") | |
| 50 | 61 | # print(anime_dict) |
| 51 | anime_dict = load_anime_data("scripts/tmp/anime_list") | |
| 52 | print(anime_dict) | |
| 53 | 62 | # print(f"ANIME DICT = {anime_dict}") |
| 63 | ||
| 54 | 64 | select_anime(anime_dict) |
| 55 | 65 | |
| 56 | 66 | with open("scripts/tmp/anime", "r") as anime: |
| 57 | 67 | anime_name = anime.read() |
| 58 | 68 | |
| 59 | # Remove everything from the last '(' including the parentheses | |
| 69 | with open("scripts/tmp/query", "w") as query_file: | |
| 70 | query_file.write(anime_name) | |
| 71 | ||
| 72 | run_script("anime_list") | |
| 73 | ||
| 74 | anime_dict = load_anime_data("scripts/tmp/anime_list") | |
| 75 | ||
| 60 | 76 | cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() |
| 61 | 77 | |
| 62 | 78 | try: |
| @@ -65,11 +81,25 @@ try: | ||
| 65 | 81 | anime_id = result['id'] |
| 66 | 82 | progress = int(result['progress']) |
| 67 | 83 | title = result['english_title'] |
| 84 | total_episodes = result['episodes'] | |
| 68 | 85 | except: |
| 69 | 86 | print("fucked up") |
| 70 | 87 | anime_id = 98460 |
| 71 | 88 | progress = 0 |
| 72 | 89 | |
| 90 | try: | |
| 91 | print("Trying to automate") | |
| 92 | with open("scripts/tmp/id", "w") as id_file: | |
| 93 | id_file.write(anime_dict[anime_name+f" ({total_episodes} episodes)"]) | |
| 94 | with open("scripts/tmp/anime", "w") as anime_name_file: | |
| 95 | anime_name_file.write(anime_name) | |
| 96 | except: | |
| 97 | print("Cannot automate") | |
| 98 | select_anime(anime_dict) | |
| 99 | ||
| 100 | # Remove everything from the last '(' including the parentheses | |
| 101 | ||
| 102 | ||
| 73 | 103 | # os.system("./scripts/episode_list.sh") |
| 74 | 104 | run_script("episode_list") |
| 75 | 105 | |
| @@ -79,35 +109,44 @@ run_script("episode_list") | ||
| 79 | 109 | # last_episode = temp[-1] |
| 80 | 110 | # ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n") |
| 81 | 111 | |
| 82 | with open("scripts/tmp/ep_no", "w") as ep_no_file: | |
| 83 | # ep_no.write("1") | |
| 84 | # ep_no_file.write(ep_no) | |
| 85 | with open("scripts/tmp/episode_list") as ep_list: | |
| 86 | temp = ep_list.read() | |
| 87 | temp = temp.split() | |
| 88 | last_episode = int(temp[-1]) | |
| 112 | while True: | |
| 113 | with open("scripts/tmp/ep_no", "w") as ep_no_file: | |
| 114 | with open("scripts/tmp/episode_list") as ep_list: | |
| 115 | temp = ep_list.read() | |
| 116 | temp = temp.split() | |
| 117 | last_episode = int(temp[-1]) | |
| 118 | ||
| 119 | if progress == last_episode: | |
| 120 | user_input = input("Do you want to start this anime from beginning?") | |
| 121 | if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "": | |
| 122 | progress = 0 | |
| 123 | else: | |
| 124 | progress = last_episode - 1 | |
| 125 | ||
| 126 | # print(progress) | |
| 127 | ep_no_file.write(str(progress+1)) | |
| 128 | ||
| 129 | os.system("./scripts/episode_url.sh") | |
| 130 | ||
| 131 | # Print the result | |
| 132 | if anime_id: | |
| 133 | print(f"Anime ID: {anime_id}") | |
| 134 | else: | |
| 135 | print("Anime not found.") | |
| 136 | ||
| 137 | # with open("scripts/tmp/link", 'r') as links: | |
| 138 | # link = links.read() | |
| 139 | ||
| 140 | links = load_links("scripts/tmp/links") | |
| 89 | 141 | |
| 90 | if progress == last_episode: | |
| 91 | user_input = input("Do you want to start this anime from beginning?") | |
| 92 | if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "": | |
| 93 | progress = 0 | |
| 142 | try: | |
| 143 | start_video(links[0][1]) | |
| 144 | except ConnectionRefusedError: | |
| 145 | print("Player Closed") | |
| 146 | to_continue_or_not_to_continue = input("Continue? (y/n)\n") | |
| 147 | if to_continue_or_not_to_continue.lower() == "yes" or to_continue_or_not_to_continue.lower() == "y" or to_continue_or_not_to_continue == "": | |
| 148 | pass | |
| 94 | 149 | else: |
| 95 | progress = last_episode - 1 | |
| 96 | ||
| 97 | print(progress) | |
| 98 | ep_no_file.write(str(progress+1)) | |
| 99 | ||
| 100 | os.system("./scripts/episode_url.sh") | |
| 101 | ||
| 102 | # Print the result | |
| 103 | if anime_id: | |
| 104 | print(f"Anime ID: {anime_id}") | |
| 105 | else: | |
| 106 | print("Anime not found.") | |
| 107 | ||
| 108 | # with open("scripts/tmp/link", 'r') as links: | |
| 109 | # link = links.read() | |
| 110 | ||
| 111 | links = load_links("scripts/tmp/links") | |
| 112 | ||
| 113 | start_video(links[0][1]) | |
| 150 | break | |
| 151 | # except: | |
| 152 | # pass | |
| \ No newline at end of file | ||