mirror of
https://github.com/searxng/searxng.git
synced 2026-07-26 18:01:33 +00:00
Compare commits
3 Commits
4884747508
...
a88b4d7036
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a88b4d7036 | ||
|
|
73d50f5748 | ||
|
|
523d2a7683 |
@@ -49,6 +49,5 @@ die-on-term
|
||||
# uwsgi serves the static files
|
||||
static-map = /static=/usr/local/searxng/searx/static
|
||||
# expires set to one day
|
||||
static-expires = /* 86400
|
||||
static-gzip-all = True
|
||||
offload-threads = %k
|
||||
|
||||
@@ -6,7 +6,7 @@ from urllib.parse import urlencode
|
||||
from datetime import datetime
|
||||
|
||||
from searx.exceptions import SearxEngineAPIException
|
||||
from searx.utils import html_to_text
|
||||
from searx.utils import html_to_text, get_embeded_stream_url
|
||||
|
||||
about = {
|
||||
"website": "https://tv.360kan.com/",
|
||||
@@ -58,6 +58,7 @@ def response(resp):
|
||||
'template': 'videos.html',
|
||||
'publishedDate': published_date,
|
||||
'thumbnail': entry["cover_img"],
|
||||
"iframe_src": get_embeded_stream_url(entry["play_url"]),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ Implementations
|
||||
|
||||
"""
|
||||
|
||||
from urllib.parse import urlencode
|
||||
from urllib.parse import urlencode, urlparse
|
||||
from searx import locales
|
||||
from searx.network import get
|
||||
from searx.utils import gen_useragent, html_to_text
|
||||
@@ -155,13 +155,34 @@ def _strip_leading_strings(text):
|
||||
return text.strip()
|
||||
|
||||
|
||||
def _fix_title(title, url):
|
||||
"""
|
||||
Titles from Presearch shows domain + title without spacing, and HTML
|
||||
This function removes these 2 issues.
|
||||
Transforming "translate.google.co.in<em>Google</em> Translate" into "Google Translate"
|
||||
"""
|
||||
parsed_url = urlparse(url)
|
||||
domain = parsed_url.netloc
|
||||
title = html_to_text(title)
|
||||
# Fixes issue where domain would show up in the title
|
||||
# translate.google.co.inGoogle Translate -> Google Translate
|
||||
if (
|
||||
title.startswith(domain)
|
||||
and len(title) > len(domain)
|
||||
and not title.startswith(domain + "/")
|
||||
and not title.startswith(domain + " ")
|
||||
):
|
||||
title = title.removeprefix(domain)
|
||||
return title
|
||||
|
||||
|
||||
def parse_search_query(json_results):
|
||||
results = []
|
||||
|
||||
for item in json_results.get('specialSections', {}).get('topStoriesCompact', {}).get('data', []):
|
||||
result = {
|
||||
'url': item['link'],
|
||||
'title': html_to_text(item['title']),
|
||||
'title': _fix_title(item['title'], item['link']),
|
||||
'thumbnail': item['image'],
|
||||
'content': '',
|
||||
'metadata': item.get('source'),
|
||||
@@ -171,7 +192,7 @@ def parse_search_query(json_results):
|
||||
for item in json_results.get('standardResults', []):
|
||||
result = {
|
||||
'url': item['link'],
|
||||
'title': html_to_text(item['title']),
|
||||
'title': _fix_title(item['title'], item['link']),
|
||||
'content': html_to_text(item['description']),
|
||||
}
|
||||
results.append(result)
|
||||
|
||||
@@ -633,7 +633,7 @@ def _get_fasttext_model() -> "fasttext.FastText._FastText": # type: ignore
|
||||
def get_embeded_stream_url(url):
|
||||
"""
|
||||
Converts a standard video URL into its embed format. Supported services include Youtube,
|
||||
Facebook, Instagram, TikTok, and Dailymotion.
|
||||
Facebook, Instagram, TikTok, Dailymotion, and Bilibili.
|
||||
"""
|
||||
parsed_url = urlparse(url)
|
||||
iframe_src = None
|
||||
@@ -673,6 +673,22 @@ def get_embeded_stream_url(url):
|
||||
video_id = path_parts[2]
|
||||
iframe_src = 'https://www.dailymotion.com/embed/video/' + video_id
|
||||
|
||||
# Bilibili
|
||||
elif parsed_url.netloc in ['www.bilibili.com', 'bilibili.com'] and parsed_url.path.startswith('/video/'):
|
||||
path_parts = parsed_url.path.split('/')
|
||||
|
||||
video_id = path_parts[2]
|
||||
param_key = None
|
||||
if video_id.startswith('av'):
|
||||
video_id = video_id[2:]
|
||||
param_key = 'aid'
|
||||
elif video_id.startswith('BV'):
|
||||
param_key = 'bvid'
|
||||
|
||||
iframe_src = (
|
||||
f'https://player.bilibili.com/player.html?{param_key}={video_id}&high_quality=1&autoplay=false&danmaku=0'
|
||||
)
|
||||
|
||||
return iframe_src
|
||||
|
||||
|
||||
|
||||
@@ -81,7 +81,5 @@ buffer-size = 8192
|
||||
# static_use_hash: true
|
||||
#
|
||||
static-map = /static=${SEARXNG_STATIC}
|
||||
# expires set to one day
|
||||
static-expires = /* 86400
|
||||
static-gzip-all = True
|
||||
offload-threads = %k
|
||||
|
||||
@@ -78,7 +78,5 @@ buffer-size = 8192
|
||||
# static_use_hash: true
|
||||
#
|
||||
static-map = /static=${SEARXNG_STATIC}
|
||||
# expires set to one day
|
||||
static-expires = /* 86400
|
||||
static-gzip-all = True
|
||||
offload-threads = %k
|
||||
|
||||
@@ -84,7 +84,5 @@ buffer-size = 8192
|
||||
# static_use_hash: true
|
||||
#
|
||||
static-map = /static=${SEARXNG_STATIC}
|
||||
# expires set to one day
|
||||
static-expires = /* 86400
|
||||
static-gzip-all = True
|
||||
offload-threads = %k
|
||||
|
||||
@@ -81,7 +81,5 @@ buffer-size = 8192
|
||||
# static_use_hash: true
|
||||
#
|
||||
static-map = /static=${SEARXNG_STATIC}
|
||||
# expires set to one day
|
||||
static-expires = /* 86400
|
||||
static-gzip-all = True
|
||||
offload-threads = %k
|
||||
|
||||
Reference in New Issue
Block a user