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