@steipete/summarize-core 0.7.1 → 0.8.1

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 (175) hide show
  1. package/dist/esm/content/cache/types.js +2 -0
  2. package/dist/esm/content/cache/types.js.map +1 -0
  3. package/dist/esm/content/index.js +1 -0
  4. package/dist/esm/content/index.js.map +1 -1
  5. package/dist/esm/content/link-preview/client.js +3 -0
  6. package/dist/esm/content/link-preview/client.js.map +1 -1
  7. package/dist/esm/content/link-preview/content/fetcher.js +1 -1
  8. package/dist/esm/content/link-preview/content/fetcher.js.map +1 -1
  9. package/dist/esm/content/link-preview/content/html.js +1 -1
  10. package/dist/esm/content/link-preview/content/html.js.map +1 -1
  11. package/dist/esm/content/link-preview/content/index.js +22 -3
  12. package/dist/esm/content/link-preview/content/index.js.map +1 -1
  13. package/dist/esm/content/link-preview/deps.js.map +1 -1
  14. package/dist/esm/content/transcript/index.js +1 -0
  15. package/dist/esm/content/transcript/index.js.map +1 -1
  16. package/dist/esm/content/transcript/providers/generic.js +84 -4
  17. package/dist/esm/content/transcript/providers/generic.js.map +1 -1
  18. package/dist/esm/content/transcript/providers/podcast.js +1 -0
  19. package/dist/esm/content/transcript/providers/podcast.js.map +1 -1
  20. package/dist/esm/content/transcript/providers/youtube/captions.js +35 -14
  21. package/dist/esm/content/transcript/providers/youtube/captions.js.map +1 -1
  22. package/dist/esm/content/transcript/providers/youtube/yt-dlp.js +84 -12
  23. package/dist/esm/content/transcript/providers/youtube/yt-dlp.js.map +1 -1
  24. package/dist/esm/content/transcript/providers/youtube.js +38 -2
  25. package/dist/esm/content/transcript/providers/youtube.js.map +1 -1
  26. package/dist/esm/content/transcript/utils.js +25 -69
  27. package/dist/esm/content/transcript/utils.js.map +1 -1
  28. package/dist/esm/content/url.js +76 -0
  29. package/dist/esm/content/url.js.map +1 -0
  30. package/dist/esm/prompts/cli.js +25 -5
  31. package/dist/esm/prompts/cli.js.map +1 -1
  32. package/dist/esm/prompts/file.js +51 -12
  33. package/dist/esm/prompts/file.js.map +1 -1
  34. package/dist/esm/prompts/format.js +26 -0
  35. package/dist/esm/prompts/format.js.map +1 -0
  36. package/dist/esm/prompts/link-summary.js +51 -22
  37. package/dist/esm/prompts/link-summary.js.map +1 -1
  38. package/dist/types/content/cache/types.d.ts +25 -0
  39. package/dist/types/content/index.d.ts +3 -1
  40. package/dist/types/content/link-preview/client.d.ts +6 -1
  41. package/dist/types/content/link-preview/content/types.d.ts +1 -1
  42. package/dist/types/content/link-preview/deps.d.ts +11 -20
  43. package/dist/types/content/transcript/cache.d.ts +1 -1
  44. package/dist/types/content/transcript/providers/generic.d.ts +1 -1
  45. package/dist/types/content/transcript/providers/youtube/captions.d.ts +3 -1
  46. package/dist/types/content/transcript/providers/youtube/yt-dlp.d.ts +3 -1
  47. package/dist/types/content/transcript/types.d.ts +2 -1
  48. package/dist/types/content/transcript/utils.d.ts +1 -3
  49. package/dist/types/content/url.d.ts +8 -0
  50. package/dist/types/prompts/cli.d.ts +4 -1
  51. package/dist/types/prompts/file.d.ts +9 -2
  52. package/dist/types/prompts/format.d.ts +14 -0
  53. package/dist/types/prompts/link-summary.d.ts +4 -1
  54. package/package.json +10 -10
  55. package/dist/cjs/content/index.js +0 -14
  56. package/dist/cjs/content/index.js.map +0 -1
  57. package/dist/cjs/content/link-preview/client.js +0 -31
  58. package/dist/cjs/content/link-preview/client.js.map +0 -1
  59. package/dist/cjs/content/link-preview/content/article.js +0 -164
  60. package/dist/cjs/content/link-preview/content/article.js.map +0 -1
  61. package/dist/cjs/content/link-preview/content/cleaner.js +0 -63
  62. package/dist/cjs/content/link-preview/content/cleaner.js.map +0 -1
  63. package/dist/cjs/content/link-preview/content/constants.js +0 -10
  64. package/dist/cjs/content/link-preview/content/constants.js.map +0 -1
  65. package/dist/cjs/content/link-preview/content/fetcher.js +0 -128
  66. package/dist/cjs/content/link-preview/content/fetcher.js.map +0 -1
  67. package/dist/cjs/content/link-preview/content/firecrawl.js +0 -90
  68. package/dist/cjs/content/link-preview/content/firecrawl.js.map +0 -1
  69. package/dist/cjs/content/link-preview/content/html.js +0 -165
  70. package/dist/cjs/content/link-preview/content/html.js.map +0 -1
  71. package/dist/cjs/content/link-preview/content/index.js +0 -348
  72. package/dist/cjs/content/link-preview/content/index.js.map +0 -1
  73. package/dist/cjs/content/link-preview/content/jsonld.js +0 -80
  74. package/dist/cjs/content/link-preview/content/jsonld.js.map +0 -1
  75. package/dist/cjs/content/link-preview/content/parsers.js +0 -81
  76. package/dist/cjs/content/link-preview/content/parsers.js.map +0 -1
  77. package/dist/cjs/content/link-preview/content/podcast-utils.js +0 -85
  78. package/dist/cjs/content/link-preview/content/podcast-utils.js.map +0 -1
  79. package/dist/cjs/content/link-preview/content/readability.js +0 -90
  80. package/dist/cjs/content/link-preview/content/readability.js.map +0 -1
  81. package/dist/cjs/content/link-preview/content/twitter-utils.js +0 -74
  82. package/dist/cjs/content/link-preview/content/twitter-utils.js.map +0 -1
  83. package/dist/cjs/content/link-preview/content/types.js +0 -7
  84. package/dist/cjs/content/link-preview/content/types.js.map +0 -1
  85. package/dist/cjs/content/link-preview/content/utils.js +0 -177
  86. package/dist/cjs/content/link-preview/content/utils.js.map +0 -1
  87. package/dist/cjs/content/link-preview/content/video.js +0 -99
  88. package/dist/cjs/content/link-preview/content/video.js.map +0 -1
  89. package/dist/cjs/content/link-preview/content/youtube.js +0 -85
  90. package/dist/cjs/content/link-preview/content/youtube.js.map +0 -1
  91. package/dist/cjs/content/link-preview/deps.js +0 -23
  92. package/dist/cjs/content/link-preview/deps.js.map +0 -1
  93. package/dist/cjs/content/link-preview/fetch-with-timeout.js +0 -38
  94. package/dist/cjs/content/link-preview/fetch-with-timeout.js.map +0 -1
  95. package/dist/cjs/content/link-preview/types.js +0 -5
  96. package/dist/cjs/content/link-preview/types.js.map +0 -1
  97. package/dist/cjs/content/transcript/cache.js +0 -85
  98. package/dist/cjs/content/transcript/cache.js.map +0 -1
  99. package/dist/cjs/content/transcript/index.js +0 -134
  100. package/dist/cjs/content/transcript/index.js.map +0 -1
  101. package/dist/cjs/content/transcript/normalize.js +0 -49
  102. package/dist/cjs/content/transcript/normalize.js.map +0 -1
  103. package/dist/cjs/content/transcript/providers/generic.js +0 -16
  104. package/dist/cjs/content/transcript/providers/generic.js.map +0 -1
  105. package/dist/cjs/content/transcript/providers/podcast/apple-flow.js +0 -226
  106. package/dist/cjs/content/transcript/providers/podcast/apple-flow.js.map +0 -1
  107. package/dist/cjs/content/transcript/providers/podcast/apple.js +0 -43
  108. package/dist/cjs/content/transcript/providers/podcast/apple.js.map +0 -1
  109. package/dist/cjs/content/transcript/providers/podcast/constants.js +0 -11
  110. package/dist/cjs/content/transcript/providers/podcast/constants.js.map +0 -1
  111. package/dist/cjs/content/transcript/providers/podcast/flow-context.js +0 -3
  112. package/dist/cjs/content/transcript/providers/podcast/flow-context.js.map +0 -1
  113. package/dist/cjs/content/transcript/providers/podcast/itunes.js +0 -139
  114. package/dist/cjs/content/transcript/providers/podcast/itunes.js.map +0 -1
  115. package/dist/cjs/content/transcript/providers/podcast/json.js +0 -43
  116. package/dist/cjs/content/transcript/providers/podcast/json.js.map +0 -1
  117. package/dist/cjs/content/transcript/providers/podcast/media.js +0 -355
  118. package/dist/cjs/content/transcript/providers/podcast/media.js.map +0 -1
  119. package/dist/cjs/content/transcript/providers/podcast/results.js +0 -32
  120. package/dist/cjs/content/transcript/providers/podcast/results.js.map +0 -1
  121. package/dist/cjs/content/transcript/providers/podcast/rss.js +0 -262
  122. package/dist/cjs/content/transcript/providers/podcast/rss.js.map +0 -1
  123. package/dist/cjs/content/transcript/providers/podcast/spotify-flow.js +0 -221
  124. package/dist/cjs/content/transcript/providers/podcast/spotify-flow.js.map +0 -1
  125. package/dist/cjs/content/transcript/providers/podcast/spotify.js +0 -119
  126. package/dist/cjs/content/transcript/providers/podcast/spotify.js.map +0 -1
  127. package/dist/cjs/content/transcript/providers/podcast.js +0 -260
  128. package/dist/cjs/content/transcript/providers/podcast.js.map +0 -1
  129. package/dist/cjs/content/transcript/providers/youtube/api.js +0 -264
  130. package/dist/cjs/content/transcript/providers/youtube/api.js.map +0 -1
  131. package/dist/cjs/content/transcript/providers/youtube/apify.js +0 -59
  132. package/dist/cjs/content/transcript/providers/youtube/apify.js.map +0 -1
  133. package/dist/cjs/content/transcript/providers/youtube/captions.js +0 -413
  134. package/dist/cjs/content/transcript/providers/youtube/captions.js.map +0 -1
  135. package/dist/cjs/content/transcript/providers/youtube/yt-dlp.js +0 -170
  136. package/dist/cjs/content/transcript/providers/youtube/yt-dlp.js.map +0 -1
  137. package/dist/cjs/content/transcript/providers/youtube.js +0 -178
  138. package/dist/cjs/content/transcript/providers/youtube.js.map +0 -1
  139. package/dist/cjs/content/transcript/types.js +0 -3
  140. package/dist/cjs/content/transcript/types.js.map +0 -1
  141. package/dist/cjs/content/transcript/utils.js +0 -303
  142. package/dist/cjs/content/transcript/utils.js.map +0 -1
  143. package/dist/cjs/index.js +0 -22
  144. package/dist/cjs/index.js.map +0 -1
  145. package/dist/cjs/language.js +0 -132
  146. package/dist/cjs/language.js.map +0 -1
  147. package/dist/cjs/package.json +0 -3
  148. package/dist/cjs/prompts/cli.js +0 -23
  149. package/dist/cjs/prompts/cli.js.map +0 -1
  150. package/dist/cjs/prompts/file.js +0 -52
  151. package/dist/cjs/prompts/file.js.map +0 -1
  152. package/dist/cjs/prompts/index.js +0 -14
  153. package/dist/cjs/prompts/index.js.map +0 -1
  154. package/dist/cjs/prompts/link-summary.js +0 -122
  155. package/dist/cjs/prompts/link-summary.js.map +0 -1
  156. package/dist/cjs/shared/contracts.js +0 -5
  157. package/dist/cjs/shared/contracts.js.map +0 -1
  158. package/dist/cjs/transcription/whisper/constants.js +0 -11
  159. package/dist/cjs/transcription/whisper/constants.js.map +0 -1
  160. package/dist/cjs/transcription/whisper/core.js +0 -307
  161. package/dist/cjs/transcription/whisper/core.js.map +0 -1
  162. package/dist/cjs/transcription/whisper/fal.js +0 -44
  163. package/dist/cjs/transcription/whisper/fal.js.map +0 -1
  164. package/dist/cjs/transcription/whisper/ffmpeg.js +0 -187
  165. package/dist/cjs/transcription/whisper/ffmpeg.js.map +0 -1
  166. package/dist/cjs/transcription/whisper/openai.js +0 -51
  167. package/dist/cjs/transcription/whisper/openai.js.map +0 -1
  168. package/dist/cjs/transcription/whisper/types.js +0 -3
  169. package/dist/cjs/transcription/whisper/types.js.map +0 -1
  170. package/dist/cjs/transcription/whisper/utils.js +0 -70
  171. package/dist/cjs/transcription/whisper/utils.js.map +0 -1
  172. package/dist/cjs/transcription/whisper/whisper-cpp.js +0 -232
  173. package/dist/cjs/transcription/whisper/whisper-cpp.js.map +0 -1
  174. package/dist/cjs/transcription/whisper.js +0 -15
  175. package/dist/cjs/transcription/whisper.js.map +0 -1
