36def response(resp):
37 try:
38 data = resp.json()
39 except Exception as e:
40 raise SearxEngineAPIException(f"Invalid response: {e}") from e
41 results = []
42
43 if not data.get("data", {}).get("list"):
44 raise SearxEngineAPIException("Invalid response")
45
46 for entry in data["data"]["list"]:
47 if not entry.get("titleEsc") or not entry.get("url"):
48 continue
49
50 video_url = entry.get("url")
51 if video_url.startswith("/vc/np"):
52 video_url = f"{base_url}{video_url}"
53
54 published_date = None
55 if entry.get("date") and entry.get("duration"):
56 try:
57 published_date = datetime.strptime(entry['date'], "%Y-%m-%d")
58 except (ValueError, TypeError):
59 published_date = None
60
61 length = None
62 if entry.get("date") and entry.get("duration"):
63 try:
64 timediff = datetime.strptime(entry['duration'], "%M:%S")
65 length = timedelta(minutes=timediff.minute, seconds=timediff.second)
66 except (ValueError, TypeError):
67 length = None
68
69 results.append(
70 {
71 'url': video_url,
72 'title': entry["titleEsc"],
73 'content': entry['site'],
74 'length': length,
75 'template': 'videos.html',
76 'publishedDate': published_date,
77 'thumbnail': entry["picurl"],
78 }
79 )
80
81 return results