fix: detect platform on video create, remove hardcoded twitter default
This commit is contained in:
@@ -12,7 +12,7 @@ class Video(Base):
|
||||
task_id = Column(String(64), unique=True, index=True, nullable=False)
|
||||
url = Column(String(512), nullable=False, index=True)
|
||||
title = Column(String(512), default="")
|
||||
platform = Column(String(32), default="twitter")
|
||||
platform = Column(String(32), default="")
|
||||
thumbnail = Column(String(1024), default="")
|
||||
quality = Column(String(32), default="")
|
||||
format_id = Column(String(64), default="")
|
||||
|
||||
@@ -12,7 +12,7 @@ from app.schemas import DownloadRequest, DownloadResponse, TaskStatus
|
||||
from app.database import get_db, async_session
|
||||
from app.models import Video, DownloadLog
|
||||
from app.auth import get_current_user, optional_auth
|
||||
from app.services.downloader import download_video, get_video_path
|
||||
from app.services.downloader import download_video, get_video_path, detect_platform
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter(prefix="/api", tags=["download"])
|
||||
@@ -154,7 +154,8 @@ async def start_download(req: DownloadRequest, background_tasks: BackgroundTasks
|
||||
return DownloadResponse(task_id=existing.task_id, status="done")
|
||||
|
||||
task_id = str(uuid.uuid4())[:8]
|
||||
video = Video(task_id=task_id, url=req.url, quality=req.quality, format_id=req.format_id, status="pending")
|
||||
video = Video(task_id=task_id, url=req.url, quality=req.quality, format_id=req.format_id,
|
||||
status="pending", platform=detect_platform(req.url))
|
||||
db.add(video)
|
||||
await db.commit()
|
||||
background_tasks.add_task(_do_download, task_id, req.url, req.format_id)
|
||||
|
||||
@@ -55,6 +55,17 @@ def _is_pornhub_url(url: str) -> bool:
|
||||
return bool(PORNHUB_URL_RE.match(url))
|
||||
|
||||
|
||||
def detect_platform(url: str) -> str:
|
||||
"""Detect platform from URL."""
|
||||
if _is_twitter_url(url):
|
||||
return "twitter"
|
||||
if _is_youtube_url(url):
|
||||
return "youtube"
|
||||
if _is_pornhub_url(url):
|
||||
return "pornhub"
|
||||
return "unknown"
|
||||
|
||||
|
||||
def _is_twitter_url(url: str) -> bool:
|
||||
return bool(TWITTER_URL_RE.match(url))
|
||||
|
||||
@@ -556,5 +567,5 @@ def download_video(url: str, format_id: str = "best", progress_callback=None) ->
|
||||
"filename": os.path.basename(filename),
|
||||
"file_path": filename,
|
||||
"file_size": file_size,
|
||||
"platform": "twitter",
|
||||
"platform": detect_platform(url),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user