@torrent-tv/proxy 2.105.4 → 2.105.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torrent-tv/proxy",
3
- "version": "2.105.4",
3
+ "version": "2.105.5",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -497,10 +497,11 @@ export class AviContainer extends Container {
497
497
  read.set(at, bytes);
498
498
  return bytes;
499
499
  };
500
- const chainAt = async start => {
500
+ const chainAt = async (start, firstOffset) => {
501
501
  let bytes = Buffer.alloc(0), cursor = 0, at = start, frames = 0;
502
502
  while (frames < 3 && at < stream.count && bytes.length < 32 * 1024) {
503
503
  bytes = Buffer.concat([bytes, await bytesAt(at++)]);
504
+ if (at === start + 1) cursor = firstOffset;
504
505
  while (bytes.length - cursor >= 7 && frames < 3) {
505
506
  if (bytes[cursor] !== 0x0b || bytes[cursor + 1] !== 0x77) return false;
506
507
  let frame;
@@ -515,14 +516,22 @@ export class AviContainer extends Container {
515
516
  };
516
517
 
517
518
  const anchor = stream.atOrBefore(interval.from);
518
- let first = -1, scannedBytes = 0;
519
+ let first = -1, firstOffset = -1, scannedBytes = 0;
519
520
  for (let at = anchor; at >= 0 && scannedBytes < 128 * 1024; at--) {
520
521
  const bytes = await bytesAt(at);
521
522
  scannedBytes += bytes.length;
522
- if (bytes.length >= 7 && bytes[0] === 0x0b && bytes[1] === 0x77 && await chainAt(at)) {
523
- first = at;
524
- break;
523
+ for (let offset = 0; offset < bytes.length; offset++) {
524
+ if (bytes[offset] !== 0x0b) continue;
525
+ if (offset + 1 < bytes.length) {
526
+ if (bytes[offset + 1] !== 0x77) continue;
527
+ } else if (at + 1 >= stream.count || (await bytesAt(at + 1))[0] !== 0x77) continue;
528
+ if (await chainAt(at, offset)) {
529
+ first = at;
530
+ firstOffset = offset;
531
+ break;
532
+ }
525
533
  }
534
+ if (first >= 0) break;
526
535
  }
527
536
  if (first < 0) throw new Error("Indexed AVI AC-3 has no complete frame chain near the requested interval.");
528
537
 
@@ -530,7 +539,9 @@ export class AviContainer extends Container {
530
539
  try {
531
540
  for (let at = first; at < stream.count; at++) {
532
541
  const bytes = await bytesAt(at);
533
- if (bytes.length) elementary.push(track.trackNumber, bytes, stream.starts[at], at === first ? { pts: stream.times[first] } : {});
542
+ const offset = at === first ? firstOffset : 0;
543
+ if (bytes.length > offset) elementary.push(track.trackNumber, bytes.subarray(offset), stream.starts[at] + offset,
544
+ at === first ? { pts: stream.times[first] } : {});
534
545
  const input = elementary.index.inputFor({ trackId: track.trackNumber, from: interval.from, to: interval.to,
535
546
  mode: interval.modes?.[track.trackNumber] ?? "transcode" });
536
547
  if (input.kind === "result") {