58def response(resp):
59 results = []
60
61 search_results = resp.json()
62 base_invidious_url = resp.search_params['base_url'] + "/watch?v="
63
64 for result in search_results:
65 rtype = result.get("type", None)
66 if rtype == "video":
67 videoid = result.get("videoId", None)
68 if not videoid:
69 continue
70
71 url = base_invidious_url + videoid
72 thumbs = result.get("videoThumbnails", [])
73 thumb = next((th for th in thumbs if th["quality"] == "sddefault"), None)
74 if thumb:
75 thumbnail = thumb.get("url", "")
76 else:
77 thumbnail = ""
78
79
80
81 if thumbnail and not urlparse(thumbnail).netloc:
82 thumbnail = resp.search_params['base_url'] + thumbnail
83
84 publishedDate = parser.parse(time.ctime(result.get("published", 0)))
85 length = time.gmtime(result.get("lengthSeconds"))
86 if length.tm_hour:
87 length = time.strftime("%H:%M:%S", length)
88 else:
89 length = time.strftime("%M:%S", length)
90
91 results.append(
92 {
93 "url": url,
94 "title": result.get("title", ""),
95 "content": result.get("description", ""),
96 "length": length,
97 "views": humanize_number(result['viewCount']),
98 "template": "videos.html",
99 "author": result.get("author"),
100 "publishedDate": publishedDate,
101 "iframe_src": resp.search_params['base_url'] + '/embed/' + videoid,
102 "thumbnail": thumbnail,
103 }
104 )
105
106 return results