Commit e03f98c4c8

e03f98c4c8179558cb2a9ca0ed86847bca1b0e9a

parent: 05022baaf4

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-03 17:58 UTC

Implemented:
Load config
continue anime from next episode

Layout: unified · split

curd.py +102 −26
@@ -29,6 +29,70 @@ user_id = os.environ.get('ANILIST_USER_ID')
2929def run_script(script):
3030 os.system(f"./scripts/{script}.sh")
3131
32def 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"
54show_adult_content=false
55history_file="$HOME/.local/share/curd/curd_history.txt"
56subs_language="english"
57sub_or_dub="sub"
58score_on_completion=true
59discord_presence=true
60presence_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
92user_config = load_config() # python dictionary containing all the configs as key value pairs
93
94print(user_config)
95
3296print("downloading user data")
3397anilist_user_data = get_user_data(access_token, user_id)
3498with open("response.json", "w") as response:
@@ -48,14 +112,12 @@ except:
48112
49113# os.system("./scripts/anime_list.sh")
50114
51
52115# with open('response.json', 'r') as file:
53116 # data = json.load(file)
54117
55118# print(data)
56119# print(type(data['data']))
57120
58
59121anime_dict = extract_anime_info(anilist_user_data)[0]
60122# print(anime_dict)
61123# anime_dict = load_anime_data("scripts/tmp/anime_list")
@@ -110,22 +172,43 @@ run_script("episode_list")
110172# last_episode = temp[-1]
111173# ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n")
112174
175binge_watching = False
176
113177while 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])
126182
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))
129212
130213 os.system("./scripts/episode_url.sh")
131214
@@ -144,8 +227,8 @@ while True:
144227 salt = random.randint(0,500)
145228 print("SALT IS:"+str(salt))
146229 start_video(links[0][1], salt)
147 # print('test')
148230 command = """echo '{ "command": ["get_property", "playback-time"] }' | socat - /tmp/mpvsocket"""+str(salt)
231
149232 while True:
150233 time.sleep(2)
151234
@@ -172,19 +255,12 @@ while True:
172255 print("Error:", result.stderr)
173256 break
174257
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
181258 except ConnectionRefusedError:
182259 print("Player Closed")
183260 finally:
184261 to_continue_or_not_to_continue = input("Continue? (y/n)\n")
185262 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
187265 else:
188266 break
189# except:
190# pass
\ No newline at end of file