add volcengine OSS support
This commit is contained in:
@@ -14,6 +14,7 @@ from .audio_metrics import (
|
||||
from .config import Settings
|
||||
from .generate_boundaries import ALGORITHM_VERSION, make_entry
|
||||
from .models import SentenceBoundary, SentenceBoundaryDocument
|
||||
from .oss import VolcanoOSSUploader
|
||||
from .repository import VideoRepository
|
||||
from .transcription import Transcript, Transcriber, split_sentences_at_punctuation
|
||||
|
||||
@@ -27,10 +28,12 @@ class VideoProcessor:
|
||||
settings: Settings,
|
||||
repository: VideoRepository,
|
||||
transcriber: Transcriber,
|
||||
oss_uploader: Optional[VolcanoOSSUploader] = None,
|
||||
):
|
||||
self.settings = settings
|
||||
self.repository = repository
|
||||
self.transcriber = transcriber
|
||||
self.oss_uploader = oss_uploader
|
||||
|
||||
def process(self, video_hash: str) -> None:
|
||||
video = self.repository.get_video(video_hash)
|
||||
@@ -57,7 +60,7 @@ class VideoProcessor:
|
||||
)
|
||||
if not document.sentences:
|
||||
raise RuntimeError("MOSS returned no timestamped speech segments.")
|
||||
self.repository.save_processing_result(document, transcript.text)
|
||||
self._finish_processing(document, transcript.text)
|
||||
else:
|
||||
entry, _ = make_entry(media_path, video_hash=video_hash)
|
||||
document = SentenceBoundaryDocument(
|
||||
@@ -66,7 +69,7 @@ class VideoProcessor:
|
||||
algorithm_version=ALGORITHM_VERSION,
|
||||
sentences=entry["sentences"],
|
||||
)
|
||||
self.repository.save_processing_result(document, None)
|
||||
self._finish_processing(document, None)
|
||||
except Exception as exc:
|
||||
self.repository.mark_failed(video_hash, str(exc))
|
||||
raise
|
||||
@@ -74,6 +77,28 @@ class VideoProcessor:
|
||||
if work_path is not None:
|
||||
work_path.unlink(missing_ok=True)
|
||||
|
||||
def _finish_processing(
|
||||
self,
|
||||
document: SentenceBoundaryDocument,
|
||||
transcription: Optional[str],
|
||||
) -> None:
|
||||
if self.oss_uploader is None or not self.oss_uploader.enabled:
|
||||
self.repository.save_processing_result(document, transcription, ready=True)
|
||||
return
|
||||
|
||||
# Keep the course invisible while the mandatory OSS upload is running.
|
||||
self.repository.save_processing_result(document, transcription, ready=False)
|
||||
video = self.repository.get_video(document.video_hash)
|
||||
if video is None:
|
||||
raise ValueError(f"Unknown video: {document.video_hash}")
|
||||
remote_url = self.oss_uploader.upload(
|
||||
video_hash=document.video_hash,
|
||||
stored_filename=video["stored_filename"],
|
||||
local_path=self.settings.videos_dir / video["stored_filename"],
|
||||
content_type=video.get("content_type"),
|
||||
)
|
||||
self.repository.mark_oss_uploaded(document.video_hash, remote_url)
|
||||
|
||||
|
||||
def extract_audio(media_path: Path, output_path: Path) -> None:
|
||||
ffmpeg = shutil.which("ffmpeg")
|
||||
|
||||
Reference in New Issue
Block a user