Commit c2de159869

c2de1598692c48f69a3ca69b974937f1adece085

parent: df550568b7

Unsigned

Wraient <wraient.911@gmail.com> · 2024-08-25 17:26 UTC

Pretty much done.

Layout: unified · split

curd.py +79 −40
@@ -20,11 +20,17 @@ user_id = os.environ.get('ANILIST_USER_ID')
20# print(access_token) 20# print(access_token)
21# print(user_id) 21# print(user_id)
22 22
23
23def run_script(script): 24def run_script(script):
24 os.system(f"./scripts/{script}.sh") 25 os.system(f"./scripts/{script}.sh")
25 26
27
28
29
26print("downloading user data") 30print("downloading user data")
27anilist_user_data = get_user_data(access_token, user_id) 31anilist_user_data = get_user_data(access_token, user_id)
32with open("response.json", "w") as response:
33 response.write(str(anilist_user_data))
28try: 34try:
29 if anilist_user_data['data'] == None: 35 if anilist_user_data['data'] == None:
30 print("Cannot process user data.") 36 print("Cannot process user data.")
@@ -33,30 +39,40 @@ try:
33except: 39except:
34 pass 40 pass
35 41
36with open("scripts/tmp/query", "w") as file: 42# Searching for anime
37 file.write(input("Enter the anime you want:\n"))
38 43
39# os.system("./scripts/anime_list.sh" 44# with open("scripts/tmp/query", "w") as file:
45# file.write(input("Enter the anime you want:\n"))
46
47# os.system("./scripts/anime_list.sh")
40 48
41run_script("anime_list")
42 49
43with open('response.json', 'r') as file: 50# with open('response.json', 'r') as file:
44 data = json.load(file) 51 # data = json.load(file)
45 52
46# print(data) 53# print(data)
47# print(type(data['data'])) 54# print(type(data['data']))
48 55
49# anime_dict = extract_anime_info(anilist_user_data)[0] 56
57
58anime_dict = extract_anime_info(anilist_user_data)[0]
59# print(anime_dict)
60# anime_dict = load_anime_data("scripts/tmp/anime_list")
50# print(anime_dict) 61# print(anime_dict)
51anime_dict = load_anime_data("scripts/tmp/anime_list")
52print(anime_dict)
53# print(f"ANIME DICT = {anime_dict}") 62# print(f"ANIME DICT = {anime_dict}")
63
54select_anime(anime_dict) 64select_anime(anime_dict)
55 65
56with open("scripts/tmp/anime", "r") as anime: 66with open("scripts/tmp/anime", "r") as anime:
57 anime_name = anime.read() 67 anime_name = anime.read()
58 68
59# Remove everything from the last '(' including the parentheses 69with open("scripts/tmp/query", "w") as query_file:
70 query_file.write(anime_name)
71
72run_script("anime_list")
73
74anime_dict = load_anime_data("scripts/tmp/anime_list")
75
60cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() 76cleaned_text = re.sub(r'\(.*$', '', anime_name).strip()
61 77
62try: 78try:
@@ -65,11 +81,25 @@ try:
65 anime_id = result['id'] 81 anime_id = result['id']
66 progress = int(result['progress']) 82 progress = int(result['progress'])
67 title = result['english_title'] 83 title = result['english_title']
84 total_episodes = result['episodes']
68except: 85except:
69 print("fucked up") 86 print("fucked up")
70 anime_id = 98460 87 anime_id = 98460
71 progress = 0 88 progress = 0
72 89
90try:
91 print("Trying to automate")
92 with open("scripts/tmp/id", "w") as id_file:
93 id_file.write(anime_dict[anime_name+f" ({total_episodes} episodes)"])
94 with open("scripts/tmp/anime", "w") as anime_name_file:
95 anime_name_file.write(anime_name)
96except:
97 print("Cannot automate")
98 select_anime(anime_dict)
99
100# Remove everything from the last '(' including the parentheses
101
102
73# os.system("./scripts/episode_list.sh") 103# os.system("./scripts/episode_list.sh")
74run_script("episode_list") 104run_script("episode_list")
75 105
@@ -79,35 +109,44 @@ run_script("episode_list")
79# last_episode = temp[-1] 109# last_episode = temp[-1]
80# ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n") 110# ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n")
81 111
82with open("scripts/tmp/ep_no", "w") as ep_no_file: 112while True:
83 # ep_no.write("1") 113 with open("scripts/tmp/ep_no", "w") as ep_no_file:
84 # ep_no_file.write(ep_no) 114 with open("scripts/tmp/episode_list") as ep_list:
85 with open("scripts/tmp/episode_list") as ep_list: 115 temp = ep_list.read()
86 temp = ep_list.read() 116 temp = temp.split()
87 temp = temp.split() 117 last_episode = int(temp[-1])
88 last_episode = int(temp[-1]) 118
119 if progress == last_episode:
120 user_input = input("Do you want to start this anime from beginning?")
121 if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "":
122 progress = 0
123 else:
124 progress = last_episode - 1
125
126 # print(progress)
127 ep_no_file.write(str(progress+1))
128
129 os.system("./scripts/episode_url.sh")
130
131 # Print the result
132 if anime_id:
133 print(f"Anime ID: {anime_id}")
134 else:
135 print("Anime not found.")
136
137 # with open("scripts/tmp/link", 'r') as links:
138 # link = links.read()
139
140 links = load_links("scripts/tmp/links")
89 141
90 if progress == last_episode: 142 try:
91 user_input = input("Do you want to start this anime from beginning?") 143 start_video(links[0][1])
92 if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "": 144 except ConnectionRefusedError:
93 progress = 0 145 print("Player Closed")
146 to_continue_or_not_to_continue = input("Continue? (y/n)\n")
147 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 == "":
148 pass
94 else: 149 else:
95 progress = last_episode - 1 150 break
96 151 # except:
97 print(progress) 152 # pass\ No newline at end of file
98 ep_no_file.write(str(progress+1))
99
100os.system("./scripts/episode_url.sh")
101
102# Print the result
103if anime_id:
104 print(f"Anime ID: {anime_id}")
105else:
106 print("Anime not found.")
107
108# with open("scripts/tmp/link", 'r') as links:
109# link = links.read()
110
111links = load_links("scripts/tmp/links")
112
113start_video(links[0][1])