simpleparty 0.2.0__tar.gz → 0.2.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simpleparty
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Easily enjoy your private video collection
5
5
  Author: Guy Freeman
6
6
  License-Expression: AGPL-3.0-only
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "simpleparty"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "Easily enjoy your private video collection"
9
9
  readme = "README.md"
10
10
  license = "AGPL-3.0-only"
@@ -500,8 +500,41 @@ def render_play_page(data, idx, next_url, prev_url, shuffle_url, is_shuffled, po
500
500
 
501
501
  # --- Video serving ---
502
502
 
503
+ def _is_mpegts(path):
504
+ try:
505
+ with open(path, 'rb') as f:
506
+ header = f.read(377)
507
+ return len(header) >= 377 and header[0] == 0x47 and header[188] == 0x47 and header[376] == 0x47
508
+ except OSError:
509
+ return False
510
+
511
+
503
512
  def _needs_transcode(path):
504
- return path.suffix.lower() not in BROWSER_NATIVE
513
+ if path.suffix.lower() not in BROWSER_NATIVE:
514
+ return True
515
+ return path.suffix.lower() == '.mp4' and _is_mpegts(path)
516
+
517
+
518
+ def _remux_mpegts(path):
519
+ tmp = path.with_suffix('.tmp.mp4')
520
+ try:
521
+ result = subprocess.run(
522
+ ['ffmpeg', '-fflags', '+genpts', '-i', str(path),
523
+ '-c', 'copy', '-bsf:a', 'aac_adtstoasc',
524
+ '-f', 'mp4', '-loglevel', 'error', '-y', str(tmp)],
525
+ capture_output=True, timeout=300,
526
+ )
527
+ if result.returncode == 0:
528
+ os.replace(str(tmp), str(path))
529
+ return True
530
+ return False
531
+ except (subprocess.TimeoutExpired, OSError):
532
+ return False
533
+ finally:
534
+ try:
535
+ tmp.unlink(missing_ok=True)
536
+ except OSError:
537
+ pass
505
538
 
506
539
 
507
540
  def _serve_transcoded(handler, path):
@@ -537,7 +570,7 @@ def _serve_transcoded(handler, path):
537
570
  handler.wfile.write(b'\r\n')
538
571
  handler.wfile.write(b'0\r\n\r\n')
539
572
  proc.wait()
540
- except BrokenPipeError:
573
+ except (BrokenPipeError, ConnectionResetError):
541
574
  proc.kill()
542
575
  except Exception:
543
576
  if proc.poll() is None:
@@ -555,7 +588,7 @@ def _stream_range(handler, path, start, length):
555
588
  break
556
589
  handler.wfile.write(chunk)
557
590
  remaining -= len(chunk)
558
- except BrokenPipeError:
591
+ except (BrokenPipeError, ConnectionResetError):
559
592
  pass
560
593
 
561
594
 
@@ -567,7 +600,7 @@ def _stream_file(handler, path):
567
600
  if not chunk:
568
601
  break
569
602
  handler.wfile.write(chunk)
570
- except BrokenPipeError:
603
+ except (BrokenPipeError, ConnectionResetError):
571
604
  pass
572
605
 
573
606
 
@@ -664,8 +697,11 @@ def handle_video(handler, root):
664
697
  return
665
698
 
666
699
  if _config['allow_transcode'] and _needs_transcode(resolved) and (_config['has_ffmpeg'] or _config['has_vlc']):
667
- _serve_transcoded(handler, resolved)
668
- return
700
+ if _is_mpegts(resolved) and _config['has_ffmpeg'] and _remux_mpegts(resolved):
701
+ pass # file is now a proper MP4, fall through to normal serving
702
+ else:
703
+ _serve_transcoded(handler, resolved)
704
+ return
669
705
 
670
706
  file_size = resolved.stat().st_size
671
707
  content_type = MIME_TYPES.get(resolved.suffix.lower(), 'application/octet-stream')
@@ -752,6 +788,8 @@ def handle_lock(handler, root):
752
788
  # --- Server ---
753
789
 
754
790
  class RequestHandler(BaseHTTPRequestHandler):
791
+ protocol_version = 'HTTP/1.1'
792
+
755
793
  def __init__(self, root, *args, **kwargs):
756
794
  self.root = root
757
795
  super().__init__(*args, **kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simpleparty
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Easily enjoy your private video collection
5
5
  Author: Guy Freeman
6
6
  License-Expression: AGPL-3.0-only
File without changes
File without changes
File without changes