[feat] add bilibili support to get get_embeded_stream_url
This commit is contained in:
		
							parent
							
								
									523d2a7683
								
							
						
					
					
						commit
						73d50f5748
					
				| @ -6,7 +6,7 @@ from urllib.parse import urlencode | |||||||
| from datetime import datetime | from datetime import datetime | ||||||
| 
 | 
 | ||||||
| from searx.exceptions import SearxEngineAPIException | from searx.exceptions import SearxEngineAPIException | ||||||
| from searx.utils import html_to_text | from searx.utils import html_to_text, get_embeded_stream_url | ||||||
| 
 | 
 | ||||||
| about = { | about = { | ||||||
|     "website": "https://tv.360kan.com/", |     "website": "https://tv.360kan.com/", | ||||||
| @ -58,6 +58,7 @@ def response(resp): | |||||||
|                 'template': 'videos.html', |                 'template': 'videos.html', | ||||||
|                 'publishedDate': published_date, |                 'publishedDate': published_date, | ||||||
|                 'thumbnail': entry["cover_img"], |                 'thumbnail': entry["cover_img"], | ||||||
|  |                 "iframe_src": get_embeded_stream_url(entry["play_url"]), | ||||||
|             } |             } | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -633,7 +633,7 @@ def _get_fasttext_model() -> "fasttext.FastText._FastText":  # type: ignore | |||||||
| def get_embeded_stream_url(url): | def get_embeded_stream_url(url): | ||||||
|     """ |     """ | ||||||
|     Converts a standard video URL into its embed format. Supported services include Youtube, |     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) |     parsed_url = urlparse(url) | ||||||
|     iframe_src = None |     iframe_src = None | ||||||
| @ -673,6 +673,22 @@ def get_embeded_stream_url(url): | |||||||
|             video_id = path_parts[2] |             video_id = path_parts[2] | ||||||
|             iframe_src = 'https://www.dailymotion.com/embed/video/' + video_id |             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 |     return iframe_src | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Austin-Olacsi
						Austin-Olacsi