mirror of
https://github.com/searxng/searxng.git
synced 2025-08-02 18:12:21 +02:00
[refactor] duration strings: move parsing logic to utils.py
This commit is contained in:
parent
c28d35c7fc
commit
4dfc47584d
5 changed files with 42 additions and 42 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
import re
|
||||
from urllib.parse import urlencode
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from dateutil.parser import parse
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
|
@ -50,12 +50,6 @@ safesearch = True
|
|||
safesearch_table = {0: 'both', 1: 'false', 2: 'false'}
|
||||
|
||||
|
||||
def minute_to_hm(minute):
|
||||
if isinstance(minute, int):
|
||||
return "%d:%02d" % (divmod(minute, 60))
|
||||
return None
|
||||
|
||||
|
||||
def request(query, params):
|
||||
"""Assemble request for the Peertube API"""
|
||||
|
||||
|
@ -117,13 +111,17 @@ def video_response(resp):
|
|||
if x
|
||||
]
|
||||
|
||||
duration = result.get('duration')
|
||||
if duration:
|
||||
duration = timedelta(seconds=duration)
|
||||
|
||||
results.append(
|
||||
{
|
||||
'url': result['url'],
|
||||
'title': result['name'],
|
||||
'content': html_to_text(result.get('description') or ''),
|
||||
'author': result.get('account', {}).get('displayName'),
|
||||
'length': minute_to_hm(result.get('duration')),
|
||||
'length': duration,
|
||||
'views': humanize_number(result['views']),
|
||||
'template': 'videos.html',
|
||||
'publishedDate': parse(result['publishedAt']),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue