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

Functions

 absolute_url (relative_url)
 init (_)
 request (query, params)
EngineResults response (resp)
None video_response (resp, EngineResults results)

Variables

dict about
list categories = ["videos"]
bool paging = True
str base_url = ""
str ta_token = ""
bool ta_link_to_mp4 = False

Detailed Description

`Tube Archivist`_ - *Your self hosted YouTube media server.*

.. _Tube Archivist: https://www.tubearchivist.com

This engine connects with a self-hosted instance of `Tube Archivist`_ to allow
searching for your hosted videos.

`Tube Archivist`_ (TA) requires authentication for all image loads via cookie
authentication.  What this means is that by default, SearXNG will have no way to
pull images from TA (as there is no way to pass cookies in a URL string only).

In the meantime while work is done on the TA side, this can be worked around by
bypassing auth for images in TA by altering the default TA nginx file.

This is located in the main tubearchivist docker container at::

  /etc/nginx/sites-available/default

It is **strongly** recommended first setting up the intial connection and
verying searching works first with broken images, and then attempting this
change.  This will limit any debugging to only images, rather than
tokens/networking.

Steps to enable **unauthenticated** metadata access for channels and videos:

#. Perform any backups of TA before editing core configurations.

#. Copy the contents of the file ``/etc/nginx/sites-available/default`` in the
   TA docker container

#. Edit ``location /cache/videos`` and ``location /cache/channels``.  Comment
   out the line ``auth_request /api/ping/;`` to ``# auth_request /api/ping/;``.

#. Save the file to wherever you normally store your docker configuration.

#. Mount this new configuration over the default configuration.  With ``docker
   run``, this would be::

     -v ./your-new-config.yml:/etc/nginx/sites-available/default

   With ``docker compose``, this would be::

     - "./your-new-config.yml:/etc/nginx/sites-available/default:ro"

#. Start the TA container.

After these steps, double check that TA works as normal (nothing should be
different on the TA side).  Searching again should now show images.


Configuration
=============

The engine has the following required settings:

- :py:obj:`base_url`
- :py:obj:`ta_token`

Optional settings:

- :py:obj:`ta_link_to_mp4`

.. code:: yaml

  - name: tubearchivist
    engine: tubearchivist
    shortcut: tuba
    base_url:
    ta_token:
    ta_link_to_mp4: true

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

Function Documentation

◆ absolute_url()

searx.engines.tubearchivist.absolute_url ( relative_url)

Definition at line 115 of file tubearchivist.py.

115def absolute_url(relative_url):
116 return f'{base_url.rstrip("/")}{relative_url}'
117
118

Referenced by video_response().

Here is the caller graph for this function:

◆ init()

searx.engines.tubearchivist.init ( _)

Definition at line 119 of file tubearchivist.py.

119def init(_):
120 if not base_url:
121 raise ValueError('tubearchivist engine: base_url is unset')
122 if not ta_token:
123 raise ValueError('tubearchivist engine: ta_token is unset')
124
125

◆ request()

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

Definition at line 126 of file tubearchivist.py.

126def request(query, params):
127 if not query:
128 return False
129
130 args = {'query': query}
131 params['url'] = f"{base_url.rstrip('/')}/api/search?{urlencode(args)}"
132 params['headers']['Authorization'] = f'Token {ta_token}'
133
134 return params
135
136

◆ response()

EngineResults searx.engines.tubearchivist.response ( resp)

Definition at line 137 of file tubearchivist.py.

137def response(resp) -> EngineResults:
138 results = EngineResults()
139 video_response(resp, results)
140 return results
141
142

References video_response().

Here is the call graph for this function:

◆ video_response()

None searx.engines.tubearchivist.video_response ( resp,
EngineResults results )
Parse video response from Tubearchivist instances.

Definition at line 143 of file tubearchivist.py.

143def video_response(resp, results: EngineResults) -> None:
144 """Parse video response from Tubearchivist instances."""
145
146 json_data = resp.json()
147
148 if 'results' not in json_data:
149 return
150
151 for channel_result in json_data['results']['channel_results']:
152 channel_url = absolute_url(f'/channel/{channel_result["channel_id"]}')
153
154 res = results.types.MainResult(
155 url=channel_url,
156 title=channel_result['channel_name'],
157 content=html_to_text(channel_result['channel_description']),
158 author=channel_result['channel_name'],
159 views=humanize_number(channel_result['channel_subs']),
160 thumbnail=f'{absolute_url(channel_result["channel_thumb_url"])}?auth={ta_token}',
161 )
162
163 results.add(result=res)
164
165 for video_result in json_data['results']['video_results']:
166 metadata = list(filter(None, [video_result['channel']['channel_name'], *video_result.get('tags', [])]))[:5]
167 if ta_link_to_mp4:
168 url = f'{base_url.rstrip("/")}{video_result["media_url"]}'
169 else:
170 url = f'{base_url.rstrip("/")}/?videoId={video_result["youtube_id"]}'
171
172 # a type for the video.html template is not yet implemented
173 # --> using LegacyResult
174
175 kwargs = {
176 'template': 'videos.html',
177 'url': url,
178 'title': video_result['title'],
179 'content': html_to_text(video_result['description']),
180 'author': video_result['channel']['channel_name'],
181 'length': video_result['player']['duration_str'],
182 'views': humanize_number(video_result['stats']['view_count']),
183 'publishedDate': parse(video_result['published']),
184 'thumbnail': f'{absolute_url(video_result["vid_thumb_url"])}?auth={ta_token}',
185 'metadata': ' | '.join(metadata),
186 }
187 results.add(results.types.LegacyResult(**kwargs))

References absolute_url().

Referenced by response().

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

Variable Documentation

◆ about

dict searx.engines.tubearchivist.about
Initial value:
1= {
2 # pylint: disable=line-too-long
3 "website": 'https://www.tubearchivist.com',
4 "official_api_documentation": 'https://docs.tubearchivist.com/api/introduction/',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 84 of file tubearchivist.py.

◆ base_url

str searx.engines.tubearchivist.base_url = ""

Definition at line 97 of file tubearchivist.py.

◆ categories

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

Definition at line 94 of file tubearchivist.py.

◆ paging

bool searx.engines.tubearchivist.paging = True

Definition at line 95 of file tubearchivist.py.

◆ ta_link_to_mp4

bool searx.engines.tubearchivist.ta_link_to_mp4 = False

Definition at line 109 of file tubearchivist.py.

◆ ta_token

str searx.engines.tubearchivist.ta_token = ""

Definition at line 101 of file tubearchivist.py.