mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-07-07 15:41:22 +08:00
first commit
This commit is contained in:
0
backend/app/validators/__init__.py
Normal file
0
backend/app/validators/__init__.py
Normal file
24
backend/app/validators/video_url_validator.py
Normal file
24
backend/app/validators/video_url_validator.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from pydantic import AnyUrl, validator, BaseModel
|
||||
import re
|
||||
|
||||
SUPPORTED_PLATFORMS = {
|
||||
"bilibili": r"(https?://)?(www\.)?bilibili\.com/video/[a-zA-Z0-9]+",
|
||||
"youtube": r"(https?://)?(www\.)?(youtube\.com/watch\?v=|youtu\.be/)[\w\-]+",
|
||||
"douyin": r"(https?://)?(www\.)?douyin\.com/video/\d+",
|
||||
}
|
||||
|
||||
|
||||
|
||||
def is_supported_video_url(url: str) -> bool:
|
||||
return any(re.match(pattern, url) for pattern in SUPPORTED_PLATFORMS.values())
|
||||
|
||||
|
||||
class VideoRequest(BaseModel):
|
||||
url: AnyUrl
|
||||
platform: str
|
||||
|
||||
@validator("url")
|
||||
def validate_video_url(cls, v):
|
||||
if not is_supported_video_url(str(v)):
|
||||
raise ValueError("暂不支持该视频平台或链接格式无效")
|
||||
return v
|
||||
Reference in New Issue
Block a user