initial commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
from evanescere.schemas import ClipCandidate
|
||||
from evanescere.services.llm import dedupe_and_rank_candidates, parse_clip_response
|
||||
|
||||
|
||||
def test_parse_clip_response():
|
||||
candidates = parse_clip_response(
|
||||
"""
|
||||
{
|
||||
"clips": [
|
||||
{
|
||||
"start_sec": 10,
|
||||
"end_sec": 60,
|
||||
"title_zh": "标题",
|
||||
"summary_zh": "摘要",
|
||||
"reason": "有趣",
|
||||
"score": 0.9,
|
||||
"tags": ["反应"],
|
||||
"subtitle_priority": "high"
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
)
|
||||
assert candidates[0].title_zh == "标题"
|
||||
|
||||
|
||||
def test_dedupe_and_rank_candidates_filters_short_and_overlapping():
|
||||
candidates = [
|
||||
ClipCandidate(
|
||||
start_sec=0,
|
||||
end_sec=20,
|
||||
title_zh="too short",
|
||||
summary_zh="",
|
||||
reason="",
|
||||
score=1,
|
||||
),
|
||||
ClipCandidate(
|
||||
start_sec=0,
|
||||
end_sec=60,
|
||||
title_zh="best",
|
||||
summary_zh="",
|
||||
reason="",
|
||||
score=0.9,
|
||||
),
|
||||
ClipCandidate(
|
||||
start_sec=10,
|
||||
end_sec=65,
|
||||
title_zh="overlap",
|
||||
summary_zh="",
|
||||
reason="",
|
||||
score=0.8,
|
||||
),
|
||||
ClipCandidate(
|
||||
start_sec=120,
|
||||
end_sec=180,
|
||||
title_zh="second",
|
||||
summary_zh="",
|
||||
reason="",
|
||||
score=0.7,
|
||||
),
|
||||
]
|
||||
ranked = dedupe_and_rank_candidates(candidates)
|
||||
assert [candidate.title_zh for candidate in ranked] == ["best", "second"]
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
from evanescere.services.subtitles import format_ass_time, format_srt_time
|
||||
|
||||
|
||||
def test_format_srt_time():
|
||||
assert format_srt_time(3661.234) == "01:01:01,234"
|
||||
|
||||
|
||||
def test_format_ass_time():
|
||||
assert format_ass_time(3661.23) == "1:01:01.23"
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
from evanescere.services.webdav import WebDavFile, has_stable_size, parse_propfind_response
|
||||
|
||||
|
||||
class DummyVideo:
|
||||
def __init__(self, samples):
|
||||
self.size_samples = samples
|
||||
|
||||
|
||||
def test_has_stable_size_requires_two_equal_positive_samples():
|
||||
assert not has_stable_size(DummyVideo([]))
|
||||
assert not has_stable_size(DummyVideo([{"size_bytes": 100}]))
|
||||
assert not has_stable_size(DummyVideo([{"size_bytes": 100}, {"size_bytes": 101}]))
|
||||
assert has_stable_size(DummyVideo([{"size_bytes": 100}, {"size_bytes": 100}]))
|
||||
|
||||
|
||||
def test_parse_propfind_response_filters_video_files():
|
||||
xml = """<?xml version="1.0"?>
|
||||
<D:multistatus xmlns:D="DAV:">
|
||||
<D:response>
|
||||
<D:href>/webdav/recordings/</D:href>
|
||||
<D:propstat><D:prop><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat>
|
||||
</D:response>
|
||||
<D:response>
|
||||
<D:href>/webdav/recordings/stream.flv</D:href>
|
||||
<D:propstat><D:prop><D:getcontentlength>123</D:getcontentlength></D:prop></D:propstat>
|
||||
</D:response>
|
||||
<D:response>
|
||||
<D:href>/webdav/recordings/readme.txt</D:href>
|
||||
<D:propstat><D:prop><D:getcontentlength>12</D:getcontentlength></D:prop></D:propstat>
|
||||
</D:response>
|
||||
</D:multistatus>"""
|
||||
assert parse_propfind_response(xml, "https://host/webdav/recordings") == [
|
||||
WebDavFile("https://host/webdav/recordings/stream.flv", "stream.flv", 123, None)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user