forked from Ponysearch/Ponysearch
[mod] engine piped: split into two dedicated engiens for video & music
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
7aa95d2d52
commit
ef5831cd84
2 changed files with 81 additions and 25 deletions
|
@ -9,6 +9,29 @@ design. `Piped’s architecture`_ consists of 3 components:
|
||||||
|
|
||||||
.. _Piped’s architecture: https://docs.piped.video/docs/architecture/
|
.. _Piped’s architecture: https://docs.piped.video/docs/architecture/
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
The :py:obj:`backend_url` and :py:obj:`frontend_url` has to be set in the engine
|
||||||
|
named `piped` and are used by all piped engines
|
||||||
|
|
||||||
|
.. code:: yaml
|
||||||
|
|
||||||
|
- name: piped
|
||||||
|
engine: piped
|
||||||
|
piped_filter: videos
|
||||||
|
...
|
||||||
|
frontend_url: https://..
|
||||||
|
backend_url:
|
||||||
|
- https://..
|
||||||
|
- https://..
|
||||||
|
|
||||||
|
- name: piped.music
|
||||||
|
engine: piped
|
||||||
|
network: piped
|
||||||
|
shortcut: ppdm
|
||||||
|
piped_filter: music_songs
|
||||||
|
...
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
@ -16,6 +39,7 @@ from __future__ import annotations
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
import datetime
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
|
|
||||||
# about
|
# about
|
||||||
|
@ -29,7 +53,7 @@ about = {
|
||||||
}
|
}
|
||||||
|
|
||||||
# engine dependent config
|
# engine dependent config
|
||||||
categories = ["videos", "music"]
|
categories = []
|
||||||
paging = False
|
paging = False
|
||||||
|
|
||||||
# search-url
|
# search-url
|
||||||
|
@ -50,17 +74,29 @@ frontend_url: str = "https://piped.video"
|
||||||
.. _Piped-Frontend: https://github.com/TeamPiped/Piped
|
.. _Piped-Frontend: https://github.com/TeamPiped/Piped
|
||||||
"""
|
"""
|
||||||
|
|
||||||
content_filter = 'videos'
|
piped_filter = 'all'
|
||||||
"""Content filter ``music_albums`` or ``videos``"""
|
"""Content filter ``music_songs`` or ``videos``"""
|
||||||
|
|
||||||
|
|
||||||
|
def _backend_url() -> str:
|
||||||
|
from searx.engines import engines # pylint: disable=import-outside-toplevel
|
||||||
|
|
||||||
|
url = engines['piped'].backend_url # type: ignore
|
||||||
|
if isinstance(url, list):
|
||||||
|
url = random.choice(url)
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
def _frontend_url() -> str:
|
||||||
|
from searx.engines import engines # pylint: disable=import-outside-toplevel
|
||||||
|
|
||||||
|
return engines['piped'].frontend_url # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def request(query, params):
|
def request(query, params):
|
||||||
if isinstance(backend_url, list):
|
|
||||||
base_url = random.choice(backend_url)
|
|
||||||
else:
|
|
||||||
base_url = backend_url
|
|
||||||
|
|
||||||
query = urlencode({'q': query})
|
query = urlencode({'q': query})
|
||||||
params["url"] = base_url + f"/search?{query}&filter={content_filter}"
|
params["url"] = _backend_url() + f"/search?{query}&filter={piped_filter}"
|
||||||
|
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
@ -73,17 +109,27 @@ def response(resp):
|
||||||
for result in search_results:
|
for result in search_results:
|
||||||
publishedDate = parser.parse(time.ctime(result.get("uploaded", 0) / 1000))
|
publishedDate = parser.parse(time.ctime(result.get("uploaded", 0) / 1000))
|
||||||
|
|
||||||
results.append(
|
item = {
|
||||||
{
|
|
||||||
# the api url differs from the frontend, hence use piped.video as default
|
# the api url differs from the frontend, hence use piped.video as default
|
||||||
"url": frontend_url + result.get("url", ""),
|
"url": _frontend_url() + result.get("url", ""),
|
||||||
"title": result.get("title", ""),
|
"title": result.get("title", ""),
|
||||||
"content": result.get("shortDescription", ""),
|
|
||||||
"template": "videos.html",
|
|
||||||
"publishedDate": publishedDate,
|
"publishedDate": publishedDate,
|
||||||
"iframe_src": frontend_url + '/embed' + result.get("url", ""),
|
"iframe_src": _frontend_url() + '/embed' + result.get("url", ""),
|
||||||
"thumbnail": result.get("thumbnail", ""),
|
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
if piped_filter == 'videos':
|
||||||
|
item["template"] = "videos.html"
|
||||||
|
item["content"] = result.get("shortDescription", "")
|
||||||
|
item["thumbnail"] = result.get("thumbnail", "")
|
||||||
|
|
||||||
|
elif piped_filter == 'music_songs':
|
||||||
|
item["template"] = "default.html"
|
||||||
|
item["img_src"] = result.get("thumbnail", "")
|
||||||
|
item["content"] = result.get("uploaderName", "")
|
||||||
|
length = result.get("duration")
|
||||||
|
if length:
|
||||||
|
item["length"] = datetime.timedelta(seconds=length)
|
||||||
|
|
||||||
|
results.append(item)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -1137,16 +1137,26 @@ engines:
|
||||||
|
|
||||||
- name: piped
|
- name: piped
|
||||||
engine: piped
|
engine: piped
|
||||||
|
shortcut: ppd
|
||||||
|
categories: videos
|
||||||
|
piped_filter: videos
|
||||||
|
timeout: 3.0
|
||||||
|
|
||||||
|
# URL to use as link and for embeds
|
||||||
|
frontend_url: https://srv.piped.video
|
||||||
# Instance will be selected randomly, for more see https://piped-instances.kavin.rocks/
|
# Instance will be selected randomly, for more see https://piped-instances.kavin.rocks/
|
||||||
backend_url:
|
backend_url:
|
||||||
- https://pipedapi.kavin.rocks
|
- https://pipedapi.kavin.rocks
|
||||||
- https://pipedapi-libre.kavin.rocks
|
- https://pipedapi-libre.kavin.rocks
|
||||||
- https://pipedapi.adminforge.de
|
- https://pipedapi.adminforge.de
|
||||||
# URL to use as link and for embeds
|
|
||||||
frontend_url: https://srv.piped.video
|
- name: piped.music
|
||||||
shortcut: ppd
|
engine: piped
|
||||||
|
network: piped
|
||||||
|
shortcut: ppdm
|
||||||
|
categories: music
|
||||||
|
piped_filter: music_songs
|
||||||
timeout: 3.0
|
timeout: 3.0
|
||||||
disabled: true
|
|
||||||
|
|
||||||
- name: piratebay
|
- name: piratebay
|
||||||
engine: piratebay
|
engine: piratebay
|
||||||
|
|
Loading…
Reference in a new issue