mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-22 00:45:10 +00:00
Compare commits
2
Commits
ec792ee10d
...
35dbfa523c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35dbfa523c | ||
|
|
2971a3a7da |
@@ -0,0 +1,39 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core.manifests.dash import DASH
|
||||
|
||||
|
||||
def adaptation_set(scheme: str, value: str) -> ET.Element:
|
||||
return ET.fromstring(f'<AdaptationSet><Accessibility schemeIdUri="{scheme}" value="{value}"/></AdaptationSet>')
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"scheme,value",
|
||||
[
|
||||
# "description" is the value the DASH role scheme defines. Stan writes it, and reading only
|
||||
# "descriptive" left every audio-description track unflagged.
|
||||
("urn:mpeg:dash:role:2011", "description"),
|
||||
("urn:mpeg:dash:role:2011", "descriptive"),
|
||||
("urn:tva:metadata:cs:AudioPurposeCS:2007", "1"),
|
||||
],
|
||||
)
|
||||
def test_descriptive_accessibility_values(scheme: str, value: str) -> None:
|
||||
assert DASH.is_descriptive(adaptation_set(scheme, value)) is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"scheme,value",
|
||||
[
|
||||
("urn:mpeg:dash:role:2011", "main"),
|
||||
("urn:mpeg:dash:role:2011", "caption"),
|
||||
("urn:tva:metadata:cs:AudioPurposeCS:2007", "2"),
|
||||
],
|
||||
)
|
||||
def test_non_descriptive_accessibility_values(scheme: str, value: str) -> None:
|
||||
assert DASH.is_descriptive(adaptation_set(scheme, value)) is False
|
||||
|
||||
|
||||
def test_no_accessibility_element() -> None:
|
||||
assert DASH.is_descriptive(ET.fromstring("<AdaptationSet/>")) is False
|
||||
@@ -23,25 +23,31 @@ def read_payload(path: Path) -> Dict[str, Any]:
|
||||
return json.load(handle)
|
||||
|
||||
|
||||
_replace_lock = threading.Lock()
|
||||
|
||||
|
||||
def write_result(path: Path, payload: Dict[str, Any]) -> None:
|
||||
"""Write the payload with an atomic replace, because the parent polls this file during the write.
|
||||
|
||||
Each call gets its own temp name, so two threads writing this destination cannot replace away
|
||||
the temp file the other is about to move.
|
||||
|
||||
Windows denies the replace while the parent holds the destination open, so retry with a backoff.
|
||||
Windows denies the replace while another thread or the parent holds the destination open. The
|
||||
lock removes the in-process contention; the retry covers the parent process.
|
||||
"""
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
tmp = path.with_name(f"{path.name}.{uuid4().hex}.tmp")
|
||||
try:
|
||||
tmp.write_text(json.dumps(payload), encoding="utf-8")
|
||||
for attempt in range(5):
|
||||
try:
|
||||
os.replace(tmp, path)
|
||||
return
|
||||
except PermissionError:
|
||||
time.sleep(0.02 * (attempt + 1))
|
||||
os.replace(tmp, path)
|
||||
with _replace_lock:
|
||||
for attempt in range(10):
|
||||
try:
|
||||
os.replace(tmp, path)
|
||||
return
|
||||
except PermissionError:
|
||||
if attempt == 9:
|
||||
raise
|
||||
time.sleep(0.02 * (attempt + 1))
|
||||
except OSError:
|
||||
tmp.unlink(missing_ok=True)
|
||||
raise
|
||||
|
||||
@@ -1111,7 +1111,11 @@ class DASH:
|
||||
"""Whether the Adaptation Set is Descriptive."""
|
||||
return any(
|
||||
(x.get("schemeIdUri"), x.get("value"))
|
||||
in (("urn:mpeg:dash:role:2011", "descriptive"), ("urn:tva:metadata:cs:AudioPurposeCS:2007", "1"))
|
||||
in (
|
||||
("urn:mpeg:dash:role:2011", "description"),
|
||||
("urn:mpeg:dash:role:2011", "descriptive"),
|
||||
("urn:tva:metadata:cs:AudioPurposeCS:2007", "1"),
|
||||
)
|
||||
for x in adaptation_set.findall("Accessibility")
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user