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.
- {simpleparty-0.2.0/src/simpleparty.egg-info → simpleparty-0.2.2}/PKG-INFO +1 -1
- {simpleparty-0.2.0 → simpleparty-0.2.2}/pyproject.toml +1 -1
- {simpleparty-0.2.0 → simpleparty-0.2.2}/src/simpleparty/server.py +44 -6
- {simpleparty-0.2.0 → simpleparty-0.2.2/src/simpleparty.egg-info}/PKG-INFO +1 -1
- {simpleparty-0.2.0 → simpleparty-0.2.2}/LICENSE +0 -0
- {simpleparty-0.2.0 → simpleparty-0.2.2}/README.md +0 -0
- {simpleparty-0.2.0 → simpleparty-0.2.2}/setup.cfg +0 -0
- {simpleparty-0.2.0 → simpleparty-0.2.2}/src/simpleparty/__init__.py +0 -0
- {simpleparty-0.2.0 → simpleparty-0.2.2}/src/simpleparty/__main__.py +0 -0
- {simpleparty-0.2.0 → simpleparty-0.2.2}/src/simpleparty.egg-info/SOURCES.txt +0 -0
- {simpleparty-0.2.0 → simpleparty-0.2.2}/src/simpleparty.egg-info/dependency_links.txt +0 -0
- {simpleparty-0.2.0 → simpleparty-0.2.2}/src/simpleparty.egg-info/entry_points.txt +0 -0
- {simpleparty-0.2.0 → simpleparty-0.2.2}/src/simpleparty.egg-info/top_level.txt +0 -0
|
@@ -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
|
-
|
|
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
|
-
|
|
668
|
-
|
|
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)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|