Skip to content

Commit ba99e3e

Browse files
committed
fix: add python scripts to packaged builds
1 parent 18d6534 commit ba99e3e

File tree

2 files changed

+69
-8
lines changed

2 files changed

+69
-8
lines changed

electron-builder.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ files:
1010
- '!{.env,.env.*,.npmrc,pnpm-lock.yaml}'
1111
- '!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}'
1212
- 'out/**/*'
13-
- 'audio_extractor.py'
14-
- 'requirements.txt'
15-
- 'setup.py'
13+
extraResources:
14+
- from: 'audio_extractor.py'
15+
to: 'audio_extractor.py'
16+
- from: 'requirements.txt'
17+
to: 'requirements.txt'
18+
- from: 'setup.py'
19+
to: 'setup.py'
1620
asarUnpack:
1721
- resources/**
1822
win:

src/main/utils/transcript.utils.ts

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,76 @@
11
import { join } from 'path'
22
import { existsSync } from 'fs'
33
import { spawn } from 'child_process'
4+
import { app } from 'electron'
45
import { PythonScriptResult } from '../types'
56
import { generateFallbackTranscript } from './file.utils'
67

8+
/**
9+
* Find available Python command
10+
*/
11+
function findPythonCommand(): Promise<string | null> {
12+
const commands = ['python3', 'python', 'py']
13+
14+
return new Promise((resolve) => {
15+
let index = 0
16+
17+
function tryNext() {
18+
if (index >= commands.length) {
19+
resolve(null)
20+
return
21+
}
22+
23+
const cmd = commands[index++]
24+
const testProcess = spawn(cmd, ['--version'], { stdio: 'pipe' })
25+
26+
testProcess.on('close', (code) => {
27+
if (code === 0) {
28+
console.log(`Found Python command: ${cmd}`)
29+
resolve(cmd)
30+
} else {
31+
tryNext()
32+
}
33+
})
34+
35+
testProcess.on('error', () => {
36+
tryNext()
37+
})
38+
}
39+
40+
tryNext()
41+
})
42+
}
43+
744
/**
845
* Extract transcript from video using Python script
946
*/
1047
export async function extractTranscriptFromVideo(videoPath: string): Promise<string> {
11-
return new Promise((resolve) => {
48+
return new Promise(async (resolve) => {
1249
try {
1350
console.log('Running Python script to extract audio and transcribe...')
1451
console.log('Video path:', videoPath)
1552

53+
// Get the app path for both development and packaged environments
54+
const appPath = app.isPackaged ? process.resourcesPath : process.cwd()
55+
1656
const possiblePaths = [
17-
join(__dirname, '../../../audio_extractor.py'),
57+
// For packaged app: resources/audio_extractor.py
58+
join(appPath, 'audio_extractor.py'),
59+
// For development: current working directory
1860
join(process.cwd(), 'audio_extractor.py'),
61+
// Relative to main process directory
62+
join(__dirname, '../../../audio_extractor.py'),
63+
// Try current directory as fallback
1964
'audio_extractor.py'
2065
]
2166

67+
console.log('App is packaged:', app.isPackaged)
68+
console.log('App path:', appPath)
2269
console.log('Possible script paths:', possiblePaths)
2370

2471
let scriptPath: string | null = null
2572
for (const path of possiblePaths) {
73+
console.log('Checking path:', path, 'exists:', existsSync(path))
2674
if (existsSync(path)) {
2775
scriptPath = path
2876
console.log('Found script at:', scriptPath)
@@ -31,13 +79,22 @@ export async function extractTranscriptFromVideo(videoPath: string): Promise<str
3179
}
3280

3381
if (!scriptPath) {
34-
console.log('No script found, using fallback')
82+
console.log('No script found at any of the expected paths, using fallback')
3583
resolve(generateFallbackTranscript(videoPath))
3684
return
3785
}
3886

39-
console.log('Spawning Python process with:', scriptPath, videoPath)
40-
const pythonProcess = spawn('python', [scriptPath, videoPath])
87+
// Find available Python command
88+
const pythonCommand = await findPythonCommand()
89+
90+
if (!pythonCommand) {
91+
console.log('No Python command found, using fallback')
92+
resolve(generateFallbackTranscript(videoPath))
93+
return
94+
}
95+
96+
console.log('Spawning Python process with:', pythonCommand, scriptPath, videoPath)
97+
const pythonProcess = spawn(pythonCommand, [scriptPath, videoPath])
4198

4299
let stdout = ''
43100
let stderr = ''

0 commit comments

Comments
 (0)