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

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

Referenced by searx.engines.piped.request().

+ Here is the caller graph for this function:

◆ _frontend_url()

str searx.engines.piped._frontend_url ( )
protected

Definition at line 101 of file piped.py.

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

Referenced by searx.engines.piped.response().

+ Here is the caller graph for this function:

◆ request()

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

Definition at line 107 of file piped.py.

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

References searx.engines.piped._backend_url().

+ Here is the call graph for this function:

◆ response()

searx.engines.piped.response ( resp)

Definition at line 126 of file piped.py.

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

References searx.engines.piped._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 57 of file piped.py.

◆ backend_url

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

Definition at line 71 of file piped.py.

◆ categories

list searx.engines.piped.categories = []

Definition at line 67 of file piped.py.

◆ frontend_url

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

Definition at line 82 of file piped.py.

◆ paging

bool searx.engines.piped.paging = True

Definition at line 68 of file piped.py.

◆ piped_filter

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

Definition at line 88 of file piped.py.