| @@ -1,3 +1,5 @@ |
| 1 | # if you are trying to read this code, god help you. |
| 2 | # this is how my implementation of the ani-cli code to get the anime works |
| 1 | 3 | |
| 2 | 4 | # search (anime_list.sh) -> tmp/anime_list |
| 3 | 5 | # anime_id -> episode_list.sh |
| @@ -58,14 +60,14 @@ def read_tmp(tmp_filename:str): |
| 58 | 60 | |
| 59 | 61 | def download_anilist_data(access_token, user_id): |
| 60 | 62 | ''' dowlnoad anilist user data''' |
| 61 | | print("downloading user data") |
| 63 | # print("downloading user data") |
| 62 | 64 | anilist_user_data = get_user_data(access_token, user_id) |
| 63 | 65 | with open("response.json", "w") as response: |
| 64 | 66 | response.write(str(anilist_user_data)) |
| 65 | 67 | try: |
| 66 | 68 | if anilist_user_data['data'] == None: |
| 67 | 69 | print("Cannot process user data.") |
| 68 | | print(anilist_user_data) |
| 70 | # print(anilist_user_data) |
| 69 | 71 | exit() |
| 70 | 72 | except: |
| 71 | 73 | pass |
| @@ -83,7 +85,7 @@ def load_config(): |
| 83 | 85 | |
| 84 | 86 | config_file_path = os.path.join(folder_name, file_name) |
| 85 | 87 | |
| 86 | | print(config_file_path) |
| 88 | # print(config_file_path) |
| 87 | 89 | if not os.path.exists(os.path.join(config_file_path)): |
| 88 | 90 | print("Creating config") |
| 89 | 91 | |
| @@ -167,8 +169,8 @@ cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() |
| 167 | 169 | |
| 168 | 170 | try: |
| 169 | 171 | result = search_anime_by_title(anilist_user_data, cleaned_text)[0] |
| 170 | | print(result) |
| 171 | | anime_id = result['id'] |
| 172 | # print(result) |
| 173 | media_id = result['id'] |
| 172 | 174 | progress = int(result['progress']) |
| 173 | 175 | title = result['english_title'] |
| 174 | 176 | total_episodes = result['episodes'] |
| @@ -176,16 +178,15 @@ try: |
| 176 | 178 | except KeyboardInterrupt: |
| 177 | 179 | print("bye") |
| 178 | 180 | exit(0) |
| 179 | | except: |
| 180 | | print("fucked up") |
| 181 | | anime_id = 98460 |
| 182 | | progress = 0 |
| 181 | except Exception as e: |
| 182 | print(f"Searching anime error: {e}") |
| 183 | exit(1) |
| 183 | 184 | |
| 184 | 185 | try: |
| 185 | | finding_anime = find_anime(get_all_anime(user_config["history_file"]), anilist_id=str(anime_id)) |
| 186 | | print(finding_anime) |
| 186 | finding_anime = find_anime(get_all_anime(user_config["history_file"]), anilist_id=str(media_id)) |
| 187 | # print(finding_anime) |
| 187 | 188 | if finding_anime: |
| 188 | | print("AUTOMATICALLY BABY") |
| 189 | print("Found anime in history") |
| 189 | 190 | write_to_tmp("id", finding_anime['allanime_id']) |
| 190 | 191 | write_to_tmp("anime", finding_anime['name']) |
| 191 | 192 | else: |
| @@ -196,7 +197,7 @@ except KeyboardInterrupt: |
| 196 | 197 | print("bye") |
| 197 | 198 | exit(0) |
| 198 | 199 | except: |
| 199 | | print("Cannot automate") |
| 200 | print("Please select anime") |
| 200 | 201 | select_anime(anime_dict) |
| 201 | 202 | |
| 202 | 203 | run_script("episode_list") |
| @@ -215,26 +216,26 @@ last_episode = int(read_tmp("episode_list").split()[-1]) |
| 215 | 216 | |
| 216 | 217 | anime_watch_history = get_all_anime(user_config['history_file']) |
| 217 | 218 | # anime_watch_history[] |
| 218 | | anime_history = find_anime(anime_watch_history, anilist_id=anime_id, allanime_id=get_contents_of("id")) |
| 219 | anime_history = find_anime(anime_watch_history, anilist_id=media_id, allanime_id=get_contents_of("id")) |
| 219 | 220 | episode_completed = False |
| 220 | 221 | if anime_history: # if it exists in local history |
| 221 | | print(f"came in history {str(progress)}") |
| 222 | # print(f"came in history {str(progress)}") |
| 222 | 223 | if int(anime_history['episode']) != progress+1: # if the upstream progress is ahead |
| 223 | 224 | write_to_tmp("ep_no", str(int(progress)+1)) |
| 224 | | print(f"Starting anime from upstream {str(progress + 1)}") |
| 225 | # print(f"Starting anime from upstream {str(progress + 1)}") |
| 225 | 226 | |
| 226 | 227 | watching_ep = progress + 1 |
| 227 | 228 | |
| 228 | 229 | elif int(anime_history['episode']) == int(progress)+1: # if the upstream progress is NOT ahead |
| 229 | 230 | mpv_args.append(f"--start={anime_history['time']}") |
| 230 | 231 | write_to_tmp("ep_no", anime_history['episode']) |
| 231 | | print(f"STARTING ANIME FROM EPISODE {anime_history['episode']} {anime_history['time']}") |
| 232 | # print(f"STARTING ANIME FROM EPISODE {anime_history['episode']} {anime_history['time']}") |
| 232 | 233 | |
| 233 | 234 | watching_ep = int(anime_history['episode']) |
| 234 | 235 | else: # if there is no history |
| 235 | | print("no history found") |
| 236 | # print("no history found") |
| 236 | 237 | |
| 237 | | print("First time watch") |
| 238 | # print("First time watch") |
| 238 | 239 | |
| 239 | 240 | if progress == last_episode: |
| 240 | 241 | user_input = input("Do you want to start this anime from beginning? (y/n):") |
| @@ -251,10 +252,12 @@ else: # if there is no history |
| 251 | 252 | run_script("episode_url") |
| 252 | 253 | |
| 253 | 254 | # Print the result |
| 254 | | if anime_id: |
| 255 | | print(f"Anime ID: {anime_id}") |
| 255 | if media_id: |
| 256 | # print(f"Anime ID: {media_id}") |
| 257 | pass |
| 256 | 258 | else: |
| 257 | 259 | print("Anime not found.") |
| 260 | exit(1) |
| 258 | 261 | |
| 259 | 262 | links = load_links("scripts/tmp/links") |
| 260 | 263 | |
| @@ -262,7 +265,7 @@ while True: |
| 262 | 265 | |
| 263 | 266 | try: |
| 264 | 267 | salt = random.randint(0,1500) |
| 265 | | print("SALT IS:"+str(salt)) |
| 268 | # print("SALT IS:"+str(salt)) |
| 266 | 269 | start_video(links[0][1], salt, mpv_args) |
| 267 | 270 | |
| 268 | 271 | mpv_socket_path = "/tmp/mpvsocket"+str(salt) |
| @@ -294,21 +297,21 @@ while True: |
| 294 | 297 | # print("Playback time:", playback_time) |
| 295 | 298 | |
| 296 | 299 | watched_percentage = get_percentage_watched(mpv_socket_path) |
| 297 | | print("watched percentage", watched_percentage) |
| 300 | mpv_playback_speed = get_mpv_playback_speed(mpv_socket_path) |
| 301 | # print("mpv speed", mpv_playback_speed) |
| 302 | # print("watched percentage", watched_percentage) |
| 298 | 303 | if watched_percentage > mark_episode_as_completed_at: |
| 299 | 304 | |
| 300 | 305 | episode_completed = True |
| 301 | 306 | binge_watching = True |
| 302 | | else: |
| 303 | | print(f"Episode not done: {watched_percentage} {mark_episode_as_completed_at}") |
| 304 | | # video_duration = subprocess.run(mpv_duration_command, shell=True, capture_output=True, text=True) |
| 305 | | |
| 307 | # else: |
| 308 | # print(f"Episode not done: {watched_percentage} {mark_episode_as_completed_at}") |
| 309 | # video_duration = subprocess.run(mpv_duration_command, shell=True, capture_output=True, text=True): |
| 310 | elif data['error'] == "property unavailable": # Stream has not started yet |
| 311 | pass |
| 306 | 312 | else: |
| 307 | | if data['error'] == "property unavailable": # Stream has not started yet |
| 308 | | pass |
| 309 | | else: |
| 310 | | print("Error (330):", data["error"]) |
| 311 | | break |
| 313 | print("Error (330):", data["error"]) |
| 314 | break |
| 312 | 315 | except json.decoder.JSONDecodeError as e: |
| 313 | 316 | print("Error decoding JSON:", e) |
| 314 | 317 | break # Exit the loop on unexpected JSON error |
| @@ -316,11 +319,11 @@ while True: |
| 316 | 319 | print("bye") |
| 317 | 320 | exit(0) |
| 318 | 321 | except Exception as e: |
| 319 | | print("some error fucked everything up:\n", e) |
| 322 | print("Unknown:\n", e) |
| 320 | 323 | else: |
| 321 | 324 | killing_error = str(result.stderr) |
| 322 | 325 | if killing_error == "property unavailable": # mpv is not started yet |
| 323 | | print("passing") |
| 326 | # print("passing") |
| 324 | 327 | pass |
| 325 | 328 | else: # Stream has ended (maybe) |
| 326 | 329 | print("Error (346):", killing_error) |
| @@ -330,8 +333,10 @@ while True: |
| 330 | 333 | # print("fuck") |
| 331 | 334 | # print(f"Exception: {e}") |
| 332 | 335 | break |
| 333 | | except ConnectionRefusedError: |
| 336 | except ConnectionRefusedError: # doesnt work ig |
| 334 | 337 | print("Player Closed") |
| 338 | # print("have a great") |
| 339 | # exit(0) |
| 335 | 340 | except KeyboardInterrupt: |
| 336 | 341 | if watched_percentage > mark_episode_as_completed_at: |
| 337 | 342 | watching_ep = int(watching_ep)+1 |
| @@ -361,12 +366,7 @@ while True: |
| 361 | 366 | |
| 362 | 367 | watching_ep = int(watching_ep)+1 |
| 363 | 368 | write_to_tmp("ep_no", str(watching_ep)) |
| 364 | | print("here") |
| 365 | | update_anime(user_config['history_file'], str(anime_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title)) |
| 366 | | print("inside") |
| 367 | | print(f"Episode done: {type(watching_ep)}") |
| 368 | | print(f"Episode done: {int(watching_ep)}") |
| 369 | | |
| 369 | update_anime(user_config['history_file'], str(media_id), str(get_contents_of("id")), str(watching_ep), "0", str(duration), str(title)) |
| 370 | 370 | anime_watch_history = get_all_anime(user_config['history_file']) |
| 371 | 371 | # anime_watch_history[] |
| 372 | 372 | anime_history = find_anime(anime_watch_history, anilist_id=anime_id, allanime_id=get_contents_of("id")) |