summd 0.1.11 → 0.1.13

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.
Files changed (2) hide show
  1. package/dist/url-to-md.js +21 -23
  2. package/package.json +1 -1
package/dist/url-to-md.js CHANGED
@@ -88,21 +88,6 @@ const SUB_FALLBACKS = [
88
88
  // 2. Most-spoken languages by global user count (covers remaining cases)
89
89
  ['--write-subs', '--write-auto-subs', '--sub-langs', 'zh-Hans,zh,ja,ko,fr,de,es,pt,hi,ar,ru'],
90
90
  ];
91
- // Detect the video's primary language via yt-dlp --dump-json.
92
- // Returns a language code like 'zh-Hans', 'en', 'ja', etc., or null on failure.
93
- async function getVideoLanguage(url, cookieArgs) {
94
- try {
95
- const { stdout } = await execFileAsync('yt-dlp', [
96
- '--dump-json', '--no-playlist', '--quiet',
97
- ...cookieArgs, url,
98
- ], { timeout: 15_000 });
99
- const meta = JSON.parse(stdout);
100
- return meta.language ?? null;
101
- }
102
- catch {
103
- return null;
104
- }
105
- }
106
91
  async function ytDlpTranscript(url, videoId) {
107
92
  const dir = tmpdir();
108
93
  const outTemplate = join(dir, videoId);
@@ -152,16 +137,18 @@ async function ytDlpTranscript(url, videoId) {
152
137
  return null;
153
138
  }
154
139
  };
155
- // Phase 1: find a working browser cookie source.
156
- // Try each browser with a no-op probe (--dump-json is light and confirms auth works).
140
+ // Phase 1: find a working browser cookie source AND detect native language in one call.
141
+ // --dump-json is lightweight (no download) and returns metadata including `language`.
157
142
  let cookieArgs = [];
143
+ let nativeLang = null;
158
144
  for (const browser of BROWSERS) {
159
145
  try {
160
- await execFileAsync('yt-dlp', [
146
+ const { stdout } = await execFileAsync('yt-dlp', [
161
147
  '--dump-json', '--no-playlist', '--quiet',
162
148
  '--cookies-from-browser', browser, url,
163
149
  ], { timeout: 15_000 });
164
150
  cookieArgs = ['--cookies-from-browser', browser];
151
+ nativeLang = JSON.parse(stdout).language ?? null;
165
152
  break;
166
153
  }
167
154
  catch (e) {
@@ -175,10 +162,21 @@ async function ytDlpTranscript(url, videoId) {
175
162
  break;
176
163
  }
177
164
  }
178
- // cookieArgs is empty if no browser found fall back to cookie-less requests
179
- // Phase 2: detect the video's primary language from metadata.
180
- const nativeLang = await getVideoLanguage(url, cookieArgs);
181
- // Phase 3: try native language subtitles first (most accurate).
165
+ // If no browser worked, try cookie-less metadata fetch for language detection.
166
+ if (!cookieArgs.length) {
167
+ try {
168
+ const { stdout } = await execFileAsync('yt-dlp', [
169
+ '--dump-json', '--no-playlist', '--quiet', url,
170
+ ], { timeout: 15_000 });
171
+ nativeLang = JSON.parse(stdout).language ?? null;
172
+ }
173
+ catch (e) {
174
+ const err = e;
175
+ if (err.code === 'ENOENT')
176
+ return { transcript: null, reason: 'not-installed' };
177
+ }
178
+ }
179
+ // Phase 2: try native language subtitles first (most accurate).
182
180
  if (nativeLang) {
183
181
  const outcome = await run(['--write-subs', '--write-auto-subs', '--sub-langs', nativeLang], cookieArgs);
184
182
  if (outcome === 'not-installed')
@@ -187,7 +185,7 @@ async function ytDlpTranscript(url, videoId) {
187
185
  if (t)
188
186
  return { transcript: t };
189
187
  }
190
- // Phase 4: fallback strategies with the confirmed cookie source.
188
+ // Phase 3: fallback strategies with the confirmed cookie source.
191
189
  for (const subArgs of SUB_FALLBACKS) {
192
190
  const outcome = await run(subArgs, cookieArgs);
193
191
  if (outcome === 'not-installed')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "summd",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "CLI for sum.md — Sum to anything.",
5
5
  "license": "MIT",
6
6
  "bin": {