( videoId: Video.VideoId, userId: string, aiGenerationEnabled = false, )
| 25 | }; |
| 26 | |
| 27 | export async function transcribeVideo( |
| 28 | videoId: Video.VideoId, |
| 29 | userId: string, |
| 30 | aiGenerationEnabled = false, |
| 31 | ): Promise<TranscribeResult> { |
| 32 | if (!serverEnv().DEEPGRAM_API_KEY) { |
| 33 | return { |
| 34 | success: false, |
| 35 | message: "Missing necessary environment variables", |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | if (!userId || !videoId) { |
| 40 | return { |
| 41 | success: false, |
| 42 | message: "userId or videoId not supplied", |
| 43 | }; |
| 44 | } |
| 45 | |
| 46 | const query = await db() |
| 47 | .select({ |
| 48 | video: videos, |
| 49 | settings: videos.settings, |
| 50 | orgSettings: organizations.settings, |
| 51 | }) |
| 52 | .from(videos) |
| 53 | .leftJoin(organizations, eq(videos.orgId, organizations.id)) |
| 54 | .where(eq(videos.id, videoId)); |
| 55 | |
| 56 | if (query.length === 0) { |
| 57 | return { success: false, message: "Video does not exist" }; |
| 58 | } |
| 59 | |
| 60 | const result = query[0]; |
| 61 | if (!result || !result.video) { |
| 62 | return { success: false, message: "Video information is missing" }; |
| 63 | } |
| 64 | |
| 65 | const { video } = result; |
| 66 | |
| 67 | if (!video) { |
| 68 | return { success: false, message: "Video information is missing" }; |
| 69 | } |
| 70 | |
| 71 | if ( |
| 72 | video.settings?.disableTranscript ?? |
| 73 | result.orgSettings?.disableTranscript |
| 74 | ) { |
| 75 | console.log( |
| 76 | `[transcribeVideo] Transcription disabled for video ${videoId}`, |
| 77 | ); |
| 78 | try { |
| 79 | await db() |
| 80 | .update(videos) |
| 81 | .set({ transcriptionStatus: "SKIPPED" }) |
| 82 | .where(eq(videos.id, videoId)); |
| 83 | } catch (err) { |
| 84 | console.error(`[transcribeVideo] Failed to mark as skipped:`, err); |
no test coverage detected