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

Functions

 minute_to_hm (minute)
 
 request (query, params)
 
 response (resp)
 
 video_response (resp)
 
 fetch_traits (EngineTraits engine_traits)
 

Variables

dict about
 
list categories = ["videos"]
 
bool paging = True
 
str base_url = "https://peer.tube"
 
bool time_range_support = True
 
dict time_range_table
 
bool safesearch = True
 
dict safesearch_table = {0: 'both', 1: 'false', 2: 'false'}
 

Detailed Description

Peertube and :py:obj:`SepiaSearch <searx.engines.sepiasearch>` do share
(more or less) the same REST API and the schema of the JSON result is identical.

Function Documentation

◆ fetch_traits()

searx.engines.peertube.fetch_traits ( EngineTraits engine_traits)
Fetch languages from peertube's search-index source code.

See videoLanguages_ in commit `8ed5c729 - Refactor and redesign client`_

.. _8ed5c729 - Refactor and redesign client:
   https://framagit.org/framasoft/peertube/search-index/-/commit/8ed5c729
.. _videoLanguages:
   https://framagit.org/framasoft/peertube/search-index/-/commit/8ed5c729#3d8747f9a60695c367c70bb64efba8f403721fad_0_291

Definition at line 139 of file peertube.py.

139def fetch_traits(engine_traits: EngineTraits):
140 """Fetch languages from peertube's search-index source code.
141
142 See videoLanguages_ in commit `8ed5c729 - Refactor and redesign client`_
143
144 .. _8ed5c729 - Refactor and redesign client:
145 https://framagit.org/framasoft/peertube/search-index/-/commit/8ed5c729
146 .. _videoLanguages:
147 https://framagit.org/framasoft/peertube/search-index/-/commit/8ed5c729#3d8747f9a60695c367c70bb64efba8f403721fad_0_291
148 """
149
150 resp = get(
151 'https://framagit.org/framasoft/peertube/search-index/-/raw/master/client/src/components/Filters.vue',
152 # the response from search-index repository is very slow
153 timeout=60,
154 )
155
156 if not resp.ok: # type: ignore
157 print("ERROR: response from peertube is not OK.")
158 return
159
160 js_lang = re.search(r"videoLanguages \‍(\‍)[^\n]+(.*?)\]", resp.text, re.DOTALL) # type: ignore
161 if not js_lang:
162 print("ERROR: can't determine languages from peertube")
163 return
164
165 for lang in re.finditer(r"\{ id: '([a-z]+)', label:", js_lang.group(1)):
166 eng_tag = lang.group(1)
167 if eng_tag == 'oc':
168 # Occitanis not known by babel, its closest relative is Catalan
169 # but 'ca' is already in the list of engine_traits.languages -->
170 # 'oc' will be ignored.
171 continue
172 try:
173 sxng_tag = language_tag(babel.Locale.parse(eng_tag))
174 except babel.UnknownLocaleError:
175 print("ERROR: %s is unknown by babel" % eng_tag)
176 continue
177
178 conflict = engine_traits.languages.get(sxng_tag)
179 if conflict:
180 if conflict != eng_tag:
181 print("CONFLICT: babel %s --> %s, %s" % (sxng_tag, conflict, eng_tag))
182 continue
183 engine_traits.languages[sxng_tag] = eng_tag
184
185 engine_traits.languages['zh_Hans'] = 'zh'
186 engine_traits.languages['zh_Hant'] = 'zh'

◆ minute_to_hm()

searx.engines.peertube.minute_to_hm ( minute)

Definition at line 53 of file peertube.py.

53def minute_to_hm(minute):
54 if isinstance(minute, int):
55 return "%d:%02d" % (divmod(minute, 60))
56 return None
57
58

Referenced by searx.engines.peertube.video_response().

+ Here is the caller graph for this function:

◆ request()

searx.engines.peertube.request ( query,
params )
Assemble request for the Peertube API

Definition at line 59 of file peertube.py.