@@ -1,355 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transcribeMediaUrl = transcribeMediaUrl;
4
- exports.probeRemoteMedia = probeRemoteMedia;
5
- exports.downloadCappedBytes = downloadCappedBytes;
6
- exports.downloadToFile = downloadToFile;
7
- exports.normalizeHeaderType = normalizeHeaderType;
8
- exports.parseContentLength = parseContentLength;
9
- exports.filenameFromUrl = filenameFromUrl;
10
- exports.formatBytes = formatBytes;
11
- const node_crypto_1 = require("node:crypto");
12
- const node_fs_1 = require("node:fs");
13
- const node_os_1 = require("node:os");
14
- const node_path_1 = require("node:path");
15
- const whisper_js_1 = require("../../../../transcription/whisper.js");
16
- const constants_js_1 = require("./constants.js");
17
- async function transcribeMediaUrl({ fetchImpl, url, filenameHint, durationSecondsHint, openaiApiKey, falApiKey, notes, progress, }) {
18
- const canChunk = await (0, whisper_js_1.isFfmpegAvailable)();
19
- const providerHint = (await (0, whisper_js_1.isWhisperCppReady)())
20
- ? 'cpp'
21
- : openaiApiKey && falApiKey
22
- ? 'openai->fal'
23
- : openaiApiKey
24
- ? 'openai'
25
- : falApiKey
26
- ? 'fal'
27
- : 'unknown';
28
- const head = await probeRemoteMedia(fetchImpl, url);
29
- if (head.contentLength !== null && head.contentLength > constants_js_1.MAX_REMOTE_MEDIA_BYTES) {
30
- throw new Error(`Remote media too large (${formatBytes(head.contentLength)}). Limit is ${formatBytes(constants_js_1.MAX_REMOTE_MEDIA_BYTES)}.`);
31
- }
32
- const mediaType = head.mediaType ?? 'application/octet-stream';
33
- const filename = head.filename ?? filenameHint;
34
- const totalBytes = head.contentLength;
35
- progress?.onProgress?.({
36
- kind: 'transcript-media-download-start',
37
- url: progress.url,
38
- service: progress.service,
39
- mediaUrl: url,
40
- totalBytes,
41
- });
42
- const modelId = providerHint === 'cpp'
43
- ? ((await (0, whisper_js_1.resolveWhisperCppModelNameForDisplay)()) ?? 'whisper.cpp')
44
- : openaiApiKey && falApiKey
45
- ? 'whisper-1->fal-ai/wizper'
46
- : openaiApiKey
47
- ? 'whisper-1'
48
- : falApiKey
49
- ? 'fal-ai/wizper'
50
- : null;
51
- if (!canChunk) {
52
- const bytes = await downloadCappedBytes(fetchImpl, url, whisper_js_1.MAX_OPENAI_UPLOAD_BYTES, {
53
- totalBytes,
54
- onProgress: (downloadedBytes) => progress?.onProgress?.({
55
- kind: 'transcript-media-download-progress',
56
- url: progress.url,
57
- service: progress.service,
58
- downloadedBytes,
59
- totalBytes,
60
- }),
61
- });
62
- progress?.onProgress?.({
63
- kind: 'transcript-media-download-done',
64
- url: progress.url,
65
- service: progress.service,
66
- downloadedBytes: bytes.byteLength,
67
- totalBytes,
68
- });
69
- progress?.onProgress?.({
70
- kind: 'transcript-whisper-start',
71
- url: progress.url,
72
- service: progress.service,
73
- providerHint,
74
- modelId,
75
- totalDurationSeconds: durationSecondsHint,
76
- parts: null,
77
- });
78
- notes.push(`Transcribed first ${formatBytes(bytes.byteLength)} only (ffmpeg not available)`);
79
- const transcript = await (0, whisper_js_1.transcribeMediaWithWhisper)({
80
- bytes,
81
- mediaType,
82
- filename,
83
- openaiApiKey,
84
- falApiKey,
85
- totalDurationSeconds: durationSecondsHint,
86
- onProgress: (event) => {
87
- progress?.onProgress?.({
88
- kind: 'transcript-whisper-progress',
89
- url: progress.url,
90
- service: progress.service,
91
- processedDurationSeconds: event.processedDurationSeconds,
92
- totalDurationSeconds: event.totalDurationSeconds,
93
- partIndex: event.partIndex,
94
- parts: event.parts,
95
- });
96
- },
97
- });
98
- if (transcript.notes.length > 0)
99
- notes.push(...transcript.notes);
100
- return { text: transcript.text, provider: transcript.provider, error: transcript.error };
101
- }
102
- if (head.contentLength !== null && head.contentLength <= whisper_js_1.MAX_OPENAI_UPLOAD_BYTES) {
103
- const bytes = await downloadCappedBytes(fetchImpl, url, whisper_js_1.MAX_OPENAI_UPLOAD_BYTES, {
104
- totalBytes,
105
- onProgress: (downloadedBytes) => progress?.onProgress?.({
106
- kind: 'transcript-media-download-progress',
107
- url: progress.url,
108
- service: progress.service,
109
- downloadedBytes,
110
- totalBytes,
111
- }),
112
- });
113
- progress?.onProgress?.({
114
- kind: 'transcript-media-download-done',
115
- url: progress.url,
116
- service: progress.service,
117
- downloadedBytes: bytes.byteLength,
118
- totalBytes,
119
- });
120
- progress?.onProgress?.({
121
- kind: 'transcript-whisper-start',
122
- url: progress.url,
123
- service: progress.service,
124
- providerHint,
125
- modelId,
126
- totalDurationSeconds: durationSecondsHint,
127
- parts: null,
128
- });
129
- const transcript = await (0, whisper_js_1.transcribeMediaWithWhisper)({
130
- bytes,
131
- mediaType,
132
- filename,
133
- openaiApiKey,
134
- falApiKey,
135
- totalDurationSeconds: durationSecondsHint,
136
- onProgress: (event) => {
137
- progress?.onProgress?.({
138
- kind: 'transcript-whisper-progress',
139
- url: progress.url,
140
- service: progress.service,
141
- processedDurationSeconds: event.processedDurationSeconds,
142
- totalDurationSeconds: event.totalDurationSeconds,
143
- partIndex: event.partIndex,
144
- parts: event.parts,
145
- });
146
- },
147
- });
148
- if (transcript.notes.length > 0)
149
- notes.push(...transcript.notes);
150
- return { text: transcript.text, provider: transcript.provider, error: transcript.error };
151
- }
152
- const tmpFile = (0, node_path_1.join)((0, node_os_1.tmpdir)(), `summarize-podcast-${(0, node_crypto_1.randomUUID)()}.bin`);
153
- try {
154
- const downloadedBytes = await downloadToFile(fetchImpl, url, tmpFile, {
155
- totalBytes,
156
- onProgress: (nextDownloadedBytes) => progress?.onProgress?.({
157
- kind: 'transcript-media-download-progress',
158
- url: progress.url,
159
- service: progress.service,
160
- downloadedBytes: nextDownloadedBytes,
161
- totalBytes,
162
- }),
163
- });
164
- progress?.onProgress?.({
165
- kind: 'transcript-media-download-done',
166
- url: progress.url,
167
- service: progress.service,
168
- downloadedBytes,
169
- totalBytes,
170
- });
171
- const probedDurationSeconds = durationSecondsHint ?? (await (0, whisper_js_1.probeMediaDurationSecondsWithFfprobe)(tmpFile));
172
- progress?.onProgress?.({
173
- kind: 'transcript-whisper-start',
174
- url: progress.url,
175
- service: progress.service,
176
- providerHint,
177
- modelId,
178
- totalDurationSeconds: probedDurationSeconds,
179
- parts: null,
180
- });
181
- const transcript = await (0, whisper_js_1.transcribeMediaFileWithWhisper)({
182
- filePath: tmpFile,
183
- mediaType,
184
- filename,
185
- openaiApiKey,
186
- falApiKey,
187
- totalDurationSeconds: probedDurationSeconds,
188
- onProgress: (event) => {
189
- progress?.onProgress?.({
190
- kind: 'transcript-whisper-progress',
191
- url: progress.url,
192
- service: progress.service,
193
- processedDurationSeconds: event.processedDurationSeconds,
194
- totalDurationSeconds: event.totalDurationSeconds,
195
- partIndex: event.partIndex,
196
- parts: event.parts,
197
- });
198
- },
199
- });
200
- if (transcript.notes.length > 0)
201
- notes.push(...transcript.notes);
202
- return { text: transcript.text, provider: transcript.provider, error: transcript.error };
203
- }
204
- finally {
205
- await node_fs_1.promises.unlink(tmpFile).catch(() => { });
206
- }
207
- }
208
- async function probeRemoteMedia(fetchImpl, url) {
209
- try {
210
- const res = await fetchImpl(url, {
211
- method: 'HEAD',
212
- redirect: 'follow',
213
- signal: AbortSignal.timeout(constants_js_1.TRANSCRIPTION_TIMEOUT_MS),
214
- });
215
- if (!res.ok)
216
- throw new Error('head failed');
217
- const contentLength = parseContentLength(res.headers.get('content-length'));
218
- const mediaType = normalizeHeaderType(res.headers.get('content-type'));
219
- const filename = filenameFromUrl(url);
220
- return { contentLength, mediaType, filename };
221
- }
222
- catch {
223
- return { contentLength: null, mediaType: null, filename: filenameFromUrl(url) };
224
- }
225
- }
226
- async function downloadCappedBytes(fetchImpl, url, maxBytes, options) {
227
- const res = await fetchImpl(url, {
228
- redirect: 'follow',
229
- headers: { Range: `bytes=0-${maxBytes - 1}` },
230
- signal: AbortSignal.timeout(constants_js_1.TRANSCRIPTION_TIMEOUT_MS),
231
- });
232
- if (!res.ok) {
233
- throw new Error(`Download failed (${res.status})`);
234
- }
235
- const body = res.body;
236
- if (!body) {
237
- const arrayBuffer = await res.arrayBuffer();
238
- return new Uint8Array(arrayBuffer.slice(0, maxBytes));
239
- }
240
- const reader = body.getReader();
241
- const chunks = [];
242
- let total = 0;
243
- let lastReported = 0;
244
- try {
245
- while (total < maxBytes) {
246
- const { value, done } = await reader.read();
247
- if (done)
248
- break;
249
- if (!value)
250
- continue;
251
- const remaining = maxBytes - total;
252
- const next = value.byteLength > remaining ? value.slice(0, remaining) : value;
253
- chunks.push(next);
254
- total += next.byteLength;
255
- if (total - lastReported >= 64 * 1024) {
256
- lastReported = total;
257
- options?.onProgress?.(total);
258
- }
259
- if (total >= maxBytes)
260
- break;
261
- }
262
- }
263
- finally {
264
- await reader.cancel().catch(() => { });
265
- }
266
- options?.onProgress?.(total);
267
- const out = new Uint8Array(total);
268
- let offset = 0;
269
- for (const chunk of chunks) {
270
- out.set(chunk, offset);
271
- offset += chunk.byteLength;
272
- }
273
- return out;
274
- }
275
- async function downloadToFile(fetchImpl, url, filePath, options) {
276
- const res = await fetchImpl(url, {
277
- redirect: 'follow',
278
- signal: AbortSignal.timeout(constants_js_1.TRANSCRIPTION_TIMEOUT_MS),
279
- });
280
- if (!res.ok) {
281
- throw new Error(`Download failed (${res.status})`);
282
- }
283
- const body = res.body;
284
- if (!body) {
285
- const bytes = new Uint8Array(await res.arrayBuffer());
286
- await node_fs_1.promises.writeFile(filePath, bytes);
287
- options?.onProgress?.(bytes.byteLength);
288
- return bytes.byteLength;
289
- }
290
- const handle = await node_fs_1.promises.open(filePath, 'w');
291
- let downloadedBytes = 0;
292
- let lastReported = 0;
293
- try {
294
- const reader = body.getReader();
295
- try {
296
- while (true) {
297
- const { value, done } = await reader.read();
298
- if (done)
299
- break;
300
- if (!value)
301
- continue;
302
- await handle.write(value);
303
- downloadedBytes += value.byteLength;
304
- if (downloadedBytes - lastReported >= 128 * 1024) {
305
- lastReported = downloadedBytes;
306
- options?.onProgress?.(downloadedBytes);
307
- }
308
- }
309
- options?.onProgress?.(downloadedBytes);
310
- }
311
- finally {
312
- await reader.cancel().catch(() => { });
313
- }
314
- }
315
- finally {
316
- await handle.close().catch(() => { });
317
- }
318
- return downloadedBytes;
319
- }
320
- function normalizeHeaderType(value) {
321
- if (!value)
322
- return null;
323
- const trimmed = value.trim();
324
- if (!trimmed)
325
- return null;
326
- return trimmed.split(';')[0]?.trim().toLowerCase() ?? null;
327
- }
328
- function parseContentLength(value) {
329
- if (!value)
330
- return null;
331
- const parsed = Number(value);
332
- return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : null;
333
- }
334
- function filenameFromUrl(url) {
335
- try {
336
- const parsed = new URL(url);
337
- const base = parsed.pathname.split('/').pop() ?? '';
338
- return base.trim().length > 0 ? base : null;
339
- }
340
- catch {
341
- return null;
342
- }
343
- }
344
- function formatBytes(bytes) {
345
- const units = ['B', 'KB', 'MB', 'GB'];
346
- let value = bytes;
347
- let idx = 0;
348
- while (value >= 1024 && idx < units.length - 1) {
349
- value /= 1024;
350
- idx += 1;
351
- }
352
- const decimals = value >= 10 || idx === 0 ? 0 : 1;
353
- return `${value.toFixed(decimals)}${units[idx]}`;
354
- }
355
- //# sourceMappingURL=media.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"media.js","sourceRoot":"","sources":["../../../../../../src/content/transcript/providers/podcast/media.ts"],"names":[],"mappings":";;AA4BA,gDA+NC;AAED,4CAkBC;AAED,kDAmDC;AAED,wCA8CC;AAED,kDAKC;AAED,gDAIC;AAED,0CAQC;AAED,kCAUC;AAvZD,6CAAwC;AACxC,qCAAwC;AACxC,qCAAgC;AAChC,yCAAgC;AAChC,qEAQ6C;AAE7C,iDAAiF;AAc1E,KAAK,UAAU,kBAAkB,CAAC,EACvC,SAAS,EACT,GAAG,EACH,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,KAAK,EACL,QAAQ,GAcT;IACC,MAAM,QAAQ,GAAG,MAAM,IAAA,8BAAiB,GAAE,CAAA;IAC1C,MAAM,YAAY,GAChB,CAAC,MAAM,IAAA,8BAAiB,GAAE,CAAC;QACzB,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,YAAY,IAAI,SAAS;YACzB,CAAC,CAAC,aAAa;YACf,CAAC,CAAC,YAAY;gBACZ,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,SAAS;oBACT,CAAC,CAAC,KAAK;oBACP,CAAC,CAAC,SAAS,CAAA;IAErB,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;IACnD,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,IAAI,IAAI,CAAC,aAAa,GAAG,qCAAsB,EAAE,CAAC;QAC/E,MAAM,IAAI,KAAK,CACb,2BAA2B,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,WAAW,CAAC,qCAAsB,CAAC,GAAG,CAChH,CAAA;IACH,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,0BAA0B,CAAA;IAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,YAAY,CAAA;IAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAA;IAErC,QAAQ,EAAE,UAAU,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AAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;QAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAA;QACnD,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC;AAED,SAAgB,WAAW,CAAC,KAAa;IACvC,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IACrC,IAAI,KAAK,GAAG,KAAK,CAAA;IACjB,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,OAAO,KAAK,IAAI,IAAI,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/C,KAAK,IAAI,IAAI,CAAA;QACb,GAAG,IAAI,CAAC,CAAA;IACV,CAAC;IACD,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACjD,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAA;AAClD,CAAC"}
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.joinNotes = joinNotes;
4
- exports.buildWhisperResult = buildWhisperResult;
5
- function joinNotes(notes) {
6
- return notes.length > 0 ? notes.join('; ') : null;
7
- }
8
- function buildWhisperResult({ attemptedProviders, notes, outcome, metadata, includeProviderOnFailure = false, }) {
9
- if (outcome.text) {
10
- return {
11
- text: outcome.text,
12
- source: 'whisper',
13
- attemptedProviders,
14
- notes: joinNotes(notes),
15
- metadata: {
16
- ...metadata,
17
- transcriptionProvider: outcome.provider,
18
- },
19
- };
20
- }
21
- const failureMetadata = includeProviderOnFailure && outcome.provider
22
- ? { ...metadata, transcriptionProvider: outcome.provider }
23
- : metadata;
24
- return {
25
- text: null,
26
- source: null,
27
- attemptedProviders,
28
- notes: outcome.error?.message ?? null,
29
- metadata: failureMetadata,
30
- };
31
- }
32
- //# sourceMappingURL=results.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"results.js","sourceRoot":"","sources":["../../../../../../src/content/transcript/providers/podcast/results.ts"],"names":[],"mappings":";;AAGA,8BAEC;AAED,gDAsCC;AA1CD,SAAgB,SAAS,CAAC,KAAe;IACvC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACnD,CAAC;AAED,SAAgB,kBAAkB,CAAC,EACjC,kBAAkB,EAClB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,wBAAwB,GAAG,KAAK,GAOjC;IACC,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,MAAM,EAAE,SAAS;YACjB,kBAAkB;YAClB,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC;YACvB,QAAQ,EAAE;gBACR,GAAG,QAAQ;gBACX,qBAAqB,EAAE,OAAO,CAAC,QAAQ;aACxC;SACF,CAAA;IACH,CAAC;IAED,MAAM,eAAe,GACnB,wBAAwB,IAAI,OAAO,CAAC,QAAQ;QAC1C,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,qBAAqB,EAAE,OAAO,CAAC,QAAQ,EAAE;QAC1D,CAAC,CAAC,QAAQ,CAAA;IAEd,OAAO;QACL,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,IAAI;QACZ,kBAAkB;QAClB,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,IAAI,IAAI;QACrC,QAAQ,EAAE,eAAe;KAC1B,CAAA;AACH,CAAC"}
@@ -1,262 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.looksLikeRssOrAtomFeed = looksLikeRssOrAtomFeed;
4
- exports.extractEnclosureFromFeed = extractEnclosureFromFeed;
5
- exports.extractEnclosureForEpisode = extractEnclosureForEpisode;
6
- exports.extractItemDurationSeconds = extractItemDurationSeconds;
7
- exports.decodeXmlEntities = decodeXmlEntities;
8
- exports.normalizeLooseTitle = normalizeLooseTitle;
9
- exports.tryFetchTranscriptFromFeedXml = tryFetchTranscriptFromFeedXml;
10
- const constants_js_1 = require("./constants.js");
11
- function looksLikeRssOrAtomFeed(xml) {
12
- const head = xml.slice(0, 4096).trimStart().toLowerCase();
13
- if (head.startsWith('<rss') || head.includes('<rss'))
14
- return true;
15
- if (head.startsWith('<?xml') && (head.includes('<rss') || head.includes('<feed')))
16
- return true;
17
- if (head.startsWith('<feed') || head.includes('<feed'))
18
- return true;
19
- return false;
20
- }
21
- function extractEnclosureFromFeed(xml) {
22
- const items = xml.match(/<item\b[\s\S]*?<\/item>/gi) ?? [];
23
- for (const item of items) {
24
- const enclosureUrl = extractEnclosureUrlFromItem(item);
25
- if (!enclosureUrl)
26
- continue;
27
- return { enclosureUrl, durationSeconds: extractItemDurationSeconds(item) };
28
- }
29
- const enclosureMatch = xml.match(/<enclosure\b[^>]*\burl\s*=\s*(['"])([^'"]+)\1/i);
30
- if (enclosureMatch?.[2]) {
31
- return { enclosureUrl: enclosureMatch[2], durationSeconds: extractItemDurationSeconds(xml) };
32
- }
33
- const atomMatch = xml.match(/<link\b[^>]*\brel\s*=\s*(['"])enclosure\1[^>]*\bhref\s*=\s*(['"])([^'"]+)\2/i);
34
- if (atomMatch?.[3]) {
35
- return { enclosureUrl: atomMatch[3], durationSeconds: extractItemDurationSeconds(xml) };
36
- }
37
- return null;
38
- }
39
- function extractEnclosureForEpisode(feedXml, episodeTitle) {
40
- const normalizedTarget = normalizeLooseTitle(episodeTitle);
41
- const items = feedXml.match(/<item\b[\s\S]*?<\/item>/gi) ?? [];
42
- for (const item of items) {
43
- const title = extractItemTitle(item);
44
- if (!title)
45
- continue;
46
- if (normalizeLooseTitle(title) !== normalizedTarget)
47
- continue;
48
- const enclosureUrl = extractEnclosureUrlFromItem(item);
49
- if (!enclosureUrl)
50
- continue;
51
- return { enclosureUrl, durationSeconds: extractItemDurationSeconds(item) };
52
- }
53
- return null;
54
- }
55
- function extractItemDurationSeconds(itemXml) {
56
- const match = itemXml.match(/<itunes:duration>([\s\S]*?)<\/itunes:duration>/i);
57
- if (!match?.[1])
58
- return null;
59
- const raw = match[1]
60
- .replaceAll(/<!\[CDATA\[/gi, '')
61
- .replaceAll(/\]\]>/g, '')
62
- .trim();
63
- if (!raw)
64
- return null;
65
- // common forms: "HH:MM:SS", "MM:SS", "SS"
66
- if (/^\d+$/.test(raw)) {
67
- const seconds = Number(raw);
68
- return Number.isFinite(seconds) && seconds > 0 ? seconds : null;
69
- }
70
- const parts = raw
71
- .split(':')
72
- .map((value) => value.trim())
73
- .filter(Boolean);
74
- if (parts.length < 2 || parts.length > 3)
75
- return null;
76
- const nums = parts.map((value) => Number(value));
77
- if (nums.some((n) => !Number.isFinite(n) || n < 0))
78
- return null;
79
- const seconds = (() => {
80
- if (nums.length === 3) {
81
- const [hours, minutes, secondsRaw] = nums;
82
- if (hours === undefined || minutes === undefined || secondsRaw === undefined)
83
- return null;
84
- return Math.round(hours * 3600 + minutes * 60 + secondsRaw);
85
- }
86
- const [minutes, secondsRaw] = nums;
87
- if (minutes === undefined || secondsRaw === undefined)
88
- return null;
89
- return Math.round(minutes * 60 + secondsRaw);
90
- })();
91
- if (seconds === null)
92
- return null;
93
- return seconds > 0 ? seconds : null;
94
- }
95
- function decodeXmlEntities(value) {
96
- return value
97
- .replaceAll(/&amp;/gi, '&')
98
- .replaceAll(/&#38;/g, '&')
99
- .replaceAll(/&lt;/gi, '<')
100
- .replaceAll(/&gt;/gi, '>')
101
- .replaceAll(/&quot;/gi, '"')
102
- .replaceAll(/&apos;/gi, "'");
103
- }
104
- function normalizeLooseTitle(value) {
105
- return value
106
- .toLowerCase()
107
- .normalize('NFKD')
108
- .replaceAll(/\p{Diacritic}+/gu, '')
109
- .replaceAll(/[^a-z0-9]+/g, ' ')
110
- .trim();
111
- }
112
- async function tryFetchTranscriptFromFeedXml({ fetchImpl, feedXml, episodeTitle, notes, }) {
113
- const items = feedXml.match(/<item\b[\s\S]*?<\/item>/gi) ?? [];
114
- const normalizedTarget = episodeTitle ? normalizeLooseTitle(episodeTitle) : null;
115
- for (const item of items) {
116
- if (normalizedTarget) {
117
- const title = extractItemTitle(item);
118
- if (!title || normalizeLooseTitle(title) !== normalizedTarget)
119
- continue;
120
- }
121
- const candidates = extractPodcastTranscriptCandidatesFromItem(item);
122
- const preferred = selectPreferredTranscriptCandidate(candidates);
123
- if (!preferred) {
124
- if (normalizedTarget)
125
- return null;
126
- continue;
127
- }
128
- const transcriptUrl = decodeXmlEntities(preferred.url);
129
- try {
130
- const res = await fetchImpl(transcriptUrl, {
131
- redirect: 'follow',
132
- signal: AbortSignal.timeout(constants_js_1.TRANSCRIPTION_TIMEOUT_MS),
133
- headers: { accept: 'text/vtt,text/plain,application/json;q=0.9,*/*;q=0.8' },
134
- });
135
- if (!res.ok)
136
- throw new Error(`transcript fetch failed (${res.status})`);
137
- const contentType = res.headers.get('content-type')?.toLowerCase().split(';')[0]?.trim() ?? null;
138
- const hintedType = preferred.type?.toLowerCase().split(';')[0]?.trim() ?? null;
139
- const effectiveType = hintedType ?? contentType;
140
- const body = await res.text();
141
- const text = (() => {
142
- if (effectiveType === 'application/json' || transcriptUrl.toLowerCase().endsWith('.json')) {
143
- try {
144
- return jsonTranscriptToPlainText(JSON.parse(body));
145
- }
146
- catch {
147
- return null;
148
- }
149
- }
150
- if (effectiveType === 'text/vtt' || transcriptUrl.toLowerCase().endsWith('.vtt')) {
151
- const plain = vttToPlainText(body);
152
- return plain.length > 0 ? plain : null;
153
- }
154
- const plain = body.trim();
155
- return plain.length > 0 ? plain : null;
156
- })();
157
- if (!text) {
158
- if (normalizedTarget)
159
- return null;
160
- continue;
161
- }
162
- notes.push('Used RSS <podcast:transcript> (skipped Whisper)');
163
- return { text, transcriptUrl, transcriptType: effectiveType };
164
- }
165
- catch (error) {
166
- if (normalizedTarget) {
167
- notes.push(`RSS <podcast:transcript> fetch failed: ${error instanceof Error ? error.message : String(error)}`);
168
- return null;
169
- }
170
- }
171
- }
172
- return null;
173
- }
174
- function extractEnclosureUrlFromItem(xml) {
175
- const enclosureMatch = xml.match(/<enclosure\b[^>]*\burl\s*=\s*(['"])([^'"]+)\1/i);
176
- if (enclosureMatch?.[2])
177
- return enclosureMatch[2];
178
- const atomMatch = xml.match(/<link\b[^>]*\brel\s*=\s*(['"])enclosure\1[^>]*\bhref\s*=\s*(['"])([^'"]+)\2/i);
179
- if (atomMatch?.[3])
180
- return atomMatch[3];
181
- return null;
182
- }
183
- function extractItemTitle(itemXml) {
184
- const match = itemXml.match(/<title>([\s\S]*?)<\/title>/i);
185
- if (!match?.[1])
186
- return null;
187
- const raw = match[1]
188
- .replaceAll(/<!\[CDATA\[/gi, '')
189
- .replaceAll(/\]\]>/g, '')
190
- .trim();
191
- return raw.length > 0 ? raw : null;
192
- }
193
- function extractPodcastTranscriptCandidatesFromItem(itemXml) {
194
- const matches = itemXml.matchAll(/<podcast:transcript\b[^>]*\burl\s*=\s*(['"])([^'"]+)\1[^>]*>/gi);
195
- const results = [];
196
- for (const match of matches) {
197
- const tag = match[0];
198
- const url = match[2]?.trim();
199
- if (!url)
200
- continue;
201
- const type = tag.match(/\btype\s*=\s*(['"])([^'"]+)\1/i)?.[2]?.trim() ?? null;
202
- results.push({ url, type });
203
- }
204
- return results;
205
- }
206
- function selectPreferredTranscriptCandidate(candidates) {
207
- if (candidates.length === 0)
208
- return null;
209
- const normalized = candidates.map((c) => ({
210
- ...c,
211
- type: c.type?.toLowerCase().split(';')[0]?.trim() ?? null,
212
- }));
213
- const json = normalized.find((c) => c.type === 'application/json' || c.url.toLowerCase().endsWith('.json'));
214
- if (json)
215
- return json;
216
- const vtt = normalized.find((c) => c.type === 'text/vtt' || c.url.toLowerCase().endsWith('.vtt'));
217
- if (vtt)
218
- return vtt;
219
- return normalized[0] ?? null;
220
- }
221
- function vttToPlainText(raw) {
222
- const lines = raw
223
- .replace(/\r\n/g, '\n')
224
- .split('\n')
225
- .map((line) => line.trim())
226
- .filter((line) => line.length > 0)
227
- .filter((line) => line.toUpperCase() !== 'WEBVTT')
228
- .filter((line) => !/^\d{2}:\d{2}:\d{2}\.\d{3}\s+-->\s+\d{2}:\d{2}:\d{2}\.\d{3}/.test(line))
229
- .filter((line) => !/^\d+$/.test(line))
230
- .filter((line) => !/^(NOTE|STYLE|REGION)\b/i.test(line));
231
- return lines.join('\n').trim();
232
- }
233
- function jsonTranscriptToPlainText(payload) {
234
- if (Array.isArray(payload)) {
235
- const parts = payload
236
- .map((row) => (row && typeof row === 'object' ? row.text : null))
237
- .filter((t) => typeof t === 'string')
238
- .map((t) => t.trim())
239
- .filter(Boolean);
240
- const text = parts.join('\n').trim();
241
- return text.length > 0 ? text : null;
242
- }
243
- if (payload && typeof payload === 'object') {
244
- const record = payload;
245
- if (typeof record.transcript === 'string' && record.transcript.trim())
246
- return record.transcript.trim();
247
- if (typeof record.text === 'string' && record.text.trim())
248
- return record.text.trim();
249
- const segments = record.segments;
250
- if (Array.isArray(segments)) {
251
- const parts = segments
252
- .map((row) => row && typeof row === 'object' ? row.text : null)
253
- .filter((t) => typeof t === 'string')
254
- .map((t) => t.trim())
255
- .filter(Boolean);
256
- const text = parts.join('\n').trim();
257
- return text.length > 0 ? text : null;
258
- }
259
- }
260
- return null;
261
- }
262
- //# sourceMappingURL=rss.js.map