mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix media:duration only for last SMIL file
Also fix serialization of clip timestamps incorrectly leading to negative durations.
This commit is contained in:
parent
05e589e510
commit
4474a89590
@ -14,6 +14,7 @@ import uuid
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from itertools import count
|
from itertools import count
|
||||||
|
from math import floor
|
||||||
|
|
||||||
from css_parser import getUrls, replaceUrls
|
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:
|
def seconds_to_timestamp(duration: float) -> str:
|
||||||
seconds = int(duration)
|
seconds = int(floor(duration))
|
||||||
float_part = int((duration - seconds) * 1000)
|
float_part = int((duration - seconds) * 1000)
|
||||||
hours = seconds // 3600
|
hours = seconds // 3600
|
||||||
minutes = (seconds % 3600) // 60
|
minutes = (seconds % 3600) // 60
|
||||||
seconds = seconds % 60
|
seconds = seconds % 60
|
||||||
ans = f'{hours:02d}:{minutes:02d}:{seconds:02d}'
|
ans = f'{hours:02d}:{minutes:02d}:{seconds:02d}'
|
||||||
if float_part:
|
if float_part:
|
||||||
ans += f'.{float_part}'
|
ans += f'.{float_part}'.rstrip('0')
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
@ -502,8 +502,8 @@ def embed_tts(container, report_progress=None, callback_to_download_voices=None)
|
|||||||
snum = 0
|
snum = 0
|
||||||
size_of_audio_data = 0
|
size_of_audio_data = 0
|
||||||
mmap = {container.href_to_name(item.get('href'), container.opf_name):item for item in container.manifest_items}
|
mmap = {container.href_to_name(item.get('href'), container.opf_name):item for item in container.manifest_items}
|
||||||
|
duration_map = {}
|
||||||
for name, pfd in name_map.items():
|
for name, pfd in name_map.items():
|
||||||
duration_map = {}
|
|
||||||
audio_map: dict[Sentence, tuple[bytes, float]] = {}
|
audio_map: dict[Sentence, tuple[bytes, float]] = {}
|
||||||
for (lang, voice), sentences in pfd.key_map.items():
|
for (lang, voice), sentences in pfd.key_map.items():
|
||||||
texts = tuple(s.text for s in sentences)
|
texts = tuple(s.text for s in sentences)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user