.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 114 of file tubearchivist.py.

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

Referenced by video_response().

Here is the caller graph for this function:

◆ init()

searx.engines.tubearchivist.init ( _)

Definition at line 118 of file tubearchivist.py.

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

◆ request()

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

Definition at line 125 of file tubearchivist.py.

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

◆ response()

EngineResults searx.engines.tubearchivist.response ( resp)

Definition at line 136 of file tubearchivist.py.

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

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 142 of file tubearchivist.py.

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

◆ base_url

str searx.engines.tubearchivist.base_url = ""

Definition at line 96 of file tubearchivist.py.

◆ categories

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

Definition at line 93 of file tubearchivist.py.

◆ paging

bool searx.engines.tubearchivist.paging = True

Definition at line 94 of file tubearchivist.py.

◆ ta_link_to_mp4

bool searx.engines.tubearchivist.ta_link_to_mp4 = False

Definition at line 108 of file tubearchivist.py.

◆ ta_token

str searx.engines.tubearchivist.ta_token = ""

Definition at line 100 of file tubearchivist.py.