mirror of https://github.com/searxng/searxng.git
[mod] result_templates/videos.html: replace embedded HTML by data_src
Embedded HTML breaks SearXNG architecture. To modularize, HTML is generated in the templates (oscar & simple) and result parameter 'embedded' is replaced by 'data_src', an URL for embedded content (<iframe>). Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
a4942213a1
commit
46e131fdad
|
@ -25,11 +25,6 @@ paging = True
|
||||||
# search-url
|
# search-url
|
||||||
# see http://www.dailymotion.com/doc/api/obj-video.html
|
# see http://www.dailymotion.com/doc/api/obj-video.html
|
||||||
search_url = 'https://api.dailymotion.com/videos?fields=created_time,title,description,duration,url,thumbnail_360_url,id&sort=relevance&limit=5&page={pageno}&{query}' # noqa
|
search_url = 'https://api.dailymotion.com/videos?fields=created_time,title,description,duration,url,thumbnail_360_url,id&sort=relevance&limit=5&page={pageno}&{query}' # noqa
|
||||||
embedded_url = (
|
|
||||||
'<iframe frameborder="0" width="540" height="304" '
|
|
||||||
+ 'data-src="https://www.dailymotion.com/embed/video/{videoid}" allowfullscreen></iframe>'
|
|
||||||
)
|
|
||||||
|
|
||||||
supported_languages_url = 'https://api.dailymotion.com/languages'
|
supported_languages_url = 'https://api.dailymotion.com/languages'
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +59,6 @@ def response(resp):
|
||||||
content = html_to_text(res['description'])
|
content = html_to_text(res['description'])
|
||||||
thumbnail = res['thumbnail_360_url']
|
thumbnail = res['thumbnail_360_url']
|
||||||
publishedDate = datetime.fromtimestamp(res['created_time'], None)
|
publishedDate = datetime.fromtimestamp(res['created_time'], None)
|
||||||
embedded = embedded_url.format(videoid=res['id'])
|
|
||||||
|
|
||||||
# http to https
|
# http to https
|
||||||
thumbnail = thumbnail.replace("http://", "https://")
|
thumbnail = thumbnail.replace("http://", "https://")
|
||||||
|
@ -76,7 +70,7 @@ def response(resp):
|
||||||
'title': title,
|
'title': title,
|
||||||
'content': content,
|
'content': content,
|
||||||
'publishedDate': publishedDate,
|
'publishedDate': publishedDate,
|
||||||
'embedded': embedded,
|
'data_src': "https://www.dailymotion.com/embed/video/" + res['id'],
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -58,14 +58,6 @@ def response(resp):
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
search_results = resp.json()
|
search_results = resp.json()
|
||||||
embedded_url = (
|
|
||||||
'<iframe width="540" height="304" '
|
|
||||||
+ 'data-src="'
|
|
||||||
+ resp.search_params['base_url']
|
|
||||||
+ '/embed/{videoid}" '
|
|
||||||
+ 'frameborder="0" allowfullscreen></iframe>'
|
|
||||||
)
|
|
||||||
|
|
||||||
base_invidious_url = resp.search_params['base_url'] + "/watch?v="
|
base_invidious_url = resp.search_params['base_url'] + "/watch?v="
|
||||||
|
|
||||||
for result in search_results:
|
for result in search_results:
|
||||||
|
@ -76,7 +68,6 @@ def response(resp):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
url = base_invidious_url + videoid
|
url = base_invidious_url + videoid
|
||||||
embedded = embedded_url.format(videoid=videoid)
|
|
||||||
thumbs = result.get("videoThumbnails", [])
|
thumbs = result.get("videoThumbnails", [])
|
||||||
thumb = next((th for th in thumbs if th["quality"] == "sddefault"), None)
|
thumb = next((th for th in thumbs if th["quality"] == "sddefault"), None)
|
||||||
if thumb:
|
if thumb:
|
||||||
|
@ -100,7 +91,7 @@ def response(resp):
|
||||||
"template": "videos.html",
|
"template": "videos.html",
|
||||||
"author": result.get("author"),
|
"author": result.get("author"),
|
||||||
"publishedDate": publishedDate,
|
"publishedDate": publishedDate,
|
||||||
"embedded": embedded,
|
"data_src": resp.search_params['base_url'] + '/embed/' + videoid,
|
||||||
"thumbnail": thumbnail,
|
"thumbnail": thumbnail,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -51,12 +51,6 @@ def response(resp):
|
||||||
|
|
||||||
search_res = loads(resp.text)
|
search_res = loads(resp.text)
|
||||||
|
|
||||||
embedded_url = (
|
|
||||||
'<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts allow-popups" '
|
|
||||||
+ 'src="'
|
|
||||||
+ sanitized_url
|
|
||||||
+ '{embed_path}" frameborder="0" allowfullscreen></iframe>'
|
|
||||||
)
|
|
||||||
# return empty array if there are no results
|
# return empty array if there are no results
|
||||||
if "data" not in search_res:
|
if "data" not in search_res:
|
||||||
return []
|
return []
|
||||||
|
@ -72,7 +66,6 @@ def response(resp):
|
||||||
content = ""
|
content = ""
|
||||||
thumbnail = sanitized_url + res["thumbnailPath"]
|
thumbnail = sanitized_url + res["thumbnailPath"]
|
||||||
publishedDate = datetime.strptime(res["publishedAt"], "%Y-%m-%dT%H:%M:%S.%fZ")
|
publishedDate = datetime.strptime(res["publishedAt"], "%Y-%m-%dT%H:%M:%S.%fZ")
|
||||||
embedded = embedded_url.format(embed_path=res["embedPath"])
|
|
||||||
|
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
|
@ -81,7 +74,7 @@ def response(resp):
|
||||||
"title": title,
|
"title": title,
|
||||||
"content": content,
|
"content": content,
|
||||||
"publishedDate": publishedDate,
|
"publishedDate": publishedDate,
|
||||||
"embedded": embedded,
|
"data_src": sanitized_url + res["embedPath"],
|
||||||
"thumbnail": thumbnail,
|
"thumbnail": thumbnail,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -41,9 +41,6 @@ time_range_table = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
embedded_url = '<iframe width="540" height="304" src="{url}" frameborder="0" allowfullscreen></iframe>'
|
|
||||||
|
|
||||||
|
|
||||||
def minute_to_hm(minute):
|
def minute_to_hm(minute):
|
||||||
if isinstance(minute, int):
|
if isinstance(minute, int):
|
||||||
return "%d:%02d" % (divmod(minute, 60))
|
return "%d:%02d" % (divmod(minute, 60))
|
||||||
|
@ -88,7 +85,6 @@ def response(resp):
|
||||||
content = result['description']
|
content = result['description']
|
||||||
thumbnail = result['thumbnailUrl']
|
thumbnail = result['thumbnailUrl']
|
||||||
publishedDate = parser.parse(result['publishedAt'])
|
publishedDate = parser.parse(result['publishedAt'])
|
||||||
embedded = embedded_url.format(url=result.get('embedUrl'))
|
|
||||||
author = result.get('account', {}).get('displayName')
|
author = result.get('account', {}).get('displayName')
|
||||||
length = minute_to_hm(result.get('duration'))
|
length = minute_to_hm(result.get('duration'))
|
||||||
url = result['url']
|
url = result['url']
|
||||||
|
@ -102,7 +98,7 @@ def response(resp):
|
||||||
'length': length,
|
'length': length,
|
||||||
'template': 'videos.html',
|
'template': 'videos.html',
|
||||||
'publishedDate': publishedDate,
|
'publishedDate': publishedDate,
|
||||||
'embedded': embedded,
|
'data_src': result.get('embedUrl'),
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -25,12 +25,6 @@ paging = True
|
||||||
base_url = 'https://vimeo.com/'
|
base_url = 'https://vimeo.com/'
|
||||||
search_url = base_url + '/search/page:{pageno}?{query}'
|
search_url = base_url + '/search/page:{pageno}?{query}'
|
||||||
|
|
||||||
embedded_url = (
|
|
||||||
'<iframe data-src="https://player.vimeo.com/video/{videoid}" '
|
|
||||||
+ 'width="540" height="304" frameborder="0" '
|
|
||||||
+ 'webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# do search-request
|
# do search-request
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
|
@ -54,7 +48,6 @@ def response(resp):
|
||||||
title = result['name']
|
title = result['name']
|
||||||
thumbnail = result['pictures']['sizes'][-1]['link']
|
thumbnail = result['pictures']['sizes'][-1]['link']
|
||||||
publishedDate = parser.parse(result['created_time'])
|
publishedDate = parser.parse(result['created_time'])
|
||||||
embedded = embedded_url.format(videoid=videoid)
|
|
||||||
|
|
||||||
# append result
|
# append result
|
||||||
results.append(
|
results.append(
|
||||||
|
@ -64,7 +57,7 @@ def response(resp):
|
||||||
'content': '',
|
'content': '',
|
||||||
'template': 'videos.html',
|
'template': 'videos.html',
|
||||||
'publishedDate': publishedDate,
|
'publishedDate': publishedDate,
|
||||||
'embedded': embedded,
|
'data_src': "https://player.vimeo.com/video/" + videoid,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -26,13 +26,6 @@ api_key = None
|
||||||
# search-url
|
# search-url
|
||||||
base_url = 'https://www.googleapis.com/youtube/v3/search'
|
base_url = 'https://www.googleapis.com/youtube/v3/search'
|
||||||
search_url = base_url + '?part=snippet&{query}&maxResults=20&key={api_key}'
|
search_url = base_url + '?part=snippet&{query}&maxResults=20&key={api_key}'
|
||||||
|
|
||||||
embedded_url = (
|
|
||||||
'<iframe width="540" height="304" '
|
|
||||||
+ 'data-src="https://www.youtube-nocookie.com/embed/{videoid}" '
|
|
||||||
+ 'frameborder="0" allowfullscreen></iframe>'
|
|
||||||
)
|
|
||||||
|
|
||||||
base_youtube_url = 'https://www.youtube.com/watch?v='
|
base_youtube_url = 'https://www.youtube.com/watch?v='
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,8 +70,6 @@ def response(resp):
|
||||||
|
|
||||||
url = base_youtube_url + videoid
|
url = base_youtube_url + videoid
|
||||||
|
|
||||||
embedded = embedded_url.format(videoid=videoid)
|
|
||||||
|
|
||||||
# append result
|
# append result
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
|
@ -87,7 +78,7 @@ def response(resp):
|
||||||
'content': content,
|
'content': content,
|
||||||
'template': 'videos.html',
|
'template': 'videos.html',
|
||||||
'publishedDate': publishedDate,
|
'publishedDate': publishedDate,
|
||||||
'embedded': embedded,
|
'data_src': "https://www.youtube-nocookie.com/embed/" + videoid,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -32,12 +32,6 @@ time_range_url = '&sp=EgII{time_range}%253D%253D'
|
||||||
next_page_url = 'https://www.youtube.com/youtubei/v1/search?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8'
|
next_page_url = 'https://www.youtube.com/youtubei/v1/search?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8'
|
||||||
time_range_dict = {'day': 'Ag', 'week': 'Aw', 'month': 'BA', 'year': 'BQ'}
|
time_range_dict = {'day': 'Ag', 'week': 'Aw', 'month': 'BA', 'year': 'BQ'}
|
||||||
|
|
||||||
embedded_url = (
|
|
||||||
'<iframe width="540" height="304" '
|
|
||||||
+ 'data-src="https://www.youtube-nocookie.com/embed/{videoid}" '
|
|
||||||
+ 'frameborder="0" allowfullscreen></iframe>'
|
|
||||||
)
|
|
||||||
|
|
||||||
base_youtube_url = 'https://www.youtube.com/watch?v='
|
base_youtube_url = 'https://www.youtube.com/watch?v='
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,7 +85,7 @@ def parse_next_page_response(response_text):
|
||||||
'author': section['ownerText']['runs'][0]['text'],
|
'author': section['ownerText']['runs'][0]['text'],
|
||||||
'length': section['lengthText']['simpleText'],
|
'length': section['lengthText']['simpleText'],
|
||||||
'template': 'videos.html',
|
'template': 'videos.html',
|
||||||
'embedded': embedded_url.format(videoid=section['videoId']),
|
'data_src': 'https://www.youtube-nocookie.com/embed/' + section['videoId'],
|
||||||
'thumbnail': section['thumbnail']['thumbnails'][-1]['url'],
|
'thumbnail': section['thumbnail']['thumbnails'][-1]['url'],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -150,7 +144,6 @@ def parse_first_page_response(response_text):
|
||||||
thumbnail = 'https://i.ytimg.com/vi/' + videoid + '/hqdefault.jpg'
|
thumbnail = 'https://i.ytimg.com/vi/' + videoid + '/hqdefault.jpg'
|
||||||
title = get_text_from_json(video.get('title', {}))
|
title = get_text_from_json(video.get('title', {}))
|
||||||
content = get_text_from_json(video.get('descriptionSnippet', {}))
|
content = get_text_from_json(video.get('descriptionSnippet', {}))
|
||||||
embedded = embedded_url.format(videoid=videoid)
|
|
||||||
author = get_text_from_json(video.get('ownerText', {}))
|
author = get_text_from_json(video.get('ownerText', {}))
|
||||||
length = get_text_from_json(video.get('lengthText', {}))
|
length = get_text_from_json(video.get('lengthText', {}))
|
||||||
|
|
||||||
|
@ -163,7 +156,7 @@ def parse_first_page_response(response_text):
|
||||||
'author': author,
|
'author': author,
|
||||||
'length': length,
|
'length': length,
|
||||||
'template': 'videos.html',
|
'template': 'videos.html',
|
||||||
'embedded': embedded,
|
'data_src': 'https://www.youtube-nocookie.com/embed/' + videoid,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -300,6 +300,12 @@ article[data-vim-selected].category-social {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.result-videos .embedded-video iframe {
|
||||||
|
width: 100%;
|
||||||
|
aspect-ratio: 16 / 9;
|
||||||
|
padding: 10px 0 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
.engines {
|
.engines {
|
||||||
.ltr-float-right();
|
.ltr-float-right();
|
||||||
color: var(--color-result-engines-font);
|
color: var(--color-result-engines-font);
|
||||||
|
|
|
@ -3,15 +3,15 @@
|
||||||
{{- result_header(result, favicons, loop.index) -}}
|
{{- result_header(result, favicons, loop.index) -}}
|
||||||
{{- result_sub_header(result, loop.index) -}}
|
{{- result_sub_header(result, loop.index) -}}
|
||||||
|
|
||||||
{%- if result.embedded -%}
|
{%- if result.data_src -%}
|
||||||
<small> • <a class="text-info btn-collapse collapsed cursor-pointer media-loader disabled_if_nojs" data-toggle="collapse" data-target="#result-video-{{ index }}" data-btn-text-collapsed="{{ _('show video') }}" data-btn-text-not-collapsed="{{ _('hide video') }}" aria-labelledby="result-{{loop.index}}">{{ icon('film') }} {{ _('show video') }}</a></small>
|
<small> • <a class="text-info btn-collapse collapsed cursor-pointer media-loader disabled_if_nojs" data-toggle="collapse" data-target="#result-video-{{ index }}" data-btn-text-collapsed="{{ _('show video') }}" data-btn-text-not-collapsed="{{ _('hide video') }}" aria-labelledby="result-{{loop.index}}">{{ icon('film') }} {{ _('show video') }}</a></small>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
{%- if result.embedded -%}
|
{% if result.data_src -%}
|
||||||
<div id="result-video-{{ index }}" class="collapse">
|
<div id="result-video-{{ index }}" class="embedded-video collapse">
|
||||||
{{- result.embedded|safe -}}
|
<iframe data-src="{{result.data_src}}" width="540" height="304" frameborder="0" allowfullscreen></iframe>
|
||||||
</div>
|
</div>
|
||||||
{%- endif -%}
|
{%- endif %}
|
||||||
|
|
||||||
<div class="container-fluid">{{- "" -}}
|
<div class="container-fluid">{{- "" -}}
|
||||||
<div class="row">{{- "" -}}
|
<div class="row">{{- "" -}}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{{ result_header(result, favicons, image_proxify) }}
|
{{ result_header(result, favicons, image_proxify) }}
|
||||||
{{ result_sub_header(result) }}
|
{{ result_sub_header(result) }}
|
||||||
{% if result.embedded -%}
|
{% if result.data_src -%}
|
||||||
<p class="altlink"> • <a class="btn-collapse collapsed media-loader disabled_if_nojs" data-target="#result-video-{{ index }}" data-btn-text-collapsed="{{ _('show video') }}" data-btn-text-not-collapsed="{{ _('hide video') }}">{{ icon('film-outline') }} {{ _('show video') }}</a></p>
|
<p class="altlink"> • <a class="btn-collapse collapsed media-loader disabled_if_nojs" data-target="#result-video-{{ index }}" data-btn-text-collapsed="{{ _('show video') }}" data-btn-text-not-collapsed="{{ _('hide video') }}">{{ icon('film-outline') }} {{ _('show video') }}</a></p>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- if result.content %}
|
{%- if result.content %}
|
||||||
|
@ -16,9 +16,9 @@
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
</p>
|
</p>
|
||||||
{{- result_sub_footer(result, proxify) -}}
|
{{- result_sub_footer(result, proxify) -}}
|
||||||
{% if result.embedded -%}
|
{% if result.data_src -%}
|
||||||
<div id="result-video-{{ index }}" class="invisible">
|
<div id="result-video-{{ index }}" class="embedded-video invisible">
|
||||||
{{- result.embedded|safe -}}
|
<iframe data-src="{{result.data_src}}" frameborder="0" allowfullscreen></iframe>
|
||||||
</div>
|
</div>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{{ result_footer(result) }}
|
{{ result_footer(result) }}
|
||||||
|
|
Loading…
Reference in New Issue