always test audio because on startup mpv won't immediately work
This commit is contained in:
parent
a5c1a49248
commit
dfdc92a98b
50
main.py
50
main.py
|
@ -38,7 +38,6 @@ def generate_interval(work_time: int, break_time: int):
|
||||||
yield 60 * 25
|
yield 60 * 25
|
||||||
yield 60 * 30
|
yield 60 * 30
|
||||||
|
|
||||||
|
|
||||||
def play_playlist(playlist):
|
def play_playlist(playlist):
|
||||||
"""
|
"""
|
||||||
Play the playlist.
|
Play the playlist.
|
||||||
|
@ -47,6 +46,18 @@ def play_playlist(playlist):
|
||||||
["mpv", "--shuffle", "--no-video", playlist], stdout=DEVNULL, stderr=DEVNULL
|
["mpv", "--shuffle", "--no-video", playlist], stdout=DEVNULL, stderr=DEVNULL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_playlist(playlist, duration=None):
|
||||||
|
print(
|
||||||
|
"testing playlist, press enter to start if you hear the playlist",
|
||||||
|
end="",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
if duration is None:
|
||||||
|
duration = float("inf")
|
||||||
|
play = play_playlist(playlist)
|
||||||
|
focus=bool(WINDOW_TITLE) and duration is None
|
||||||
|
wait_or_enter(duration, i3_focus=focus)
|
||||||
|
play.terminate()
|
||||||
|
|
||||||
def wait_or_enter(duration, i3_focus=False):
|
def wait_or_enter(duration, i3_focus=False):
|
||||||
"""
|
"""
|
||||||
|
@ -80,10 +91,10 @@ def wait_or_enter(duration, i3_focus=False):
|
||||||
if stop:
|
if stop:
|
||||||
return sys.stdin.readline().strip()
|
return sys.stdin.readline().strip()
|
||||||
else:
|
else:
|
||||||
|
print()
|
||||||
tcflush(sys.stdin, TCIOFLUSH)
|
tcflush(sys.stdin, TCIOFLUSH)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def write_break_message(msg):
|
def write_break_message(msg):
|
||||||
today = datetime.now().strftime("%Y-%m-%d")
|
today = datetime.now().strftime("%Y-%m-%d")
|
||||||
minute = datetime.now().strftime("%H:%M")
|
minute = datetime.now().strftime("%H:%M")
|
||||||
|
@ -95,16 +106,6 @@ def write_break_message(msg):
|
||||||
|
|
||||||
def main(playlist, work_time, break_time):
|
def main(playlist, work_time, break_time):
|
||||||
interval = generate_interval(work_time, break_time)
|
interval = generate_interval(work_time, break_time)
|
||||||
|
|
||||||
print(
|
|
||||||
"testing playlist, press enter to start if you hear the playlist",
|
|
||||||
end="",
|
|
||||||
flush=True,
|
|
||||||
)
|
|
||||||
play = play_playlist(playlist)
|
|
||||||
wait_or_enter(float("inf"), i3_focus=True)
|
|
||||||
play.terminate()
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# work
|
# work
|
||||||
i = next(interval)
|
i = next(interval)
|
||||||
|
@ -127,17 +128,8 @@ def main(playlist, work_time, break_time):
|
||||||
|
|
||||||
|
|
||||||
def timer(playlist, duration):
|
def timer(playlist, duration):
|
||||||
print(
|
second = datetime.now().strftime("%H:%M:%S")
|
||||||
"testing playlist, press enter to start if you hear the playlist",
|
print(second, "wait for", duration, "seconds")
|
||||||
end="",
|
|
||||||
flush=True,
|
|
||||||
)
|
|
||||||
play = play_playlist(playlist)
|
|
||||||
wait_or_enter(float("inf"), i3_focus=bool(WINDOW_TITLE))
|
|
||||||
play.terminate()
|
|
||||||
|
|
||||||
# work
|
|
||||||
print("wait for", duration, "seconds")
|
|
||||||
msg = wait_or_enter(duration, i3_focus=bool(WINDOW_TITLE))
|
msg = wait_or_enter(duration, i3_focus=bool(WINDOW_TITLE))
|
||||||
|
|
||||||
# start music to signal the end of a break.
|
# start music to signal the end of a break.
|
||||||
|
@ -147,7 +139,6 @@ def timer(playlist, duration):
|
||||||
wait_or_enter(float("inf"), i3_focus=bool(WINDOW_TITLE))
|
wait_or_enter(float("inf"), i3_focus=bool(WINDOW_TITLE))
|
||||||
play.terminate()
|
play.terminate()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
@ -179,9 +170,20 @@ if __name__ == "__main__":
|
||||||
type=int,
|
type=int,
|
||||||
help="set true for this to be a single timer",
|
help="set true for this to be a single timer",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--test-sound",
|
||||||
|
action="store_true",
|
||||||
|
help="test the sound before starting the timer",
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
WINDOW_TITLE = args.window_title
|
WINDOW_TITLE = args.window_title
|
||||||
|
|
||||||
|
if args.test_sound:
|
||||||
|
test_playlist(args.playlist)
|
||||||
|
else:
|
||||||
|
# For some reason the first time I play the playlist it doesn't work.
|
||||||
|
# This is a workaround.
|
||||||
|
test_playlist(args.playlist, 10)
|
||||||
if args.once:
|
if args.once:
|
||||||
timer(args.playlist, args.once)
|
timer(args.playlist, args.once)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user