2021-02-10 11:46:49 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-02-11 03:44:58 -05:00
|
|
|
"""
|
|
|
|
Test script, for simulating speed up the clock.
|
|
|
|
With the WARP_FACTOR you can transform a second to a fraction.
|
|
|
|
With this functionality it is possible to run a 24 hours playlist in a minute,
|
|
|
|
and debug the playlist reader.
|
|
|
|
"""
|
|
|
|
|
2021-02-11 03:29:39 -05:00
|
|
|
import datetime
|
2021-02-10 11:46:49 -05:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
2022-01-01 17:08:56 -05:00
|
|
|
from zoneinfo import ZoneInfo
|
2021-02-10 11:46:49 -05:00
|
|
|
|
|
|
|
import time_machine
|
|
|
|
|
|
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
|
|
# set time zone
|
|
|
|
_TZ = ZoneInfo("Europe/Berlin")
|
|
|
|
# fake date and time
|
2021-02-11 03:29:39 -05:00
|
|
|
SOURCE_TIME = [2021, 2, 12, 5, 0, 0]
|
|
|
|
USE_TIME_MACHINE = True
|
2021-02-10 11:46:49 -05:00
|
|
|
|
|
|
|
# warp time by factor
|
|
|
|
WARP_FACTOR = 1000
|
|
|
|
|
|
|
|
|
2021-02-11 03:29:39 -05:00
|
|
|
def warp_time():
|
2022-01-26 06:01:00 -05:00
|
|
|
get_source = GetSourceIter()
|
2021-02-10 11:46:49 -05:00
|
|
|
stamp = time.time()
|
|
|
|
duration = 0
|
|
|
|
with time_machine.travel(stamp, tick=False) as traveller:
|
2021-02-17 02:45:16 -05:00
|
|
|
for node in get_source.next():
|
2021-02-10 11:46:49 -05:00
|
|
|
duration = node['out'] - node['seek']
|
|
|
|
messenger.info(f'Play: "{node["source"]}"')
|
|
|
|
|
|
|
|
warp_duration = duration / WARP_FACTOR
|
2021-02-11 03:29:39 -05:00
|
|
|
messenger.debug(f'Original duration {duration} '
|
|
|
|
f'warped to {warp_duration:.3f}')
|
2021-02-10 11:46:49 -05:00
|
|
|
|
|
|
|
time.sleep(warp_duration)
|
|
|
|
stamp += duration
|
|
|
|
|
|
|
|
traveller.move_to(stamp)
|
|
|
|
|
|
|
|
|
2021-02-11 03:29:39 -05:00
|
|
|
@time_machine.travel(datetime.datetime(*SOURCE_TIME, tzinfo=_TZ))
|
|
|
|
def run_in_time_machine():
|
|
|
|
warp_time()
|
|
|
|
|
|
|
|
|
|
|
|
def run_in_time_warp():
|
|
|
|
warp_time()
|
|
|
|
|
|
|
|
|
2021-02-10 11:46:49 -05:00
|
|
|
if __name__ == '__main__':
|
2022-01-26 06:01:00 -05:00
|
|
|
from ffplayout.player.playlist import GetSourceIter
|
2021-02-10 11:46:49 -05:00
|
|
|
from ffplayout.utils import messenger
|
|
|
|
|
|
|
|
try:
|
2021-02-11 03:29:39 -05:00
|
|
|
if USE_TIME_MACHINE:
|
|
|
|
run_in_time_machine()
|
|
|
|
else:
|
|
|
|
warp_time()
|
2021-02-10 11:46:49 -05:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print('Interrupted')
|