Skip to content

Commit c64465c

Browse files
committed
✨ for new api
1 parent 97f962e commit c64465c

3 files changed

Lines changed: 14 additions & 34 deletions

File tree

src/badapple/audio.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import os
2-
from multiprocessing import Process
3-
from typing import Tuple
42

53
from .util import get_info
6-
from .players import realias, playa
7-
from .players import is_player, is_available, get_players, get_availables
4+
from .players import get_names, get_availables, get_available_player, Player
85

96

107
def help_audio() -> None:
11-
players = get_players()
8+
players = get_names()
129
availables = get_availables()
1310
s = 'usage: badapple --audio_player AUDIO_PLAYER [options] ... \n\n'
1411
s += get_info() + '\n\navailable AUDIO_PLAYER:\n'
@@ -21,33 +18,20 @@ def help_audio() -> None:
2118
print(s, end='', flush=True)
2219

2320

24-
def preplaya(
21+
def get_player(
2522
audio: str,
2623
player: str,
2724
video: str = None,
2825
check_player: bool = True
29-
) -> Tuple[str, str]:
26+
) -> None | Player:
3027
if not audio:
3128
if not player:
32-
return '', ''
29+
return None
3330
if video is None:
3431
raise FileNotFoundError(audio)
3532
audio = video
3633

3734
audio = os.path.abspath(audio)
3835
open(audio, 'rb').close()
3936

40-
if not is_player(player):
41-
raise ValueError('%s is not a player' % player)
42-
player = realias(player)
43-
if check_player:
44-
if not is_available(player):
45-
raise ValueError('Player %s is not available' % player)
46-
47-
return audio, player
48-
49-
50-
def p_playa(audio: str, player: str) -> Process:
51-
p = Process(target=playa, args=(audio, player))
52-
p.start()
53-
return p
37+
return get_available_player(player, audio, err=True)

src/badapple/play.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from multiprocessing import Process
55

66
from .util import get_func, Timer, Font
7-
from .audio import preplaya, p_playa
7+
from .audio import get_player
88
from .replay import replay
99

1010

@@ -57,9 +57,7 @@ def play(
5757

5858
video = os.path.abspath(video)
5959
open(video, 'rb').close()
60-
audio, player = preplaya(audio, player, video, check_player=check_player)
61-
if debug:
62-
print(audio, player)
60+
p = get_player(audio, player, video, check_player=check_player)
6361

6462
x = int(x)
6563
y = int(y)
@@ -109,9 +107,9 @@ def play(
109107
timer = Timer(clk)
110108
print('BEGINNING...', flush=True)
111109
timer.slp()
112-
if audio:
113-
p = p_playa(audio, player)
110+
if p:
114111
p_list.append(p)
112+
p.start()
115113
timer.slp(0.1)
116114
if debug:
117115
timer.slp(5)

src/badapple/replay.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from multiprocessing import Process
33

44
from .util import get_func, Timer
5-
from .audio import p_playa, preplaya
5+
from .audio import get_player
66

77

88
def replay(
@@ -13,9 +13,7 @@ def replay(
1313
) -> None:
1414
video = os.path.abspath(video)
1515
open(video, 'r').close()
16-
audio, player = preplaya(audio, player, check_player=check_player)
17-
if debug:
18-
print(audio, player)
16+
p = get_player(audio, player, check_player=check_player)
1917

2018
s = open(video, 'r').read().split('\n\n')
2119
x, y, clk = s[0].split()
@@ -30,9 +28,9 @@ def replay(
3028
timer = Timer(clk)
3129
print('BEGINNING...', flush=True)
3230
timer.slp()
33-
if audio:
34-
p = p_playa(audio, player)
31+
if p:
3532
p_list.append(p)
33+
p.start()
3634
timer.slp(0.01)
3735
if debug:
3836
timer.slp(5)

0 commit comments

Comments
 (0)