.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.piped Namespace Reference

Functions

str _backend_url ()
str _frontend_url ()
 request (query, params)
 response (resp)

Variables

dict about
list categories = []
bool paging = True
list backend_url = "https://pipedapi.kavin.rocks"
str frontend_url = "https://piped.video"
str piped_filter = 'all'

Detailed Description

An alternative privacy-friendly YouTube frontend which is efficient by
design.  `Piped’s architecture`_ consists of 3 components:

- :py:obj:`backend <backend_url>`
- :py:obj:`frontend <frontend_url>`
- proxy

.. _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
    ...

Known Quirks
============

The implementation to support :py:obj:`paging <searx.enginelib.Engine.paging>`
is based on the *nextpage* method of Piped's REST API / the :py:obj:`frontend
API <frontend_url>`.  This feature is *next page driven* and plays well with the
:ref:`infinite_scroll <settings ui>` setting in SearXNG but it does not really
fit into SearXNG's UI to select a page by number.

Implementations
===============

Function Documentation

◆ _backend_url()

str searx.engines.piped._backend_url ( )
protected

Definition at line 93 of file piped.py.

93def _backend_url() -> str:
94 from searx.engines import engines # pylint: disable=import-outside-toplevel
95
96 url = engines['piped'].backend_url # type: ignore
97 if isinstance(url, list):
98 url = random.choice(url)
99 return url
100
101
::1337x
Definition 1337x.py:1

Referenced by request().

Here is the caller graph for this function:

◆ _frontend_url()

str searx.engines.piped._frontend_url ( )
protected

Definition at line 102 of file piped.py.

102def _frontend_url() -> str:
103 from searx.engines import engines # pylint: disable=import-outside-toplevel
104
105 return engines['piped'].frontend_url # type: ignore
106
107

Referenced by response().

Here is the caller graph for this function:

◆ request()

searx.engines.piped.request ( query,
params )

Definition at line 108 of file piped.py.

108def request(query, params):
109
110 args = {
111 'q': query,
112 'filter': piped_filter,
113 }
114
115 path = "/search"
116 if params['pageno'] > 1:
117 # don't use nextpage when user selected to jump back to page 1
118 nextpage = params['engine_data'].get('nextpage')
119 if nextpage:
120 path = "/nextpage/search"
121 args['nextpage'] = nextpage
122
123 params["url"] = _backend_url() + f"{path}?" + urlencode(args)
124 return params
125
126

References _backend_url().

Here is the call graph for this function:

◆ response()

searx.engines.piped.response ( resp)

Definition at line 127 of file piped.py.

127def response(resp):
128 results = []
129
130 json = resp.json()
131
132 for result in json["items"]:
133 # note: piped returns -1 for all upload times when filtering for music
134 uploaded = result.get("uploaded", -1)
135
136 item = {
137 # the api url differs from the frontend, hence use piped.video as default
138 "url": _frontend_url() + result.get("url", ""),
139 "title": result.get("title", ""),
140 "publishedDate": parser.parse(time.ctime(uploaded / 1000)) if uploaded != -1 else None,
141 "iframe_src": _frontend_url() + '/embed' + result.get("url", ""),
142 "views": humanize_number(result["views"]),
143 }
144 length = result.get("duration")
145 if length:
146 item["length"] = datetime.timedelta(seconds=length)
147
148 if piped_filter == 'videos':
149 item["template"] = "videos.html"
150 # if the value of shortDescription set, but is None, return empty string
151 item["content"] = result.get("shortDescription", "") or ""
152 item["thumbnail"] = result.get("thumbnail", "")
153
154 elif piped_filter == 'music_songs':
155 item["template"] = "default.html"
156 item["thumbnail"] = result.get("thumbnail", "")
157 item["content"] = result.get("uploaderName", "") or ""
158
159 results.append(item)
160
161 results.append(
162 {
163 "engine_data": json["nextpage"],
164 "key": "nextpage",
165 }
166 )
167 return results

References _frontend_url().

Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.piped.about
Initial value:
1= {
2 "website": 'https://github.com/TeamPiped/Piped/',
3 "wikidata_id": 'Q107565255',
4 "official_api_documentation": 'https://docs.piped.video/docs/api-documentation/',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 58 of file piped.py.

◆ backend_url

list searx.engines.piped.backend_url = "https://pipedapi.kavin.rocks"

Definition at line 72 of file piped.py.

◆ categories

list searx.engines.piped.categories = []

Definition at line 68 of file piped.py.

◆ frontend_url

str searx.engines.piped.frontend_url = "https://piped.video"

Definition at line 83 of file piped.py.

◆ paging

bool searx.engines.piped.paging = True

Definition at line 69 of file piped.py.

◆ piped_filter

str searx.engines.piped.piped_filter = 'all'

Definition at line 89 of file piped.py.