Skip to content

Commit e61672a

Browse files
authored
Merge pull request #55 from johnpc/feat/sync-languages
feat: add SYNC_LANGUAGES env var to filter by language
2 parents 03ec4fa + 704adb2 commit e61672a

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ docker run -d \
101101
| --------------------------- | ----------------------------- | -------------------------------------------------------------------------------- |
102102
| `SCAN_PATHS` | `/scan_dir` | Comma-separated directories to scan for SRT files (must be mounted as volumes) |
103103
| `EXCLUDE_PATHS` | _(none)_ | Comma-separated directories to exclude from scanning |
104+
| `SYNC_LANGUAGES` | _(none)_ | Comma-separated language codes to sync (e.g., `en,de`). Only syncs subtitles with matching language tags in the filename (e.g., `movie.en.srt`). If not set, all subtitles are synced. |
104105
| `CRON_SCHEDULE` | `0 0 * * *` | Cron expression for sync schedule (daily at midnight), or `disabled` to turn off |
105106
| `MAX_CONCURRENT_SYNC_TASKS` | `1` | Number of subtitle files to process in parallel (higher = faster but more CPU) |
106107
| `INCLUDE_ENGINES` | `ffsubsync,autosubsync,alass` | Which sync engines to use (comma-separated) |

src/findAllSrtFiles.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,32 @@ function isAlreadySynced(srtPath: string, engines: string[]): boolean {
1313
});
1414
}
1515

16+
function matchesLanguageFilter(fileName: string, languages: string[]): boolean {
17+
if (languages.length === 0) return true;
18+
19+
// Extract language tag from filename like "movie.en.srt" or "movie.eng.srt"
20+
const parts = basename(fileName, '.srt').split('.');
21+
if (parts.length < 2) return false;
22+
23+
const langTag = parts[parts.length - 1].toLowerCase();
24+
return languages.some((lang) => lang.toLowerCase() === langTag);
25+
}
26+
1627
export interface ScanResult {
1728
files: string[];
1829
skippedCount: number;
1930
}
2031

2132
export async function findAllSrtFiles(config: ScanConfig): Promise<ScanResult> {
2233
const engines = process.env.INCLUDE_ENGINES?.split(',') || ['ffsubsync', 'autosubsync', 'alass'];
34+
const languages = process.env.SYNC_LANGUAGES?.split(',').map((l) => l.trim()).filter(Boolean) || [];
2335
const files: string[] = [];
2436
let skippedCount = 0;
2537

38+
if (languages.length > 0) {
39+
console.log(`${new Date().toLocaleString()} Language filter active: ${languages.join(', ')}`);
40+
}
41+
2642
async function scan(directory: string): Promise<void> {
2743
// Check if this directory should be excluded
2844
if (config.excludePaths.some((excludePath) => directory.startsWith(excludePath))) {
@@ -41,7 +57,8 @@ export async function findAllSrtFiles(config: ScanConfig): Promise<ScanResult> {
4157
extname(entry.name).toLowerCase() === '.srt' &&
4258
!entry.name.includes('.ffsubsync.') &&
4359
!entry.name.includes('.alass.') &&
44-
!entry.name.includes('.autosubsync.')
60+
!entry.name.includes('.autosubsync.') &&
61+
matchesLanguageFilter(entry.name, languages)
4562
) {
4663
if (isAlreadySynced(fullPath, engines)) {
4764
skippedCount++;

0 commit comments

Comments
 (0)