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

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

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

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

+ Here is the caller graph for this function:

◆ request()

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

Definition at line 109 of file piped.py.

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

References searx.engines.piped._backend_url().

+ Here is the call graph for this function:

◆ response()

searx.engines.piped.response ( resp)

Definition at line 128 of file piped.py.

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

◆ backend_url

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

Definition at line 73 of file piped.py.

◆ categories

list searx.engines.piped.categories = []

Definition at line 69 of file piped.py.

◆ frontend_url

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

Definition at line 84 of file piped.py.

◆ paging

bool searx.engines.piped.paging = True

Definition at line 70 of file piped.py.

◆ piped_filter

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

Definition at line 90 of file piped.py.