Celeskry commited on
Commit
c3e5aa2
·
verified ·
1 Parent(s): 797f38a

Update app/ht_noti.py

Browse files
Files changed (1) hide show
  1. app/ht_noti.py +96 -3
app/ht_noti.py CHANGED
@@ -4,11 +4,8 @@ from datetime import datetime, timedelta
4
  from typing import Dict, List, Optional
5
  from fastapi import HTTPException
6
 
7
-
8
  class HentaiApp:
9
-
10
  def __init__(self):
11
-
12
  self.base_url = "https://hentaiz3.com/watch"
13
 
14
  self.api_url = (
@@ -221,6 +218,102 @@ class HentaiApp:
221
  detail=f"Parse error: {str(e)}"
222
  )
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
 
225
  async def get_new(self, apikey: Optional[str], system_key: Optional[str]):
226
 
 
4
  from typing import Dict, List, Optional
5
  from fastapi import HTTPException
6
 
 
7
  class HentaiApp:
 
8
  def __init__(self):
 
9
  self.base_url = "https://hentaiz3.com/watch"
10
 
11
  self.api_url = (
 
218
  detail=f"Parse error: {str(e)}"
219
  )
220
 
221
+ async def fetch_info(self, slug: str):
222
+
223
+ url = f"https://hentaiz1.com/watch/{slug}/__data.json?x-sveltekit-invalidated=001"
224
+
225
+ headers = {
226
+ "User-Agent": "Mozilla/5.0"
227
+ }
228
+
229
+ res = self.scraper.get(url, headers=headers, timeout=15)
230
+
231
+ if res.status_code != 200:
232
+ raise HTTPException(status_code=404, detail="Episode not found")
233
+
234
+ raw = res.json()
235
+
236
+ data_pool = raw["nodes"][2]["data"]
237
+
238
+ info = data_pool[1]
239
+
240
+ title = data_pool[info["title"]]
241
+ description = data_pool[info["description"]]
242
+
243
+ episode = info.get("episodeNumber")
244
+ year = info.get("releaseYear")
245
+ views = info.get("viewsTotal")
246
+
247
+ embed_url = data_pool[info["embedUrl"]] if isinstance(info["embedUrl"], int) else info["embedUrl"]
248
+
249
+ published = ""
250
+
251
+ if isinstance(info["publishedAt"], list):
252
+ published = info["publishedAt"][1]
253
+
254
+ # genres
255
+ genres = []
256
+
257
+ genres_ref = info.get("genres")
258
+
259
+ if isinstance(genres_ref, list):
260
+
261
+ for g_idx in genres_ref:
262
+
263
+ g_obj = data_pool[g_idx]
264
+
265
+ if isinstance(g_obj, dict):
266
+
267
+ genre_idx = g_obj.get("genre")
268
+
269
+ if isinstance(genre_idx, int):
270
+
271
+ genre_obj = data_pool[genre_idx]
272
+
273
+ name_idx = genre_obj.get("name")
274
+
275
+ if isinstance(name_idx, int):
276
+ genres.append(data_pool[name_idx])
277
+
278
+
279
+ # studios
280
+ studios = []
281
+
282
+ studios_ref = info.get("studios")
283
+
284
+ if isinstance(studios_ref, list):
285
+
286
+ for s_idx in studios_ref:
287
+
288
+ s_obj = data_pool[s_idx]
289
+
290
+ if isinstance(s_obj, dict):
291
+
292
+ studio_idx = s_obj.get("studio")
293
+
294
+ if isinstance(studio_idx, int):
295
+
296
+ studio_obj = data_pool[studio_idx]
297
+
298
+ name_idx = studio_obj.get("name")
299
+
300
+ if isinstance(name_idx, int):
301
+ studios.append(data_pool[name_idx])
302
+
303
+
304
+ return {
305
+ "ok": True,
306
+ "title": title,
307
+ "slug": slug,
308
+ "episode": episode,
309
+ "year": year,
310
+ "views": views,
311
+ "published_at": published,
312
+ "description": description,
313
+ "embed_url": embed_url,
314
+ "genres": genres,
315
+ "studios": studios
316
+ }
317
 
318
  async def get_new(self, apikey: Optional[str], system_key: Optional[str]):
319