-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviddla.py
72 lines (57 loc) · 1.97 KB
/
viddla.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Viddla (Videos)
"""
from json import loads
from datetime import datetime
from urllib.parse import urlencode
from searx.utils import match_language, html_to_text
# about
about = {
"website": 'https://vidd.la',
"wikidata_id": None,
"official_api_documentation": 'https://docs.vidd.la/',
"use_official_api": True,
"require_api_key": False,
"results": 'JSON',
}
# engine dependent config
categories = ['videos']
paging = True
time_range_support = True
# search-url
search_url = 'https://api-dev.vidd.la/search?fields=date,title,shdesc,longdesc,duration,url,thumbnail,id&sort=relevance&src=viddla&limit=5&page={pageno}&{query}' # noqa
embedded_url = '<iframe frameborder="0" width="540" height="304" ' +\
'data-src="https://embed.vidd.la/{videoid}" allowfullscreen></iframe>'
# do search-request
def request(query, params):
params['url'] = search_url.format(
query=urlencode({'search': query}),
pageno=params['pageno'])
return params
# get response from search-request
def response(resp):
results = []
search_res = loads(resp.text)
# return empty array if there are no results
if 'list' not in search_res:
return []
# parse results
for res in search_res['list']:
title = res['title']
url = res['url']
content = html_to_text(res['shdesc'])
thumbnail = res['thumbnail']
publishedDate = datetime.fromtimestamp(res['date'], None)
embedded = embedded_url.format(videoid=res['id'])
# http to https
thumbnail = thumbnail.replace("http://", "https://")
results.append({'template': 'videos.html',
'url': url,
'title': title,
'content': content,
'publishedDate': publishedDate,
'embedded': embedded,
'thumbnail': thumbnail})
# return results
return results