Commit e03f98c4c8
Unsigned
Layout: unified · split
curd.py +102 −26
| @@ -29,6 +29,70 @@ user_id = os.environ.get('ANILIST_USER_ID') | |||
| 29 | def run_script(script): | 29 | def run_script(script): |
| 30 | os.system(f"./scripts/{script}.sh") | 30 | os.system(f"./scripts/{script}.sh") |
| 31 | 31 | ||
| 32 | def load_config(): | ||
| 33 | command = """echo $(xdg-user-dir CONFIG)""" | ||
| 34 | |||
| 35 | result = subprocess.run(command, shell=True, capture_output=True, text=True) | ||
| 36 | output = result.stdout.strip() | ||
| 37 | |||
| 38 | folder_name = f"{output}/.config/curd" | ||
| 39 | file_name = "curd.conf" | ||
| 40 | |||
| 41 | config_file_path = os.path.join(folder_name, file_name) | ||
| 42 | |||
| 43 | print(config_file_path) | ||
| 44 | if not os.path.exists(os.path.join(config_file_path)): | ||
| 45 | print("Creating config") | ||
| 46 | |||
| 47 | try: | ||
| 48 | os.makedirs(folder_name) | ||
| 49 | except: | ||
| 50 | pass | ||
| 51 | |||
| 52 | with open(config_file_path, 'w') as file: | ||
| 53 | file.write(r"""player="mpv" | ||
| 54 | show_adult_content=false | ||
| 55 | history_file="$HOME/.local/share/curd/curd_history.txt" | ||
| 56 | subs_language="english" | ||
| 57 | sub_or_dub="sub" | ||
| 58 | score_on_completion=true | ||
| 59 | discord_presence=true | ||
| 60 | presence_script_path="curddiscordpresence.py" | ||
| 61 | """) | ||
| 62 | |||
| 63 | config_dict = {} | ||
| 64 | |||
| 65 | with open(config_file_path, 'r') as file: | ||
| 66 | for line in file: | ||
| 67 | # Strip whitespace and ignore comments or empty lines | ||
| 68 | line = line.strip() | ||
| 69 | if line and not line.startswith("#"): | ||
| 70 | # Split the line into key and value | ||
| 71 | key, value = line.split("=", 1) | ||
| 72 | key = key.strip() | ||
| 73 | value = value.strip().strip('"') | ||
| 74 | |||
| 75 | # Handle environment variables in the value | ||
| 76 | value = os.path.expandvars(value) | ||
| 77 | |||
| 78 | # Convert boolean strings to actual booleans | ||
| 79 | if value.lower() == "true": | ||
| 80 | value = True | ||
| 81 | elif value.lower() == "false": | ||
| 82 | value = False | ||
| 83 | |||
| 84 | # Store in the dictionary | ||
| 85 | config_dict[key] = value | ||
| 86 | return config_dict | ||
| 87 | |||
| 88 | # else: | ||
| 89 | # with open(config_file_path, "r") as config_file: | ||
| 90 | # return config_file.read() | ||
| 91 | |||
| 92 | user_config = load_config() # python dictionary containing all the configs as key value pairs | ||
| 93 | |||
| 94 | print(user_config) | ||
| 95 | |||
| 32 | print("downloading user data") | 96 | print("downloading user data") |
| 33 | anilist_user_data = get_user_data(access_token, user_id) | 97 | anilist_user_data = get_user_data(access_token, user_id) |
| 34 | with open("response.json", "w") as response: | 98 | with open("response.json", "w") as response: |
| @@ -48,14 +112,12 @@ except: | |||
| 48 | 112 | ||
| 49 | # os.system("./scripts/anime_list.sh") | 113 | # os.system("./scripts/anime_list.sh") |
| 50 | 114 | ||
| 51 | |||
| 52 | # with open('response.json', 'r') as file: | 115 | # with open('response.json', 'r') as file: |
| 53 | # data = json.load(file) | 116 | # data = json.load(file) |
| 54 | 117 | ||
| 55 | # print(data) | 118 | # print(data) |
| 56 | # print(type(data['data'])) | 119 | # print(type(data['data'])) |
| 57 | 120 | ||
| 58 | |||
| 59 | anime_dict = extract_anime_info(anilist_user_data)[0] | 121 | anime_dict = extract_anime_info(anilist_user_data)[0] |
| 60 | # print(anime_dict) | 122 | # print(anime_dict) |
| 61 | # anime_dict = load_anime_data("scripts/tmp/anime_list") | 123 | # anime_dict = load_anime_data("scripts/tmp/anime_list") |
| @@ -110,22 +172,43 @@ run_script("episode_list") | |||
| 110 | # last_episode = temp[-1] | 172 | # last_episode = temp[-1] |
| 111 | # ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n") | 173 | # ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n") |
| 112 | 174 | ||
| 175 | binge_watching = False | ||
| 176 | |||
| 113 | while True: | 177 | while True: |
| 114 | with open("scripts/tmp/ep_no", "w") as ep_no_file: | 178 | with open("scripts/tmp/episode_list") as ep_list: |
| 115 | with open("scripts/tmp/episode_list") as ep_list: | 179 | temp = ep_list.read() |
| 116 | temp = ep_list.read() | 180 | temp = temp.split() |
| 117 | temp = temp.split() | 181 | last_episode = int(temp[-1]) |
| 118 | last_episode = int(temp[-1]) | ||
| 119 | |||
| 120 | if progress == last_episode: | ||
| 121 | user_input = input("Do you want to start this anime from beginning? (y/n):") | ||
| 122 | if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "": | ||
| 123 | progress = 0 | ||
| 124 | else: | ||
| 125 | progress = last_episode - 1 | ||
| 126 | 182 | ||
| 127 | # print(progress) | 183 | if binge_watching: |
| 128 | ep_no_file.write(str(progress+1)) | 184 | print("binge watching") |
| 185 | with open("scripts/tmp/ep_no", "r") as ep_no_file_1: | ||
| 186 | current_ep = int(ep_no_file_1.read()) | ||
| 187 | if current_ep == last_episode: | ||
| 188 | print("completed anime.") | ||
| 189 | |||
| 190 | # TODO: Add way to rate the anime | ||
| 191 | exit(0) | ||
| 192 | |||
| 193 | else: | ||
| 194 | print(f"Next episode is here, goshujin sama progress: {current_ep} {type(current_ep)}") | ||
| 195 | with open("scripts/tmp/ep_no", "w") as ep_no_file: | ||
| 196 | ep_no_file.write(str(int(current_ep)+1)) | ||
| 197 | else: | ||
| 198 | print("First time watch") | ||
| 199 | with open("scripts/tmp/ep_no", "w") as ep_no_file: | ||
| 200 | |||
| 201 | if progress == last_episode: | ||
| 202 | user_input = input("Do you want to start this anime from beginning? (y/n):") | ||
| 203 | if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "": | ||
| 204 | progress = 0 | ||
| 205 | else: | ||
| 206 | print("Starting last episode of anime") | ||
| 207 | progress = last_episode - 1 | ||
| 208 | # else: | ||
| 209 | |||
| 210 | # print(progress) | ||
| 211 | ep_no_file.write(str(progress+1)) | ||
| 129 | 212 | ||
| 130 | os.system("./scripts/episode_url.sh") | 213 | os.system("./scripts/episode_url.sh") |
| 131 | 214 | ||
| @@ -144,8 +227,8 @@ while True: | |||
| 144 | salt = random.randint(0,500) | 227 | salt = random.randint(0,500) |
| 145 | print("SALT IS:"+str(salt)) | 228 | print("SALT IS:"+str(salt)) |
| 146 | start_video(links[0][1], salt) | 229 | start_video(links[0][1], salt) |
| 147 | # print('test') | ||
| 148 | command = """echo '{ "command": ["get_property", "playback-time"] }' | socat - /tmp/mpvsocket"""+str(salt) | 230 | command = """echo '{ "command": ["get_property", "playback-time"] }' | socat - /tmp/mpvsocket"""+str(salt) |
| 231 | |||
| 149 | while True: | 232 | while True: |
| 150 | time.sleep(2) | 233 | time.sleep(2) |
| 151 | 234 | ||
| @@ -172,19 +255,12 @@ while True: | |||
| 172 | print("Error:", result.stderr) | 255 | print("Error:", result.stderr) |
| 173 | break | 256 | break |
| 174 | 257 | ||
| 175 | # break | ||
| 176 | # Define the command to run | ||
| 177 | |||
| 178 | # Execute the command and capture the output | ||
| 179 | # result = subprocess.run(command, capture_output=True, text=True) | ||
| 180 | |||
| 181 | except ConnectionRefusedError: | 258 | except ConnectionRefusedError: |
| 182 | print("Player Closed") | 259 | print("Player Closed") |
| 183 | finally: | 260 | finally: |
| 184 | to_continue_or_not_to_continue = input("Continue? (y/n)\n") | 261 | to_continue_or_not_to_continue = input("Continue? (y/n)\n") |
| 185 | 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 == "": | 262 | 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 == "": |
| 186 | pass | 263 | binge_watching = True |
| 264 | # ep_no_file | ||
| 187 | else: | 265 | else: |
| 188 | break | 266 | break |
| 189 | # except: | ||
| 190 | # pass\ No newline at end of file | ||