Skip to content

Commit

Permalink
feat: add alass engine (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: John Corser <[email protected]>
  • Loading branch information
johnpc and John Corser authored Feb 2, 2025
1 parent 89938dd commit e61a2bf
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# .dockerignore
node_modules
vendor
.git
test-srts
*.log
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ RUN npm install --ignore-scripts

# Copy the rest of your application
COPY . .
RUN mv bin/* /root/.local/bin/

# Build TypeScript
RUN npm run build
Expand Down
Binary file added bin/alass
Binary file not shown.
33 changes: 33 additions & 0 deletions src/generateAlassSubtitles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { basename, dirname, join } from 'path';
import { execPromise, ProcessingResult } from './helpers';
import { existsSync } from 'fs';

export async function generateAlassSubtitles(srtPath: string, videoPath: string): Promise<ProcessingResult> {
const directory = dirname(srtPath);
const srtBaseName = basename(srtPath, '.srt');
const outputPath = join(directory, `${srtBaseName}.alass.srt`);

const exists = existsSync(outputPath);
if (exists) {
return {
success: true,
message: `Skipping ${outputPath} - already processed`,
};
}

try {
const command = `alass "${videoPath}" "${srtPath}" "${outputPath}"`;
console.log(`${new Date().toLocaleString()} Processing: ${command}`);
await execPromise(command);
return {
success: true,
message: `Successfully processed: ${outputPath}`,
};
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
return {
success: false,
message: `Error processing ${outputPath}: ${errorMessage}`,
};
}
}
7 changes: 6 additions & 1 deletion src/processSrtFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { basename } from 'path';
import { findMatchingVideoFile } from './findMatchingVideoFile';
import { generateAutosubsyncSubtitles } from './generateAutosubsyncSubtitles';
import { generateFfsubsyncSubtitles } from './generateFfsubsyncSubtitles';
import { generateAlassSubtitles } from './generateAlassSubtitles';

export const processSrtFile = async (srtFile: string) => {
const videoFile = findMatchingVideoFile(srtFile);
const includeEngines = process.env.INCLUDE_ENGINES?.split(',') || ['ffsubsync', 'autosubsync'];
const includeEngines = process.env.INCLUDE_ENGINES?.split(',') || ['ffsubsync', 'autosubsync', 'alass'];

if (videoFile) {
if (includeEngines.includes('ffsubsync')) {
Expand All @@ -16,6 +17,10 @@ export const processSrtFile = async (srtFile: string) => {
const autosubsyncResult = await generateAutosubsyncSubtitles(srtFile, videoFile);
console.log(`${new Date().toLocaleString()} autosubsync result: ${autosubsyncResult.message}`);
}
if (includeEngines.includes('alass')) {
const alassResult = await generateAlassSubtitles(srtFile, videoFile);
console.log(`${new Date().toLocaleString()} alass result: ${alassResult.message}`);
}
} else {
console.log(`${new Date().toLocaleString()} No matching video file found for: ${basename(srtFile)}`);
}
Expand Down

0 comments on commit e61a2bf

Please sign in to comment.