mirror of
https://github.com/searxng/searxng.git
synced 2024-11-04 20:30:11 +01:00
[mod] result_templates/default.html replace embedded HTML by data_src audio_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' (and 'audio_src'), an URL for embedded content (<iframe>). Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
b9a2e8b387
commit
98cab4cf75
@ -4,7 +4,7 @@ Bandcamp (Music)
|
||||
@website https://bandcamp.com/
|
||||
@provide-api no
|
||||
@results HTML
|
||||
@parse url, title, content, publishedDate, embedded, thumbnail
|
||||
@parse url, title, content, publishedDate, data_src, thumbnail
|
||||
"""
|
||||
|
||||
from urllib.parse import urlencode, urlparse, parse_qs
|
||||
@ -27,10 +27,7 @@ paging = True
|
||||
|
||||
base_url = "https://bandcamp.com/"
|
||||
search_string = search_string = 'search?{query}&page={page}'
|
||||
embedded_url = '''<iframe width="100%" height="166"
|
||||
scrolling="no" frameborder="no"
|
||||
data-src="https://bandcamp.com/EmbeddedPlayer/{type}={result_id}/size=large/bgcol=ffffff/linkcol=0687f5/tracklist=false/artwork=small/transparent=true/"
|
||||
></iframe>'''
|
||||
data_src = "https://bandcamp.com/EmbeddedPlayer/{type}={result_id}/size=large/bgcol=ffffff/linkcol=0687f5/tracklist=false/artwork=small/transparent=true/"
|
||||
|
||||
|
||||
def request(query, params):
|
||||
@ -74,8 +71,9 @@ def response(resp):
|
||||
if thumbnail:
|
||||
new_result['thumbnail'] = thumbnail[0]
|
||||
if "album" in result.classes:
|
||||
new_result["embedded"] = embedded_url.format(type='album', result_id=result_id)
|
||||
new_result["data_src"] = data_src.format(type='album', result_id=result_id)
|
||||
elif "track" in result.classes:
|
||||
new_result["embedded"] = embedded_url.format(type='track', result_id=result_id)
|
||||
new_result["data_src"] = data_src.format(type='track', result_id=result_id)
|
||||
|
||||
results.append(new_result)
|
||||
return results
|
||||
|
@ -23,13 +23,7 @@ paging = True
|
||||
# search-url
|
||||
url = 'https://api.deezer.com/'
|
||||
search_url = url + 'search?{query}&index={offset}'
|
||||
|
||||
embedded_url = (
|
||||
'<iframe scrolling="no" frameborder="0" allowTransparency="true" '
|
||||
+ 'data-src="https://www.deezer.com/plugins/player?type=tracks&id={audioid}" '
|
||||
+ 'width="540" height="80"></iframe>'
|
||||
)
|
||||
|
||||
data_src = "https://www.deezer.com/plugins/player?type=tracks&id={audioid}"
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
@ -57,10 +51,10 @@ def response(resp):
|
||||
|
||||
content = '{} - {} - {}'.format(result['artist']['name'], result['album']['title'], result['title'])
|
||||
|
||||
embedded = embedded_url.format(audioid=result['id'])
|
||||
|
||||
# append result
|
||||
results.append({'url': url, 'title': title, 'embedded': embedded, 'content': content})
|
||||
results.append(
|
||||
{'url': url, 'title': title, 'data_src': data_src.format(audioid=result['id']), 'content': content}
|
||||
)
|
||||
|
||||
# return results
|
||||
return results
|
||||
|
@ -29,9 +29,6 @@ search_url = (
|
||||
url + "search/text/?query={query}&page={page}&fields=name,url,download,created,description,type&token={api_key}"
|
||||
)
|
||||
|
||||
embedded_url = '<audio controls><source src="{uri}" type="audio/{ftype}"></audio>'
|
||||
|
||||
|
||||
# search request
|
||||
def request(query, params):
|
||||
params["url"] = search_url.format(
|
||||
@ -52,7 +49,6 @@ def response(resp):
|
||||
content = result["description"][:128]
|
||||
publishedDate = datetime.fromisoformat(result["created"])
|
||||
uri = result["download"]
|
||||
embedded = embedded_url.format(uri=uri, ftype=result["type"])
|
||||
|
||||
# append result
|
||||
results.append(
|
||||
@ -60,7 +56,7 @@ def response(resp):
|
||||
"url": result["url"],
|
||||
"title": title,
|
||||
"publishedDate": publishedDate,
|
||||
"embedded": embedded,
|
||||
"audio_src": uri,
|
||||
"content": content,
|
||||
}
|
||||
)
|
||||
|
@ -24,12 +24,7 @@ paging = True
|
||||
# search-url
|
||||
url = 'https://api.mixcloud.com/'
|
||||
search_url = url + 'search/?{query}&type=cloudcast&limit=10&offset={offset}'
|
||||
|
||||
embedded_url = (
|
||||
'<iframe scrolling="no" frameborder="0" allowTransparency="true" '
|
||||
+ 'data-src="https://www.mixcloud.com/widget/iframe/?feed={url}" width="300" height="300"></iframe>'
|
||||
)
|
||||
|
||||
data_src = "https://www.mixcloud.com/widget/iframe/?feed={url}"
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
@ -51,12 +46,17 @@ def response(resp):
|
||||
title = result['name']
|
||||
url = result['url']
|
||||
content = result['user']['name']
|
||||
embedded = embedded_url.format(url=url)
|
||||
publishedDate = parser.parse(result['created_time'])
|
||||
|
||||
# append result
|
||||
results.append(
|
||||
{'url': url, 'title': title, 'embedded': embedded, 'publishedDate': publishedDate, 'content': content}
|
||||
{
|
||||
'url': url,
|
||||
'title': title,
|
||||
'data_src': data_src.format(url=url),
|
||||
'publishedDate': publishedDate,
|
||||
'content': content,
|
||||
}
|
||||
)
|
||||
|
||||
# return results
|
||||
|
@ -37,12 +37,6 @@ search_url = (
|
||||
'&client_id={client_id}'
|
||||
) # noqa
|
||||
|
||||
embedded_url = (
|
||||
'<iframe width="100%" height="166" '
|
||||
+ 'scrolling="no" frameborder="no" '
|
||||
+ 'data-src="https://w.soundcloud.com/player/?url={uri}"></iframe>'
|
||||
)
|
||||
|
||||
cid_re = re.compile(r'client_id:"([^"]*)"', re.I | re.U)
|
||||
guest_client_id = ''
|
||||
|
||||
@ -97,7 +91,6 @@ def response(resp):
|
||||
content = result['description'] or ''
|
||||
publishedDate = parser.parse(result['last_modified'])
|
||||
uri = quote_plus(result['uri'])
|
||||
embedded = embedded_url.format(uri=uri)
|
||||
|
||||
# append result
|
||||
results.append(
|
||||
@ -105,7 +98,7 @@ def response(resp):
|
||||
'url': result['permalink_url'],
|
||||
'title': title,
|
||||
'publishedDate': publishedDate,
|
||||
'embedded': embedded,
|
||||
'data_src': "https://w.soundcloud.com/player/?url=" + uri,
|
||||
'content': content,
|
||||
}
|
||||
)
|
||||
|
@ -29,10 +29,6 @@ api_client_secret = None
|
||||
url = 'https://api.spotify.com/'
|
||||
search_url = url + 'v1/search?{query}&type=track&offset={offset}'
|
||||
|
||||
embedded_url = '<iframe data-src="https://embed.spotify.com/?uri=spotify:track:{audioid}"\
|
||||
width="300" height="80" frameborder="0" allowtransparency="true"></iframe>'
|
||||
|
||||
|
||||
# do search-request
|
||||
def request(query, params):
|
||||
offset = (params['pageno'] - 1) * 20
|
||||
@ -66,10 +62,15 @@ def response(resp):
|
||||
url = result['external_urls']['spotify']
|
||||
content = '{} - {} - {}'.format(result['artists'][0]['name'], result['album']['name'], result['name'])
|
||||
|
||||
embedded = embedded_url.format(audioid=result['id'])
|
||||
|
||||
# append result
|
||||
results.append({'url': url, 'title': title, 'embedded': embedded, 'content': content})
|
||||
results.append(
|
||||
{
|
||||
'url': url,
|
||||
'title': title,
|
||||
'data_src': "https://embed.spotify.com/?uri=spotify:track:" + result['id'],
|
||||
'content': content,
|
||||
}
|
||||
)
|
||||
|
||||
# return results
|
||||
return results
|
||||
|
@ -33,5 +33,10 @@ def on_result(request, search, result):
|
||||
if pattern.search(parsed_data_src.netloc):
|
||||
parsed_data_src = parsed_data_src._replace(netloc=pattern.sub(replacement, parsed_data_src.netloc))
|
||||
result['data_src'] = urlunparse(parsed_data_src)
|
||||
if result.get('audio_src', False):
|
||||
parsed_audio_src = urlparse(result['audio_src'])
|
||||
if pattern.search(parsed_audio_src.netloc):
|
||||
parsed_audio_src = parsed_audio_src._replace(netloc=pattern.sub(replacement, parsed_audio_src.netloc))
|
||||
result['audio_src'] = urlunparse(parsed_audio_src)
|
||||
|
||||
return True
|
||||
|
@ -296,6 +296,16 @@ article[data-vim-selected].category-social {
|
||||
padding: 0 5px 25px 0 !important;
|
||||
}
|
||||
|
||||
.audio-control audio {
|
||||
width: 100%;
|
||||
padding: 10px 0 0 0;
|
||||
}
|
||||
|
||||
.embedded-content iframe {
|
||||
width: 100%;
|
||||
padding: 10px 0 0 0;
|
||||
}
|
||||
|
||||
.result-videos .content {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
@ -3,13 +3,13 @@
|
||||
{{- result_header(result, favicons, 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-media-{{ index }}" data-btn-text-collapsed="{{ _('show media') }}" data-btn-text-not-collapsed="{{ _('hide media') }}" aria-labelledby="result-{{loop.index}}">{{ icon('music') }} {{ _('show media') }}</a></small>
|
||||
{%- endif -%}
|
||||
|
||||
{%- if result.embedded -%}
|
||||
<div id="result-media-{{ index }}" class="collapse">
|
||||
{{- result.embedded|safe -}}
|
||||
{% if result.data_src -%}
|
||||
<div id="result-media-{{ index }}" class="embedded-content invisible">
|
||||
<iframe data-src="{{result.data_src}}" frameborder="0" allowfullscreen></iframe>
|
||||
</div>
|
||||
{%- endif -%}
|
||||
|
||||
@ -24,6 +24,13 @@
|
||||
{%- if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif -%}
|
||||
{%- endif -%}
|
||||
|
||||
{% if result.audio_src -%}
|
||||
<div id="result-media-{{ index }}" class="audio-control">
|
||||
<audio controls><source src="{{result.audio_src}}"></audio>
|
||||
</div>
|
||||
{%- endif %}
|
||||
|
||||
|
||||
{%- if rtl -%}
|
||||
{{ result_footer_rtl(result, loop.index) }}
|
||||
{%- else -%}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
{{ result_header(result, favicons, image_proxify) -}}
|
||||
{{- 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-media-{{ index }}" data-btn-text-collapsed="{{ _('show media') }}" data-btn-text-not-collapsed="{{ _('hide media') }}">{{ icon('music-note') }} {{ _('show media') }}</a></p>
|
||||
{%- endif %}
|
||||
{%- if result.content %}
|
||||
@ -15,9 +15,14 @@
|
||||
</p>
|
||||
{% endif -%}
|
||||
{{- result_sub_footer(result, proxify) -}}
|
||||
{% if result.embedded -%}
|
||||
<div id="result-media-{{ index }}" class="invisible">
|
||||
{{- result.embedded|safe -}}
|
||||
{% if result.data_src -%}
|
||||
<div id="result-media-{{ index }}" class="embedded-content invisible">
|
||||
<iframe data-src="{{result.data_src}}" frameborder="0" allowfullscreen></iframe>
|
||||
</div>
|
||||
{%- endif %}
|
||||
{% if result.audio_src -%}
|
||||
<div id="result-media-{{ index }}" class="audio-control">
|
||||
<audio controls><source src="{{result.audio_src}}"></audio>
|
||||
</div>
|
||||
{%- endif %}
|
||||
{{- result_footer(result) }}
|
||||
|
Loading…
Reference in New Issue
Block a user