tokwatchr 0.6.2 → 0.6.4

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.d.mts CHANGED
@@ -101,6 +101,8 @@ interface RemuxInfo {
101
101
  filePath: string;
102
102
  /** Input file size in MB. */
103
103
  inputSizeMB: number;
104
+ /** Output file size in MB. Only set when status is "completed". */
105
+ outputSizeMB?: number;
104
106
  /** Remux status: started → completed (with outputPath) or failed (keeping .ts). */
105
107
  status: "started" | "completed" | "failed";
106
108
  /** Output file path. Only set when status is "completed". */
package/dist/index.mjs CHANGED
@@ -766,6 +766,8 @@ var TikTokLiveDownloader = class {
766
766
  return resolved;
767
767
  }
768
768
  async _run(waitForLive) {
769
+ this.abortController = new AbortController();
770
+ if (this.options.signal) this.options.signal.addEventListener("abort", () => this.abortController.abort(), { once: true });
769
771
  const pendingRemuxes = [];
770
772
  try {
771
773
  this.setState("waiting");
@@ -988,6 +990,11 @@ var TikTokLiveDownloader = class {
988
990
  });
989
991
  try {
990
992
  await this.remuxAndNormalize(this.options.ffmpegPath, inputPath, finalPath);
993
+ let realSizeBytes = tsResult.sizeBytes;
994
+ try {
995
+ const { statSync } = await import("node:fs");
996
+ realSizeBytes = statSync(finalPath).size;
997
+ } catch {}
991
998
  try {
992
999
  const { unlinkSync } = await import("node:fs");
993
1000
  unlinkSync(inputPath);
@@ -996,11 +1003,14 @@ var TikTokLiveDownloader = class {
996
1003
  filePath: inputPath,
997
1004
  outputPath: finalPath,
998
1005
  inputSizeMB: tsResult.sizeMB,
1006
+ outputSizeMB: realSizeBytes / (1024 * 1024),
999
1007
  status: "completed"
1000
1008
  });
1001
1009
  return {
1002
1010
  ...tsResult,
1003
1011
  filePath: finalPath,
1012
+ sizeBytes: realSizeBytes,
1013
+ sizeMB: realSizeBytes / (1024 * 1024),
1004
1014
  format: finalExt
1005
1015
  };
1006
1016
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokwatchr",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "Download TikTok livestreams. Given a username, download the livestream.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",
@@ -244,6 +244,16 @@ export class TikTokLiveDownloader {
244
244
  }
245
245
 
246
246
  private async _run(waitForLive: boolean): Promise<DownloadResult> {
247
+ // Reset abortController so start() can be called multiple times
248
+ this.abortController = new AbortController();
249
+ if (this.options.signal) {
250
+ this.options.signal.addEventListener(
251
+ "abort",
252
+ () => this.abortController.abort(),
253
+ { once: true },
254
+ );
255
+ }
256
+
247
257
  // Track background remuxes so we can await them on error/abort
248
258
  const pendingRemuxes: Promise<DownloadResult>[] = [];
249
259
 
@@ -584,7 +594,16 @@ export class TikTokLiveDownloader {
584
594
  inputPath,
585
595
  finalPath,
586
596
  );
587
- // Remux succeeded — delete temp .ts
597
+ // Remux succeeded — stat the real output size
598
+ let realSizeBytes = tsResult.sizeBytes;
599
+ try {
600
+ const { statSync } = await import("node:fs");
601
+ realSizeBytes = statSync(finalPath).size;
602
+ } catch {
603
+ // fall back to input size if stat fails
604
+ }
605
+
606
+ // Delete temp .ts
588
607
  try {
589
608
  const { unlinkSync } = await import("node:fs");
590
609
  unlinkSync(inputPath);
@@ -596,12 +615,15 @@ export class TikTokLiveDownloader {
596
615
  filePath: inputPath,
597
616
  outputPath: finalPath,
598
617
  inputSizeMB: tsResult.sizeMB,
618
+ outputSizeMB: realSizeBytes / (1024 * 1024),
599
619
  status: "completed",
600
620
  });
601
621
 
602
622
  return {
603
623
  ...tsResult,
604
624
  filePath: finalPath,
625
+ sizeBytes: realSizeBytes,
626
+ sizeMB: realSizeBytes / (1024 * 1024),
605
627
  format: finalExt as "mp4" | "mkv",
606
628
  };
607
629
  } catch (err) {
package/src/types.ts CHANGED
@@ -128,6 +128,8 @@ export interface RemuxInfo {
128
128
  filePath: string;
129
129
  /** Input file size in MB. */
130
130
  inputSizeMB: number;
131
+ /** Output file size in MB. Only set when status is "completed". */
132
+ outputSizeMB?: number;
131
133
  /** Remux status: started → completed (with outputPath) or failed (keeping .ts). */
132
134
  status: "started" | "completed" | "failed";
133
135
  /** Output file path. Only set when status is "completed". */