Commit e03f98c4c8
Unsigned
Layout: unified · split
curd.py +102 −26
| @@ -29,6 +29,70 @@ user_id = os.environ.get('ANILIST_USER_ID') | ||
| 29 | 29 | def run_script(script): |
| 30 | 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 | 96 | print("downloading user data") |
| 33 | 97 | anilist_user_data = get_user_data(access_token, user_id) |
| 34 | 98 | with open("response.json", "w") as response: |
| @@ -48,14 +112,12 @@ except: | ||
| 48 | 112 | |
| 49 | 113 | # os.system("./scripts/anime_list.sh") |
| 50 | 114 | |
| 51 | ||
| 52 | 115 | # with open('response.json', 'r') as file: |
| 53 | 116 | # data = json.load(file) |
| 54 | 117 | |
| 55 | 118 | # print(data) |
| 56 | 119 | # print(type(data['data'])) |
| 57 | 120 | |
| 58 | ||
| 59 | 121 | anime_dict = extract_anime_info(anilist_user_data)[0] |
| 60 | 122 | # print(anime_dict) |
| 61 | 123 | # anime_dict = load_anime_data("scripts/tmp/anime_list") |
| @@ -110,22 +172,43 @@ run_script("episode_list") | ||
| 110 | 172 | # last_episode = temp[-1] |
| 111 | 173 | # ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n") |
| 112 | 174 | |
| 175 | binge_watching = False | |
| 176 | ||
| 113 | 177 | while True: |
| 114 | with open("scripts/tmp/ep_no", "w") as ep_no_file: | |
| 115 | with open("scripts/tmp/episode_list") as ep_list: | |
| 116 | temp = ep_list.read() | |
| 117 | temp = temp.split() | |
| 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 | |
| 178 | with open("scripts/tmp/episode_list") as ep_list: | |
| 179 | temp = ep_list.read() | |
| 180 | temp = temp.split() | |
| 181 | last_episode = int(temp[-1]) | |
| 126 | 182 | |
| 127 | # print(progress) | |
| 128 | ep_no_file.write(str(progress+1)) | |
| 183 | if binge_watching: | |
| 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 | 213 | os.system("./scripts/episode_url.sh") |
| 131 | 214 | |
| @@ -144,8 +227,8 @@ while True: | ||
| 144 | 227 | salt = random.randint(0,500) |
| 145 | 228 | print("SALT IS:"+str(salt)) |
| 146 | 229 | start_video(links[0][1], salt) |
| 147 | # print('test') | |
| 148 | 230 | command = """echo '{ "command": ["get_property", "playback-time"] }' | socat - /tmp/mpvsocket"""+str(salt) |
| 231 | ||
| 149 | 232 | while True: |
| 150 | 233 | time.sleep(2) |
| 151 | 234 | |
| @@ -172,19 +255,12 @@ while True: | ||
| 172 | 255 | print("Error:", result.stderr) |
| 173 | 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 | 258 | except ConnectionRefusedError: |
| 182 | 259 | print("Player Closed") |
| 183 | 260 | finally: |
| 184 | 261 | to_continue_or_not_to_continue = input("Continue? (y/n)\n") |
| 185 | 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 | 265 | else: |
| 188 | 266 | break |
| 189 | # except: | |
| 190 | # pass | |
| \ No newline at end of file | ||