koztv-blog-tools 1.3.2 → 1.3.3

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/node.d.mts CHANGED
@@ -27,6 +27,8 @@ interface TelegramExportOptions {
27
27
  downloadMedia?: boolean;
28
28
  /** Skip posts that already have markdown files */
29
29
  skipExisting?: boolean;
30
+ /** Compress large videos and skip files over 95MB (requires ffmpeg) */
31
+ compressMedia?: boolean;
30
32
  /** Number of concurrent media downloads */
31
33
  mediaWorkers?: number;
32
34
  /** Callback for progress updates */
package/dist/node.d.ts CHANGED
@@ -27,6 +27,8 @@ interface TelegramExportOptions {
27
27
  downloadMedia?: boolean;
28
28
  /** Skip posts that already have markdown files */
29
29
  skipExisting?: boolean;
30
+ /** Compress large videos and skip files over 95MB (requires ffmpeg) */
31
+ compressMedia?: boolean;
30
32
  /** Number of concurrent media downloads */
31
33
  mediaWorkers?: number;
32
34
  /** Callback for progress updates */
package/dist/node.js CHANGED
@@ -539,6 +539,7 @@ async function exportTelegramChannel(options) {
539
539
  until,
540
540
  downloadMedia = true,
541
541
  skipExisting = false,
542
+ compressMedia = false,
542
543
  mediaWorkers = 3,
543
544
  onProgress,
544
545
  onPhoneNumber = () => defaultReadline("Phone number: "),
@@ -679,36 +680,40 @@ async function exportTelegramChannel(options) {
679
680
  const mediaFileName = `media${ext}`;
680
681
  const mediaPath = path.join(postMediaDir, mediaFileName);
681
682
  fs.writeFileSync(mediaPath, buffer);
682
- const stats = fs.statSync(mediaPath);
683
- const isVideo = [".mp4", ".mov", ".avi", ".webm", ".m4v"].includes(ext.toLowerCase());
684
- if (stats.size > MAX_FILE_SIZE) {
685
- if (isVideo && hasFFmpeg()) {
686
- const compressedPath = path.join(postMediaDir, `media_compressed${ext}`);
687
- if (compressVideo(mediaPath, compressedPath)) {
688
- fs.unlinkSync(mediaPath);
689
- fs.renameSync(compressedPath, mediaPath);
690
- mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
683
+ if (compressMedia) {
684
+ const stats = fs.statSync(mediaPath);
685
+ const isVideo = [".mp4", ".mov", ".avi", ".webm", ".m4v"].includes(ext.toLowerCase());
686
+ if (stats.size > MAX_FILE_SIZE) {
687
+ if (isVideo && hasFFmpeg()) {
688
+ const compressedPath = path.join(postMediaDir, `media_compressed${ext}`);
689
+ if (compressVideo(mediaPath, compressedPath)) {
690
+ fs.unlinkSync(mediaPath);
691
+ fs.renameSync(compressedPath, mediaPath);
692
+ mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
693
+ } else {
694
+ fs.unlinkSync(mediaPath);
695
+ if (fs.existsSync(compressedPath)) fs.unlinkSync(compressedPath);
696
+ console.warn(`Skipping large media for message ${msgId} (>${MAX_FILE_SIZE / 1024 / 1024}MB)`);
697
+ }
691
698
  } else {
692
699
  fs.unlinkSync(mediaPath);
693
- if (fs.existsSync(compressedPath)) fs.unlinkSync(compressedPath);
694
700
  console.warn(`Skipping large media for message ${msgId} (>${MAX_FILE_SIZE / 1024 / 1024}MB)`);
695
701
  }
696
- } else {
697
- fs.unlinkSync(mediaPath);
698
- console.warn(`Skipping large media for message ${msgId} (>${MAX_FILE_SIZE / 1024 / 1024}MB)`);
699
- }
700
- } else if (stats.size > COMPRESS_THRESHOLD && isVideo && hasFFmpeg()) {
701
- const compressedPath = path.join(postMediaDir, `media_compressed${ext}`);
702
- if (compressVideo(mediaPath, compressedPath)) {
703
- const compressedStats = fs.statSync(compressedPath);
704
- if (compressedStats.size < stats.size) {
705
- fs.unlinkSync(mediaPath);
706
- fs.renameSync(compressedPath, mediaPath);
707
- } else {
708
- fs.unlinkSync(compressedPath);
702
+ } else if (stats.size > COMPRESS_THRESHOLD && isVideo && hasFFmpeg()) {
703
+ const compressedPath = path.join(postMediaDir, `media_compressed${ext}`);
704
+ if (compressVideo(mediaPath, compressedPath)) {
705
+ const compressedStats = fs.statSync(compressedPath);
706
+ if (compressedStats.size < stats.size) {
707
+ fs.unlinkSync(mediaPath);
708
+ fs.renameSync(compressedPath, mediaPath);
709
+ } else {
710
+ fs.unlinkSync(compressedPath);
711
+ }
709
712
  }
713
+ mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
714
+ } else {
715
+ mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
710
716
  }
711
- mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
712
717
  } else {
713
718
  mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
714
719
  }
package/dist/node.mjs CHANGED
@@ -189,6 +189,7 @@ async function exportTelegramChannel(options) {
189
189
  until,
190
190
  downloadMedia = true,
191
191
  skipExisting = false,
192
+ compressMedia = false,
192
193
  mediaWorkers = 3,
193
194
  onProgress,
194
195
  onPhoneNumber = () => defaultReadline("Phone number: "),
@@ -329,36 +330,40 @@ async function exportTelegramChannel(options) {
329
330
  const mediaFileName = `media${ext}`;
330
331
  const mediaPath = path.join(postMediaDir, mediaFileName);
331
332
  fs.writeFileSync(mediaPath, buffer);
332
- const stats = fs.statSync(mediaPath);
333
- const isVideo = [".mp4", ".mov", ".avi", ".webm", ".m4v"].includes(ext.toLowerCase());
334
- if (stats.size > MAX_FILE_SIZE) {
335
- if (isVideo && hasFFmpeg()) {
336
- const compressedPath = path.join(postMediaDir, `media_compressed${ext}`);
337
- if (compressVideo(mediaPath, compressedPath)) {
338
- fs.unlinkSync(mediaPath);
339
- fs.renameSync(compressedPath, mediaPath);
340
- mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
333
+ if (compressMedia) {
334
+ const stats = fs.statSync(mediaPath);
335
+ const isVideo = [".mp4", ".mov", ".avi", ".webm", ".m4v"].includes(ext.toLowerCase());
336
+ if (stats.size > MAX_FILE_SIZE) {
337
+ if (isVideo && hasFFmpeg()) {
338
+ const compressedPath = path.join(postMediaDir, `media_compressed${ext}`);
339
+ if (compressVideo(mediaPath, compressedPath)) {
340
+ fs.unlinkSync(mediaPath);
341
+ fs.renameSync(compressedPath, mediaPath);
342
+ mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
343
+ } else {
344
+ fs.unlinkSync(mediaPath);
345
+ if (fs.existsSync(compressedPath)) fs.unlinkSync(compressedPath);
346
+ console.warn(`Skipping large media for message ${msgId} (>${MAX_FILE_SIZE / 1024 / 1024}MB)`);
347
+ }
341
348
  } else {
342
349
  fs.unlinkSync(mediaPath);
343
- if (fs.existsSync(compressedPath)) fs.unlinkSync(compressedPath);
344
350
  console.warn(`Skipping large media for message ${msgId} (>${MAX_FILE_SIZE / 1024 / 1024}MB)`);
345
351
  }
346
- } else {
347
- fs.unlinkSync(mediaPath);
348
- console.warn(`Skipping large media for message ${msgId} (>${MAX_FILE_SIZE / 1024 / 1024}MB)`);
349
- }
350
- } else if (stats.size > COMPRESS_THRESHOLD && isVideo && hasFFmpeg()) {
351
- const compressedPath = path.join(postMediaDir, `media_compressed${ext}`);
352
- if (compressVideo(mediaPath, compressedPath)) {
353
- const compressedStats = fs.statSync(compressedPath);
354
- if (compressedStats.size < stats.size) {
355
- fs.unlinkSync(mediaPath);
356
- fs.renameSync(compressedPath, mediaPath);
357
- } else {
358
- fs.unlinkSync(compressedPath);
352
+ } else if (stats.size > COMPRESS_THRESHOLD && isVideo && hasFFmpeg()) {
353
+ const compressedPath = path.join(postMediaDir, `media_compressed${ext}`);
354
+ if (compressVideo(mediaPath, compressedPath)) {
355
+ const compressedStats = fs.statSync(compressedPath);
356
+ if (compressedStats.size < stats.size) {
357
+ fs.unlinkSync(mediaPath);
358
+ fs.renameSync(compressedPath, mediaPath);
359
+ } else {
360
+ fs.unlinkSync(compressedPath);
361
+ }
359
362
  }
363
+ mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
364
+ } else {
365
+ mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
360
366
  }
361
- mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
362
367
  } else {
363
368
  mediaFiles.push(`media/${paddedId}/${mediaFileName}`);
364
369
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koztv-blog-tools",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Shared utilities for Telegram-based blog sites",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",