59def request(query, params):
60 """Assemble request for the Peertube API"""
61
62 if not query:
63 return False
64
65 # eng_region = traits.get_region(params['searxng_locale'], 'en_US')
66 eng_lang = traits.get_language(params['searxng_locale'], None)
67
68 params['url'] = (
69 base_url.rstrip("/")
70 + "/api/v1/search/videos?"
71 + urlencode(
72 {
73 'search': query,
74 'searchTarget': 'search-index', # Vidiversum
75 'resultType': 'videos',
76 'start': (params['pageno'] - 1) * 10,
77 'count': 10,
78 # -createdAt: sort by date ascending / createdAt: date descending
79 'sort': '-match', # sort by *match descending*
80 'nsfw': safesearch_table[params['safesearch']],
81 }
82 )
83 )
84
85 if eng_lang is not None:
86 params['url'] += '&languageOneOf[]=' + eng_lang
87 params['url'] += '&boostLanguages[]=' + eng_lang
88
89 if params['time_range'] in time_range_table:
90 time = datetime.now().date() + time_range_table[params['time_range']]
91 params['url'] += '&startDate=' + time.isoformat()
92
93 return params
94
95

◆ response()

searx.engines.peertube.response ( resp)

Definition at line 96 of file peertube.py.

96def response(resp):
97 return video_response(resp)
98
99

References searx.engines.peertube.video_response().

+ Here is the call graph for this function:

◆ video_response()

searx.engines.peertube.video_response ( resp)
Parse video response from SepiaSearch and Peertube instances.

Definition at line 100 of file peertube.py.

100def video_response(resp):
101 """Parse video response from SepiaSearch and Peertube instances."""
102 results = []
103
104 json_data = resp.json()
105
106 if 'data' not in json_data:
107 return []
108
109 for result in json_data['data']:
110 metadata = [
111 x
112 for x in [
113 result.get('channel', {}).get('displayName'),
114 result.get('channel', {}).get('name') + '@' + result.get('channel', {}).get('host'),
115 ', '.join(result.get('tags', [])),
116 ]
117 if x
118 ]
119
120 results.append(
121 {
122 'url': result['url'],
123 'title': result['name'],
124 'content': html_to_text(result.get('description') or ''),
125 'author': result.get('account', {}).get('displayName'),
126 'length': minute_to_hm(result.get('duration')),
127 'views': humanize_number(result['views']),
128 'template': 'videos.html',
129 'publishedDate': parse(result['publishedAt']),
130 'iframe_src': result.get('embedUrl'),
131 'thumbnail': result.get('thumbnailUrl') or result.get('previewUrl'),
132 'metadata': ' | '.join(metadata),
133 }
134 )
135
136 return results
137
138

References searx.engines.peertube.minute_to_hm().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ about

dict searx.engines.peertube.about
Initial value:
1= {
2 # pylint: disable=line-too-long
3 "website": 'https://joinpeertube.org',
4 "wikidata_id": 'Q50938515',
5 "official_api_documentation": 'https://docs.joinpeertube.org/api-rest-reference.html#tag/Search/operation/searchVideos',
6 "use_official_api": True,
7 "require_api_key": False,
8 "results": 'JSON',
9}

Definition at line 22 of file peertube.py.

◆ base_url

str searx.engines.peertube.base_url = "https://peer.tube"

Definition at line 35 of file peertube.py.

◆ categories

list searx.engines.peertube.categories = ["videos"]

Definition at line 33 of file peertube.py.

◆ paging

bool searx.engines.peertube.paging = True

Definition at line 34 of file peertube.py.

◆ safesearch

bool searx.engines.peertube.safesearch = True

Definition at line 49 of file peertube.py.

◆ safesearch_table

dict searx.engines.peertube.safesearch_table = {0: 'both', 1: 'false', 2: 'false'}

Definition at line 50 of file peertube.py.

◆ time_range_support

bool searx.engines.peertube.time_range_support = True

Definition at line 41 of file peertube.py.

◆ time_range_table

dict searx.engines.peertube.time_range_table
Initial value:
1= {
2 'day': relativedelta(),
3 'week': relativedelta(weeks=-1),
4 'month': relativedelta(months=-1),
5 'year': relativedelta(years=-1),
6}

Definition at line 42 of file peertube.py.