41def response(resp):
42
43 results = []
44 json = resp.json()
45 now = datetime.now()
46
47
48
49 for result in json.get('result', []):
50
51 title = result.get("title")
52 thumbnailUrl = result.get("thumbnailUrl")
53 category = result.get("category/name")
54 username = result.get("user", {}).get("userName", "")
55 url = f'https://live.space/watch/{username}'
56
57
58
59
60 tags = ''
61 if result.get("tags"):
62 tags = [x for x in result.get("tags").split(';') if x and x != 'null']
63 tags = ', '.join(tags)
64
65 content = []
66 if category:
67 content.append(f'category - {category}')
68
69 if tags and len(tags) > 0:
70 content.append(f'tags - {tags}')
71
72
73 start_time = None
74 if result.get("startTimeStamp"):
75 start_time = datetime.fromtimestamp(result.get("startTimeStamp") / 1000)
76
77
78 end_time = None
79 if result.get("endTimeStamp"):
80 end_time = datetime.fromtimestamp(result.get("endTimeStamp") / 1000)
81
82 timestring = ""
83 if start_time:
84 delta = (now if end_time is None else end_time) - start_time
85 timestring = dates.format_timedelta(delta, granularity='second')
86
87 results.append(
88 {
89 'url': url,
90 'title': title,
91 'content': "No category or tags." if len(content) == 0 else ' '.join(content),
92 'author': username,
93 'length': (">= " if end_time is None else "") + timestring,
94 'publishedDate': start_time,
95 'thumbnail': thumbnailUrl,
96 'template': 'videos.html',
97 }
98 )
99
100 return results