-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.py
More file actions
91 lines (78 loc) · 3.27 KB
/
Copy pathplugin.py
File metadata and controls
91 lines (78 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
Dispatcharr VOD Concurrency Fix
===============================
Coalesces the burst of near-simultaneous HTTP range requests that Emby /
libmpv (and similar MKV direct-play clients) fire when opening a VOD file, so
they share ONE provider connection slot instead of each tripping a
`max_streams: 1` profile and failing over to a different provider account /
different underlying file.
See patch.py for the full design writeup. This module is the Dispatcharr plugin
entry point: it applies the monkeypatch at import time (Dispatcharr imports an
enabled plugin's code in every uWSGI worker at boot) and reverts it in stop().
Author: andyj682
License: MIT
"""
import logging
logger = logging.getLogger("plugins.dispatcharr_vod_concurrency_fix")
# Apply the patch as soon as the module is imported. Dispatcharr only imports an
# enabled plugin's code, and under `lazy-apps = true` every uWSGI worker imports
# it at boot -- so importing == "this worker should be patched".
try:
from . import patch as _patch
except Exception: # pragma: no cover - fall back to flat import layout
import patch as _patch
try:
_patch.install()
except Exception: # never break app startup because of the plugin
logger.exception("[VOD-CC] auto-install on import failed")
class Plugin:
name = "VOD Concurrency Fix"
version = "1.2.0"
description = (
"Coalesces the near-simultaneous range requests "
"from some clients (notably Emby) when playing MKV VOD files so they "
"share one provider slot instead of failing over to a different file "
"and corrupting playback."
)
author = "andyj682"
help_url = "https://github.com/andyj682/dispatcharr_vod_concurrency_fix"
# No user configuration required.
fields = []
# A status button so the user can confirm the patch is live in a worker.
actions = [
{
"id": "status",
"label": "Show patch status",
"description": "Report whether the concurrency patch is active in "
"the worker that handles this request.",
"button_label": "Check status",
"button_variant": "outline",
},
]
def run(self, action=None, params=None, context=None):
context = context or {}
if action == "enable":
ok = _patch.install()
return {
"status": "ok" if ok else "error",
"message": "VOD concurrency patch installed"
if ok else "Failed to install (see logs)",
}
if action == "disable":
_patch.uninstall()
return {"status": "ok", "message": "VOD concurrency patch reverted"}
if action == "status":
import os
return {
"status": "ok",
"message": (
f"active={_patch._ACTIVE} in worker pid={os.getpid()} "
f"(note: this reflects ONE worker; check logs for all "
f"worker pids)"
),
}
return {"status": "error", "message": f"Unknown action: {action}"}
def stop(self, context=None):
"""Called by Dispatcharr on disable / delete / reload."""
_patch.uninstall()
return {"status": "ok", "message": "VOD concurrency patch reverted"}