forked from Ponysearch/Ponysearch
[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
10 changed files with 62 additions and 53 deletions
|
@ -4,7 +4,7 @@ Bandcamp (Music)
|
||||||
@website https://bandcamp.com/
|
@website https://bandcamp.com/
|
||||||
@provide-api no
|
@provide-api no
|
||||||
@results HTML
|
@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
|
from urllib.parse import urlencode, urlparse, parse_qs
|
||||||
|
@ -27,10 +27,7 @@ paging = True
|
||||||
|
|
||||||
base_url = "https://bandcamp.com/"
|
base_url = "https://bandcamp.com/"
|
||||||
search_string = search_string = 'search?{query}&page={page}'
|
search_string = search_string = 'search?{query}&page={page}'
|
||||||
embedded_url = '''<iframe width="100%" height="166"
|
data_src = "https://bandcamp.com/EmbeddedPlayer/{type}={result_id}/size=large/bgcol=ffffff/linkcol=0687f5/tracklist=false/artwork=small/transparent=true/"
|
||||||
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>'''
|
|
||||||
|
|
||||||
|
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
|
@ -74,8 +71,9 @@ def response(resp):
|
||||||
if thumbnail:
|
if thumbnail:
|
||||||
new_result['thumbnail'] = thumbnail[0]
|
new_result['thumbnail'] = thumbnail[0]
|
||||||
if "album" in result.classes:
|
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:
|
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)
|
results.append(new_result)
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -23,13 +23,7 @@ paging = True
|
||||||
# search-url
|
# search-url
|
||||||
url = 'https://api.deezer.com/'
|
url = 'https://api.deezer.com/'
|
||||||
search_url = url + 'search?{query}&index={offset}'
|
search_url = url + 'search?{query}&index={offset}'
|
||||||
|
data_src = "https://www.deezer.com/plugins/player?type=tracks&id={audioid}"
|
||||||
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>'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# do search-request
|
# do search-request
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
|
@ -57,10 +51,10 @@ def response(resp):
|
||||||
|
|
||||||
content = '{} - {} - {}'.format(result['artist']['name'], result['album']['title'], result['title'])
|
content = '{} - {} - {}'.format(result['artist']['name'], result['album']['title'], result['title'])
|
||||||
|
|
||||||
embedded = embedded_url.format(audioid=result['id'])
|
|
||||||
|
|
||||||
# append result
|
# 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
|
||||||
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}"
|
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
|
# search request
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
params["url"] = search_url.format(
|
params["url"] = search_url.format(
|
||||||
|
@ -52,7 +49,6 @@ def response(resp):
|
||||||
content = result["description"][:128]
|
content = result["description"][:128]
|
||||||
publishedDate = datetime.fromisoformat(result["created"])
|
publishedDate = datetime.fromisoformat(result["created"])
|
||||||
uri = result["download"]
|
uri = result["download"]
|
||||||
embedded = embedded_url.format(uri=uri, ftype=result["type"])
|
|
||||||
|
|
||||||
# append result
|
# append result
|
||||||
results.append(
|
results.append(
|
||||||
|
@ -60,7 +56,7 @@ def response(resp):
|
||||||
"url": result["url"],
|
"url": result["url"],
|
||||||
"title": title,
|
"title": title,
|
||||||
"publishedDate": publishedDate,
|
"publishedDate": publishedDate,
|
||||||
"embedded": embedded,
|
"audio_src": uri,
|
||||||
"content": content,
|
"content": content,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,12 +24,7 @@ paging = True
|
||||||
# search-url
|
# search-url
|
||||||
url = 'https://api.mixcloud.com/'
|
url = 'https://api.mixcloud.com/'
|
||||||
search_url = url + 'search/?{query}&type=cloudcast&limit=10&offset={offset}'
|
search_url = url + 'search/?{query}&type=cloudcast&limit=10&offset={offset}'
|
||||||
|
data_src = "https://www.mixcloud.com/widget/iframe/?feed={url}"
|
||||||
embedded_url = (
|
|
||||||
'<iframe scrolling="no" frameborder="0" allowTransparency="true" '
|
|
||||||
+ 'data-src="https://www.mixcloud.com/widget/iframe/?feed={url}" width="300" height="300"></iframe>'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# do search-request
|
# do search-request
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
|
@ -51,12 +46,17 @@ def response(resp):
|
||||||
title = result['name']
|
title = result['name']
|
||||||
url = result['url']
|
url = result['url']
|
||||||
content = result['user']['name']
|
content = result['user']['name']
|
||||||
embedded = embedded_url.format(url=url)
|
|
||||||
publishedDate = parser.parse(result['created_time'])
|
publishedDate = parser.parse(result['created_time'])
|
||||||
|
|
||||||
# append result
|
# append result
|
||||||
results.append(
|
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
|
# return results
|
||||||
|
|
|
@ -37,12 +37,6 @@ search_url = (
|
||||||
'&client_id={client_id}'
|
'&client_id={client_id}'
|
||||||
) # noqa
|
) # 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)
|
cid_re = re.compile(r'client_id:"([^"]*)"', re.I | re.U)
|
||||||
guest_client_id = ''
|
guest_client_id = ''
|
||||||
|
|
||||||
|
@ -97,7 +91,6 @@ def response(resp):
|
||||||
content = result['description'] or ''
|
content = result['description'] or ''
|
||||||
publishedDate = parser.parse(result['last_modified'])
|
publishedDate = parser.parse(result['last_modified'])
|
||||||
uri = quote_plus(result['uri'])
|
uri = quote_plus(result['uri'])
|
||||||
embedded = embedded_url.format(uri=uri)
|
|
||||||
|
|
||||||
# append result
|
# append result
|
||||||
results.append(
|
results.append(
|
||||||
|
@ -105,7 +98,7 @@ def response(resp):
|
||||||
'url': result['permalink_url'],
|
'url': result['permalink_url'],
|
||||||
'title': title,
|
'title': title,
|
||||||
'publishedDate': publishedDate,
|
'publishedDate': publishedDate,
|
||||||
'embedded': embedded,
|
'data_src': "https://w.soundcloud.com/player/?url=" + uri,
|
||||||
'content': content,
|
'content': content,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -29,10 +29,6 @@ api_client_secret = None
|
||||||
url = 'https://api.spotify.com/'
|
url = 'https://api.spotify.com/'
|
||||||
search_url = url + 'v1/search?{query}&type=track&offset={offset}'
|
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
|
# do search-request
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
offset = (params['pageno'] - 1) * 20
|
offset = (params['pageno'] - 1) * 20
|
||||||
|
@ -66,10 +62,15 @@ def response(resp):
|
||||||
url = result['external_urls']['spotify']
|
url = result['external_urls']['spotify']
|
||||||
content = '{} - {} - {}'.format(result['artists'][0]['name'], result['album']['name'], result['name'])
|
content = '{} - {} - {}'.format(result['artists'][0]['name'], result['album']['name'], result['name'])
|
||||||
|
|
||||||
embedded = embedded_url.format(audioid=result['id'])
|
|
||||||
|
|
||||||
# append result
|
# 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
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -33,5 +33,10 @@ def on_result(request, search, result):
|
||||||
if pattern.search(parsed_data_src.netloc):
|
if pattern.search(parsed_data_src.netloc):
|
||||||
parsed_data_src = parsed_data_src._replace(netloc=pattern.sub(replacement, 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)
|
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
|
return True
|
||||||
|
|
|
@ -296,6 +296,16 @@ article[data-vim-selected].category-social {
|
||||||
padding: 0 5px 25px 0 !important;
|
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 {
|
.result-videos .content {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
{{- 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-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>
|
<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 -%}
|
{%- endif -%}
|
||||||
|
|
||||||
{%- if result.embedded -%}
|
{% if result.data_src -%}
|
||||||
<div id="result-media-{{ index }}" class="collapse">
|
<div id="result-media-{{ index }}" class="embedded-content invisible">
|
||||||
{{- result.embedded|safe -}}
|
<iframe data-src="{{result.data_src}}" frameborder="0" allowfullscreen></iframe>
|
||||||
</div>
|
</div>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
|
@ -24,6 +24,13 @@
|
||||||
{%- if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif -%}
|
{%- if result.content %}<p class="result-content">{{ result.content|safe }}</p>{% endif -%}
|
||||||
{%- 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 -%}
|
{%- if rtl -%}
|
||||||
{{ result_footer_rtl(result, loop.index) }}
|
{{ result_footer_rtl(result, loop.index) }}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
|
|
|
@ -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-media-{{ index }}" data-btn-text-collapsed="{{ _('show media') }}" data-btn-text-not-collapsed="{{ _('hide media') }}">{{ icon('music-note') }} {{ _('show media') }}</a></p>
|
<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 %}
|
{%- endif %}
|
||||||
{%- if result.content %}
|
{%- if result.content %}
|
||||||
|
@ -15,9 +15,14 @@
|
||||||
</p>
|
</p>
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{{- result_sub_footer(result, proxify) -}}
|
{{- result_sub_footer(result, proxify) -}}
|
||||||
{% if result.embedded -%}
|
{% if result.data_src -%}
|
||||||
<div id="result-media-{{ index }}" class="invisible">
|
<div id="result-media-{{ index }}" class="embedded-content invisible">
|
||||||
{{- result.embedded|safe -}}
|
<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>
|
</div>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{{- result_footer(result) }}
|
{{- result_footer(result) }}
|
||||||
|
|
Loading…
Reference in a new issue