diff options
| author | Austin-Olacsi <138650713+Austin-Olacsi@users.noreply.github.com> | 2025-03-05 18:15:32 -0700 |
|---|---|---|
| committer | Bnyro <bnyro@tutanota.com> | 2025-03-08 10:47:30 +0100 |
| commit | 73d50f57481cfe2951c3231b2f5dfd70c0e6b49f (patch) | |
| tree | 7e7b5564a543640698848f3a25416a8edcc01601 /searx/utils.py | |
| parent | 523d2a76837cc8e94f29afc490c312e6af8398a7 (diff) | |
[feat] add bilibili support to get get_embeded_stream_url
Diffstat (limited to 'searx/utils.py')
| -rw-r--r-- | searx/utils.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/searx/utils.py b/searx/utils.py index f342c2803..8fdcb0fda 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -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 |