37def response(resp):
38 try:
39 data = resp.json()
40 except Exception as e:
41 raise SearxEngineAPIException(f"Invalid response: {e}") from e
42 results = []
43
44 if "data" not in data or "templates" not in data["data"]:
45 raise SearxEngineAPIException("Invalid response")
46
47 for entry in data["data"]["templates"]:
48 album_info = entry.get("albumInfo", {})
49
50 published_date = None
51 release_time = album_info.get("releaseTime", {}).get("value")
52 if release_time:
53 try:
54 published_date = datetime.strptime(release_time, "%Y-%m-%d")
55 except (ValueError, TypeError):
56 pass
57
58 length = None
59 subscript_content = album_info.get("subscriptContent")
60 if subscript_content:
61 try:
62 time_parts = subscript_content.split(":")
63 if len(time_parts) == 2:
64 minutes, seconds = map(int, time_parts)
65 length = timedelta(minutes=minutes, seconds=seconds)
66 elif len(time_parts) == 3:
67 hours, minutes, seconds = map(int, time_parts)
68 length = timedelta(hours=hours, minutes=minutes, seconds=seconds)
69 except (ValueError, TypeError):
70 pass
71
72 results.append(
73 {
74 'url': album_info.get("pageUrl", "").replace("http://", "https://"),
75 'title': album_info.get("title", ""),
76 'content': album_info.get("brief", {}).get("value", ""),
77 'template': 'videos.html',
78 'length': length,
79 'publishedDate': published_date,
80 'thumbnail': album_info.get("img", ""),
81 }
82 )
83
84 return results