mirror of
https://github.com/searxng/searxng.git
synced 2024-11-14 06:01:28 +00:00
[feat] videos template: support for view count
This commit is contained in:
parent
3f22dbb68a
commit
304ddd8114
6 changed files with 23 additions and 2 deletions
|
@ -7,6 +7,8 @@ import random
|
|||
from urllib.parse import quote_plus, urlparse
|
||||
from dateutil import parser
|
||||
|
||||
from searx.utils import humanize_number
|
||||
|
||||
# about
|
||||
about = {
|
||||
"website": 'https://api.invidious.io/',
|
||||
|
@ -91,7 +93,8 @@ def response(resp):
|
|||
"url": url,
|
||||
"title": result.get("title", ""),
|
||||
"content": result.get("description", ""),
|
||||
'length': length,
|
||||
"length": length,
|
||||
"views": humanize_number(result['viewCount']),
|
||||
"template": "videos.html",
|
||||
"author": result.get("author"),
|
||||
"publishedDate": publishedDate,
|
||||
|
|
|
@ -14,7 +14,7 @@ import babel
|
|||
|
||||
from searx.network import get # see https://github.com/searxng/searxng/issues/762
|
||||
from searx.locales import language_tag
|
||||
from searx.utils import html_to_text
|
||||
from searx.utils import html_to_text, humanize_number
|
||||
from searx.enginelib.traits import EngineTraits
|
||||
|
||||
traits: EngineTraits
|
||||
|
@ -124,6 +124,7 @@ def video_response(resp):
|
|||
'content': html_to_text(result.get('description') or ''),
|
||||
'author': result.get('account', {}).get('displayName'),
|
||||
'length': minute_to_hm(result.get('duration')),
|
||||
'views': humanize_number(result['views']),
|
||||
'template': 'videos.html',
|
||||
'publishedDate': parse(result['publishedAt']),
|
||||
'iframe_src': result.get('embedUrl'),
|
||||
|
|
|
@ -53,6 +53,8 @@ from urllib.parse import urlencode
|
|||
import datetime
|
||||
from dateutil import parser
|
||||
|
||||
from searx.utils import humanize_number
|
||||
|
||||
# about
|
||||
about = {
|
||||
"website": 'https://github.com/TeamPiped/Piped/',
|
||||
|
@ -138,6 +140,7 @@ def response(resp):
|
|||
"title": result.get("title", ""),
|
||||
"publishedDate": parser.parse(time.ctime(uploaded / 1000)) if uploaded != -1 else None,
|
||||
"iframe_src": _frontend_url() + '/embed' + result.get("url", ""),
|
||||
"views": humanize_number(result["views"]),
|
||||
}
|
||||
length = result.get("duration")
|
||||
if length:
|
||||
|
|
|
@ -271,6 +271,7 @@ article[data-vim-selected].category-social {
|
|||
|
||||
.published_date,
|
||||
.result_length,
|
||||
.result_views,
|
||||
.result_author,
|
||||
.result_shipping,
|
||||
.result_source_country {
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
{%- macro result_sub_header(result) -%}
|
||||
{%- if result.publishedDate %}<time class="published_date" datetime="{{ result.pubdate }}" >{{ result.publishedDate }}</time>{% endif -%}
|
||||
{%- if result.length %}<div class="result_length">{{ _('Length') }}: {{ result.length }}</div>{% endif -%}
|
||||
{%- if result.views %}<div class="result_views">{{ _('Views') }}: {{ result.views }}</div>{% endif -%}
|
||||
{%- if result.author %}<div class="result_author">{{ _('Author') }}: {{ result.author }}</div>{% endif -%}
|
||||
{%- if result.metadata %}<div class="highlight">{{ result.metadata|safe }}</div>{% endif -%}
|
||||
{%- endmacro -%}
|
||||
|
|
|
@ -334,6 +334,18 @@ def humanize_bytes(size, precision=2):
|
|||
return "%.*f %s" % (precision, size, s[p])
|
||||
|
||||
|
||||
def humanize_number(size, precision=0):
|
||||
"""Determine the *human readable* value of a decimal number."""
|
||||
s = ['', 'K', 'M', 'B', 'T']
|
||||
|
||||
x = len(s)
|
||||
p = 0
|
||||
while size > 1000 and p < x:
|
||||
p += 1
|
||||
size = size / 1000.0
|
||||
return "%.*f%s" % (precision, size, s[p])
|
||||
|
||||
|
||||
def convert_str_to_int(number_str: str) -> int:
|
||||
"""Convert number_str to int or 0 if number_str is not a number."""
|
||||
if number_str.isdigit():
|
||||
|
|
Loading…
Reference in a new issue