Fix media:duration only for last SMIL file

Also fix serialization of clip timestamps incorrectly leading to
negative durations.
This commit is contained in:
Kovid Goyal 2024-11-01 19:05:30 +05:30
parent 05e589e510
commit 4474a89590
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 4 additions and 3 deletions

View File

@ -14,6 +14,7 @@ import uuid
from collections import defaultdict
from io import BytesIO
from itertools import count
from math import floor
from css_parser import getUrls, replaceUrls
@ -129,14 +130,14 @@ def href_to_name(href, root, base=None):
def seconds_to_timestamp(duration: float) -> str:
seconds = int(duration)
seconds = int(floor(duration))
float_part = int((duration - seconds) * 1000)
hours = seconds // 3600
minutes = (seconds % 3600) // 60
seconds = seconds % 60
ans = f'{hours:02d}:{minutes:02d}:{seconds:02d}'
if float_part:
ans += f'.{float_part}'
ans += f'.{float_part}'.rstrip('0')
return ans

View File

@ -502,8 +502,8 @@ def embed_tts(container, report_progress=None, callback_to_download_voices=None)
snum = 0
size_of_audio_data = 0
mmap = {container.href_to_name(item.get('href'), container.opf_name):item for item in container.manifest_items}
for name, pfd in name_map.items():
duration_map = {}
for name, pfd in name_map.items():
audio_map: dict[Sentence, tuple[bytes, float]] = {}
for (lang, voice), sentences in pfd.key_map.items():
texts = tuple(s.text for s in sentences)