.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 = None
str frontend_url = None
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 (unless an individual values
for ``backend_url`` and ``frontend_url`` are configured for the engine).


.. 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 96 of file piped.py.

96def _backend_url() -> str:
97 from searx.engines import engines # pylint: disable=import-outside-toplevel
98
99 url: list[str] | str = backend_url or engines["piped"].backend_url # type: ignore
100 if isinstance(url, list):
101 url = random.choice(url)
102 return url
103
104
::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 105 of file piped.py.

105def _frontend_url() -> str:
106 from searx.engines import engines # pylint: disable=import-outside-toplevel
107
108 return frontend_url or engines["piped"].frontend_url # type: ignore
109
110

Referenced by response().

Here is the caller graph for this function:

◆ request()

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

Definition at line 111 of file piped.py.

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

References _backend_url().

Here is the call graph for this function:

◆ response()

searx.engines.piped.response ( resp)

Definition at line 130 of file piped.py.

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

◆ backend_url

list searx.engines.piped.backend_url = None

Definition at line 75 of file piped.py.

◆ categories

list searx.engines.piped.categories = []

Definition at line 71 of file piped.py.

◆ frontend_url

str searx.engines.piped.frontend_url = None

Definition at line 86 of file piped.py.

◆ paging

bool searx.engines.piped.paging = True

Definition at line 72 of file piped.py.

◆ piped_filter

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

Definition at line 92 of file piped.py.