mirror of
https://github.com/MODSetter/SurfSense.git
synced 2025-09-02 18:49:09 +00:00
YouTube video processing utils
This commit is contained in:
parent
ff04efed12
commit
1609e59086
2 changed files with 65 additions and 39 deletions
|
@ -39,6 +39,7 @@ class DocumentType(str, Enum):
|
||||||
FILE = "FILE"
|
FILE = "FILE"
|
||||||
SLACK_CONNECTOR = "SLACK_CONNECTOR"
|
SLACK_CONNECTOR = "SLACK_CONNECTOR"
|
||||||
NOTION_CONNECTOR = "NOTION_CONNECTOR"
|
NOTION_CONNECTOR = "NOTION_CONNECTOR"
|
||||||
|
YOUTUBE_VIDEO = "YOUTUBE_VIDEO"
|
||||||
|
|
||||||
class SearchSourceConnectorType(str, Enum):
|
class SearchSourceConnectorType(str, Enum):
|
||||||
SERPER_API = "SERPER_API"
|
SERPER_API = "SERPER_API"
|
||||||
|
|
|
@ -46,6 +46,13 @@ async def create_documents(
|
||||||
url,
|
url,
|
||||||
request.search_space_id
|
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:
|
else:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=400,
|
status_code=400,
|
||||||
|
@ -117,44 +124,6 @@ async def create_documents(
|
||||||
detail=f"Failed to upload files: {str(e)}"
|
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(
|
async def process_file_in_background(
|
||||||
file_path: str,
|
file_path: str,
|
||||||
|
@ -349,3 +318,59 @@ async def delete_document(
|
||||||
status_code=500,
|
status_code=500,
|
||||||
detail=f"Failed to delete document: {str(e)}"
|
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)}")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue