summd 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -2
- package/dist/url-to-md.js +16 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
|
-
import { extname } from 'path';
|
|
3
|
+
import { extname, dirname, join } from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
4
5
|
import { createInterface } from 'readline';
|
|
5
6
|
import { program } from 'commander';
|
|
7
|
+
const _pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '../package.json'), 'utf8'));
|
|
6
8
|
import { saveKey } from './config.js';
|
|
7
9
|
import * as api from './api.js';
|
|
8
10
|
import { urlToMarkdown } from './url-to-md.js';
|
|
@@ -47,7 +49,7 @@ function formatDate(iso) {
|
|
|
47
49
|
program
|
|
48
50
|
.name('summd')
|
|
49
51
|
.description('Sum to anything.')
|
|
50
|
-
.version(
|
|
52
|
+
.version(_pkg.version)
|
|
51
53
|
.option('--key <token>', 'API key for this request')
|
|
52
54
|
.option('--base <url>', 'Override API base URL');
|
|
53
55
|
// ── summd key ─────────────────────────────────────────────────────────────────
|
package/dist/url-to-md.js
CHANGED
|
@@ -132,23 +132,34 @@ async function ytDlpTranscript(url, videoId) {
|
|
|
132
132
|
return { transcript: null, reason: 'no-transcript' };
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
//
|
|
135
|
+
// Pick the best subtitle file and clean up all temp files.
|
|
136
|
+
// Priority: original-language ASR (-orig suffix) > English > first available.
|
|
137
|
+
// yt-dlp names the original-language auto-generated track with an "-orig" infix,
|
|
138
|
+
// e.g. zh-Hans-orig.json3 — this is the most reliable source for non-English videos.
|
|
136
139
|
try {
|
|
137
140
|
const files = readdirSync(dir).filter(f => f.startsWith(videoId) && f.endsWith('.json3'));
|
|
141
|
+
const pick = files.find(f => f.includes('-orig.')) ?? // original language ASR
|
|
142
|
+
files.find(f => /\.en(-\w+)?\.json3$/.test(f)) ?? // English (manual or ASR)
|
|
143
|
+
files[0]; // first available
|
|
144
|
+
let transcript = null;
|
|
138
145
|
for (const file of files) {
|
|
139
146
|
const filePath = join(dir, file);
|
|
140
147
|
try {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
148
|
+
if (file === pick) {
|
|
149
|
+
const text = parseTimedText(JSON.parse(readFileSync(filePath, 'utf8')));
|
|
150
|
+
if (text)
|
|
151
|
+
transcript = text;
|
|
152
|
+
}
|
|
144
153
|
}
|
|
145
154
|
finally {
|
|
146
155
|
try {
|
|
147
156
|
unlinkSync(filePath);
|
|
148
157
|
}
|
|
149
|
-
catch { }
|
|
158
|
+
catch { } // clean up every file, not just the picked one
|
|
150
159
|
}
|
|
151
160
|
}
|
|
161
|
+
if (transcript)
|
|
162
|
+
return { transcript };
|
|
152
163
|
}
|
|
153
164
|
catch { }
|
|
154
165
|
return { transcript: null, reason: 'no-transcript' };
|