Commit 10832a6d38
Unsigned
Layout: unified · split
curd.py +72 −24
| @@ -7,35 +7,71 @@ import re | ||
| 7 | 7 | import os |
| 8 | 8 | import json |
| 9 | 9 | from anilist import search_anime_by_title |
| 10 | from anilist import get_user_data | |
| 11 | from select_link import load_links | |
| 12 | from start_video import * | |
| 13 | from select_anime import load_anime_data | |
| 14 | from select_anime import extract_anime_info | |
| 15 | from select_anime import select_anime | |
| 16 | ||
| 17 | access_token = os.environ.get('ANILIST_ACCESS_TOKEN') | |
| 18 | user_id = os.environ.get('ANILIST_USER_ID') | |
| 19 | ||
| 20 | # print(access_token) | |
| 21 | # print(user_id) | |
| 22 | ||
| 23 | def run_script(script): | |
| 24 | os.system(f"./scripts/{script}.sh") | |
| 25 | ||
| 26 | print("downloading user data") | |
| 27 | anilist_user_data = get_user_data(access_token, user_id) | |
| 28 | try: | |
| 29 | if anilist_user_data['data'] == None: | |
| 30 | print("Cannot process user data.") | |
| 31 | print(anilist_user_data) | |
| 32 | exit() | |
| 33 | except: | |
| 34 | pass | |
| 10 | 35 | |
| 11 | 36 | with open("scripts/tmp/query", "w") as file: |
| 12 | 37 | file.write(input("Enter the anime you want:\n")) |
| 13 | 38 | |
| 14 | os.system("./scripts/anime_list.sh") | |
| 39 | # os.system("./scripts/anime_list.sh" | |
| 15 | 40 | |
| 16 | import select_anime | |
| 17 | ||
| 18 | with open("scripts/tmp/anime", "r") as anime: | |
| 19 | anime_name = anime.read() | |
| 41 | run_script("anime_list") | |
| 20 | 42 | |
| 21 | 43 | with open('response.json', 'r') as file: |
| 22 | 44 | data = json.load(file) |
| 23 | 45 | |
| 46 | # print(data) | |
| 47 | # print(type(data['data'])) | |
| 48 | ||
| 49 | # anime_dict = extract_anime_info(anilist_user_data)[0] | |
| 50 | # print(anime_dict) | |
| 51 | anime_dict = load_anime_data("scripts/tmp/anime_list") | |
| 52 | print(anime_dict) | |
| 53 | # print(f"ANIME DICT = {anime_dict}") | |
| 54 | select_anime(anime_dict) | |
| 55 | ||
| 56 | with open("scripts/tmp/anime", "r") as anime: | |
| 57 | anime_name = anime.read() | |
| 58 | ||
| 24 | 59 | # Remove everything from the last '(' including the parentheses |
| 25 | 60 | cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() |
| 26 | 61 | |
| 27 | # try: | |
| 28 | result = search_anime_by_title(data, cleaned_text)[0] | |
| 29 | print(result) | |
| 30 | anime_id = result['id'] | |
| 31 | progress = int(result['progress']) | |
| 32 | title = result['english_title'] | |
| 33 | # except: | |
| 34 | # print("fucked up") | |
| 35 | # anime_id = 98460 | |
| 62 | try: | |
| 63 | result = search_anime_by_title(anilist_user_data, cleaned_text)[0] | |
| 64 | print(result) | |
| 65 | anime_id = result['id'] | |
| 66 | progress = int(result['progress']) | |
| 67 | title = result['english_title'] | |
| 68 | except: | |
| 69 | print("fucked up") | |
| 70 | anime_id = 98460 | |
| 71 | progress = 0 | |
| 36 | 72 | |
| 37 | ||
| 38 | os.system("./scripts/episode_list.sh") | |
| 73 | # os.system("./scripts/episode_list.sh") | |
| 74 | run_script("episode_list") | |
| 39 | 75 | |
| 40 | 76 | # with open("scripts/tmp/episode_list") as ep_list: |
| 41 | 77 | # temp = ep_list.read() |
| @@ -43,18 +79,25 @@ os.system("./scripts/episode_list.sh") | ||
| 43 | 79 | # last_episode = temp[-1] |
| 44 | 80 | # ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n") |
| 45 | 81 | |
| 46 | os.system("./scripts/episode_url.sh") | |
| 47 | ||
| 48 | ||
| 49 | # Define the title to search for | |
| 50 | # search_title = '' # Replace with the actual title you're searching for | |
| 51 | ||
| 52 | 82 | with open("scripts/tmp/ep_no", "w") as ep_no_file: |
| 53 | 83 | # ep_no.write("1") |
| 54 | 84 | # ep_no_file.write(ep_no) |
| 55 | ep_no_file.write(str(progress)) | |
| 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]) | |
| 89 | ||
| 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 | |
| 94 | else: | |
| 95 | progress = last_episode - 1 | |
| 96 | ||
| 97 | print(progress) | |
| 98 | ep_no_file.write(str(progress+1)) | |
| 56 | 99 | |
| 57 | # Search for the anime and get its ID | |
| 100 | os.system("./scripts/episode_url.sh") | |
| 58 | 101 | |
| 59 | 102 | # Print the result |
| 60 | 103 | if anime_id: |
| @@ -62,4 +105,9 @@ if anime_id: | ||
| 62 | 105 | else: |
| 63 | 106 | print("Anime not found.") |
| 64 | 107 | |
| 108 | # with open("scripts/tmp/link", 'r') as links: | |
| 109 | # link = links.read() | |
| 110 | ||
| 111 | links = load_links("scripts/tmp/links") | |
| 65 | 112 | |
| 113 | start_video(links[0][1]) | |