conditional time machine
This commit is contained in:
parent
e880b912cb
commit
5326cae9c3
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
@ -14,25 +14,25 @@ sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|||||||
# set time zone
|
# set time zone
|
||||||
_TZ = ZoneInfo("Europe/Berlin")
|
_TZ = ZoneInfo("Europe/Berlin")
|
||||||
# fake date and time
|
# fake date and time
|
||||||
# SOURCE_TIME = [2021, 2, 9, 5, 50, 0]
|
SOURCE_TIME = [2021, 2, 12, 5, 0, 0]
|
||||||
|
USE_TIME_MACHINE = True
|
||||||
|
|
||||||
# warp time by factor
|
# warp time by factor
|
||||||
WARP_FACTOR = 1000
|
WARP_FACTOR = 1000
|
||||||
|
|
||||||
|
|
||||||
# @time_machine.travel(datetime.datetime(*SOURCE_TIME, tzinfo=_TZ))
|
def warp_time():
|
||||||
def playlist_test():
|
|
||||||
get_source = GetSourceFromPlaylist()
|
get_source = GetSourceFromPlaylist()
|
||||||
stamp = time.time()
|
stamp = time.time()
|
||||||
duration = 0
|
duration = 0
|
||||||
|
|
||||||
with time_machine.travel(stamp, tick=False) as traveller:
|
with time_machine.travel(stamp, tick=False) as traveller:
|
||||||
for src_cmd, node in get_source.next():
|
for src_cmd, node in get_source.next():
|
||||||
duration = node['out'] - node['seek']
|
duration = node['out'] - node['seek']
|
||||||
messenger.info(f'Play: "{node["source"]}"')
|
messenger.info(f'Play: "{node["source"]}"')
|
||||||
|
|
||||||
warp_duration = duration / WARP_FACTOR
|
warp_duration = duration / WARP_FACTOR
|
||||||
messenger.debug(f'warp duration: {warp_duration:.3f}')
|
messenger.debug(f'Original duration {duration} '
|
||||||
|
f'warped to {warp_duration:.3f}')
|
||||||
|
|
||||||
time.sleep(warp_duration)
|
time.sleep(warp_duration)
|
||||||
stamp += duration
|
stamp += duration
|
||||||
@ -40,11 +40,23 @@ def playlist_test():
|
|||||||
traveller.move_to(stamp)
|
traveller.move_to(stamp)
|
||||||
|
|
||||||
|
|
||||||
|
@time_machine.travel(datetime.datetime(*SOURCE_TIME, tzinfo=_TZ))
|
||||||
|
def run_in_time_machine():
|
||||||
|
warp_time()
|
||||||
|
|
||||||
|
|
||||||
|
def run_in_time_warp():
|
||||||
|
warp_time()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from ffplayout.playlist import GetSourceFromPlaylist
|
from ffplayout.playlist import GetSourceFromPlaylist
|
||||||
from ffplayout.utils import messenger
|
from ffplayout.utils import messenger
|
||||||
|
|
||||||
try:
|
try:
|
||||||
playlist_test()
|
if USE_TIME_MACHINE:
|
||||||
|
run_in_time_machine()
|
||||||
|
else:
|
||||||
|
warp_time()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print('Interrupted')
|
print('Interrupted')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user