Commit
·
049df0c
1
Parent(s):
1fa8166
fix
Browse files- LoadBalancer.py +27 -13
LoadBalancer.py
CHANGED
@@ -95,10 +95,12 @@ class LoadBalancer:
|
|
95 |
# logging.info(f"Cache Size: {cache_size}")
|
96 |
|
97 |
# Process films
|
|
|
98 |
for title, path in film_store.items():
|
99 |
url = f"{instance_url}/api/film/{title.replace(' ', '%20')}"
|
100 |
self.update_film_store_json(title, url)
|
101 |
|
|
|
102 |
# Process TV shows
|
103 |
for title, seasons in tv_store.items():
|
104 |
for season, episodes in seasons.items():
|
@@ -148,8 +150,7 @@ class LoadBalancer:
|
|
148 |
print(f"Error getting system proxies: {e}")
|
149 |
return {}
|
150 |
|
151 |
-
|
152 |
-
def update_film_store_json(title, url):
|
153 |
"""
|
154 |
Updates the film store JSON with the new file.
|
155 |
|
@@ -157,7 +158,7 @@ class LoadBalancer:
|
|
157 |
title (str): The title of the film.
|
158 |
url (str): The url.
|
159 |
"""
|
160 |
-
FILM_STORE_JSON_PATH =
|
161 |
|
162 |
film_store_data = {}
|
163 |
if os.path.exists(FILM_STORE_JSON_PATH):
|
@@ -170,18 +171,11 @@ class LoadBalancer:
|
|
170 |
json.dump(film_store_data, json_file, indent=2)
|
171 |
print(f'Film store updated with {title}.')
|
172 |
|
173 |
-
|
174 |
-
def download_episode(title, season, episode):
|
175 |
-
"""
|
176 |
-
Downloads a episode to a specific instance
|
177 |
-
"""
|
178 |
-
|
179 |
-
@staticmethod
|
180 |
-
def update_tv_store_json(title, season, episode, url):
|
181 |
"""
|
182 |
Updates the TV store JSON with the new file, organizing by title, season, and episode.
|
183 |
"""
|
184 |
-
TV_STORE_JSON_PATH =
|
185 |
|
186 |
tv_store_data = {}
|
187 |
if os.path.exists(TV_STORE_JSON_PATH):
|
@@ -201,6 +195,26 @@ class LoadBalancer:
|
|
201 |
|
202 |
print(f'TV store updated with {title}, {season}, {episode}.')
|
203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
@staticmethod
|
205 |
def is_valid_url(url):
|
206 |
# Simple URL validation (could be more complex if needed)
|
@@ -298,7 +312,7 @@ class LoadBalancer:
|
|
298 |
status = result["status"]
|
299 |
progress_url = f'{best_instance}/api/progress/{episode_id}'
|
300 |
response = {
|
301 |
-
"
|
302 |
"status":status,
|
303 |
"progress_url":progress_url
|
304 |
}
|
|
|
95 |
# logging.info(f"Cache Size: {cache_size}")
|
96 |
|
97 |
# Process films
|
98 |
+
self.clear_json_file(self.FILM_STORE_JSON_PATH)
|
99 |
for title, path in film_store.items():
|
100 |
url = f"{instance_url}/api/film/{title.replace(' ', '%20')}"
|
101 |
self.update_film_store_json(title, url)
|
102 |
|
103 |
+
self.clear_json_file(self.TV_STORE_JSON_PATH)
|
104 |
# Process TV shows
|
105 |
for title, seasons in tv_store.items():
|
106 |
for season, episodes in seasons.items():
|
|
|
150 |
print(f"Error getting system proxies: {e}")
|
151 |
return {}
|
152 |
|
153 |
+
def update_film_store_json(self,title, url):
|
|
|
154 |
"""
|
155 |
Updates the film store JSON with the new file.
|
156 |
|
|
|
158 |
title (str): The title of the film.
|
159 |
url (str): The url.
|
160 |
"""
|
161 |
+
FILM_STORE_JSON_PATH = self.FILM_STORE_JSON_PATH
|
162 |
|
163 |
film_store_data = {}
|
164 |
if os.path.exists(FILM_STORE_JSON_PATH):
|
|
|
171 |
json.dump(film_store_data, json_file, indent=2)
|
172 |
print(f'Film store updated with {title}.')
|
173 |
|
174 |
+
def update_tv_store_json(self, title, season, episode, url):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
"""
|
176 |
Updates the TV store JSON with the new file, organizing by title, season, and episode.
|
177 |
"""
|
178 |
+
TV_STORE_JSON_PATH = self.TV_STORE_JSON_PATH
|
179 |
|
180 |
tv_store_data = {}
|
181 |
if os.path.exists(TV_STORE_JSON_PATH):
|
|
|
195 |
|
196 |
print(f'TV store updated with {title}, {season}, {episode}.')
|
197 |
|
198 |
+
@staticmethod
|
199 |
+
def clear_json_file(file_path):
|
200 |
+
"""
|
201 |
+
Clears the data in a JSON file by replacing its contents with an empty JSON object.
|
202 |
+
|
203 |
+
:param file_path: Path to the JSON file to be cleared
|
204 |
+
"""
|
205 |
+
# Create an empty dictionary to replace the existing data
|
206 |
+
empty_data = {}
|
207 |
+
|
208 |
+
try:
|
209 |
+
# Open the file in write mode
|
210 |
+
with open(file_path, 'w') as json_file:
|
211 |
+
# Write the empty dictionary to the file
|
212 |
+
json.dump(empty_data, json_file)
|
213 |
+
print(f"Successfully cleared the data in {file_path}")
|
214 |
+
except Exception as e:
|
215 |
+
print(f"An error occurred while clearing the data in {file_path}: {e}")
|
216 |
+
|
217 |
+
|
218 |
@staticmethod
|
219 |
def is_valid_url(url):
|
220 |
# Simple URL validation (could be more complex if needed)
|
|
|
312 |
status = result["status"]
|
313 |
progress_url = f'{best_instance}/api/progress/{episode_id}'
|
314 |
response = {
|
315 |
+
"episode_id":episode_id,
|
316 |
"status":status,
|
317 |
"progress_url":progress_url
|
318 |
}
|