YouTube video processing utils

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2025-04-09 18:46:10 -07:00
parent ff04efed12
commit 1609e59086
2 changed files with 65 additions and 39 deletions

View file

@ -39,6 +39,7 @@ class DocumentType(str, Enum):
FILE = "FILE"
SLACK_CONNECTOR = "SLACK_CONNECTOR"
NOTION_CONNECTOR = "NOTION_CONNECTOR"
YOUTUBE_VIDEO = "YOUTUBE_VIDEO"
class SearchSourceConnectorType(str, Enum):
SERPER_API = "SERPER_API"

View file

@ -46,6 +46,13 @@ async def create_documents(
url,
request.search_space_id
)
elif request.document_type == DocumentType.YOUTUBE_VIDEO:
for url in request.content:
fastapi_background_tasks.add_task(
process_youtube_video_with_new_session,
url,
request.search_space_id
)
else:
raise HTTPException(
status_code=400,
@ -117,44 +124,6 @@ async def create_documents(
detail=f"Failed to upload files: {str(e)}"
)
async def process_extension_document_with_new_session(
individual_document,
search_space_id: int
):
"""Create a new session and process extension document."""
from app.db import async_session_maker
async with async_session_maker() as session:
try:
await add_extension_received_document(session, individual_document, search_space_id)
except Exception as e:
import logging
logging.error(f"Error processing extension document: {str(e)}")
async def process_crawled_url_with_new_session(
url: str,
search_space_id: int
):
"""Create a new session and process crawled URL."""
from app.db import async_session_maker
async with async_session_maker() as session:
try:
await add_crawled_url_document(session, url, search_space_id)
except Exception as e:
import logging
logging.error(f"Error processing crawled URL: {str(e)}")
async def process_file_in_background_with_new_session(
file_path: str,
filename: str,
search_space_id: int
):
"""Create a new session and process file."""
from app.db import async_session_maker
async with async_session_maker() as session:
await process_file_in_background(file_path, filename, search_space_id, session)
async def process_file_in_background(
file_path: str,
@ -348,4 +317,60 @@ async def delete_document(
raise HTTPException(
status_code=500,
detail=f"Failed to delete document: {str(e)}"
)
)
async def process_extension_document_with_new_session(
individual_document,
search_space_id: int
):
"""Create a new session and process extension document."""
from app.db import async_session_maker
async with async_session_maker() as session:
try:
await add_extension_received_document(session, individual_document, search_space_id)
except Exception as e:
import logging
logging.error(f"Error processing extension document: {str(e)}")
async def process_crawled_url_with_new_session(
url: str,
search_space_id: int
):
"""Create a new session and process crawled URL."""
from app.db import async_session_maker
async with async_session_maker() as session:
try:
await add_crawled_url_document(session, url, search_space_id)
except Exception as e:
import logging
logging.error(f"Error processing crawled URL: {str(e)}")
async def process_file_in_background_with_new_session(
file_path: str,
filename: str,
search_space_id: int
):
"""Create a new session and process file."""
from app.db import async_session_maker
async with async_session_maker() as session:
await process_file_in_background(file_path, filename, search_space_id, session)
async def process_youtube_video_with_new_session(
url: str,
search_space_id: int
):
"""Create a new session and process YouTube video."""
from app.db import async_session_maker
async with async_session_maker() as session:
try:
# TODO: Implement YouTube video processing
print("Processing YouTube video with new session")
except Exception as e:
import logging
logging.error(f"Error processing YouTube video: {str(e)}")