101def response(resp):
102 results = []
103
104 response_json = loads(resp.text)
105
106 if not response_json:
107 return []
108
109 for result in response_json.get('results', []):
110 title = result['label']
111 url = result['url'].replace('file://' + mount_prefix, dl_prefix)
112 content = '{}'.format(result['snippet'])
113
114
115 item = {'url': url, 'title': title, 'content': content, 'template': 'files.html'}
116
117 if result['size']:
118 item['size'] = int(result['size'])
119
120 for parameter in ['filename', 'abstract', 'author', 'mtype', 'time']:
121 if result[parameter]:
122 item[parameter] = result[parameter]
123
124
125 if 'mtype' in result and '/' in result['mtype']:
126 (mtype, subtype) = result['mtype'].split('/')
127 item['mtype'] = mtype
128 item['subtype'] = subtype
129
130 if mtype in ['audio', 'video']:
131 item['embedded'] = embedded_url.format(
132 ttype=mtype, url=quote(url.encode('utf8'), '/:'), mtype=result['mtype']
133 )
134
135 if mtype in ['image'] and subtype in ['bmp', 'gif', 'jpeg', 'png']:
136 item['thumbnail'] = url
137
138 results.append(item)
139
140 if 'nres' in response_json:
141 results.append({'number_of_results': response_json['nres']})
142
143 return results