forked from camila314/tap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheasy_run.py
123 lines (97 loc) · 3.69 KB
/
easy_run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import sys
import tkinter as tk
from tkinter import filedialog
import replays
from pathlib import Path
import clicks
from pydub import AudioSegment
from tqdm import tqdm
from distutils.spawn import find_executable
import os
import gd
def promptExit():
input('Press enter to close...')
sys.exit()
os.environ['PATH'] += os.pathsep + str(Path('./ffmpeg/bin').resolve())
CWD = Path.cwd()
print('Tap by Camden314, X position approx. port by mat')
print('This version approximates time via speed portals in the given level')
print('sometimes can be wildly inaccurate.')
try:
root = tk.Tk()
root.withdraw()
if find_executable('ffmpeg') is None:
print('FFmpeg was not found on path, please download it from the link below, and extract it.')
print('https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full.7z')
input('Press enter after you\'ve extracted ffmpeg...')
ffmpeg_folder = filedialog.askdirectory(mustexist=True, title='Open the extracted ffmpeg folder')
if not ffmpeg_folder:
print('why did you press cancel')
promptExit()
ffmpeg_folder = Path(ffmpeg_folder)
for path in ffmpeg_folder.glob('ffmpeg-*'):
ffmpeg_folder = path
break
if not (ffmpeg_folder / 'bin' / 'ffmpeg.exe').exists():
print('No ffmpeg.exe found, make sure you select the folder with the following structure')
print('bin/\ndoc/\npresets/\nLICENSE\nREADME.txt')
promptExit()
ffmpeg_folder.rename(CWD / 'ffmpeg')
if len(sys.argv) < 2:
replay_file = filedialog.askopenfile(title='Open the .zbot macro', filetypes=('zBot {.zbot}',), mode='rb')
if not replay_file:
promptExit()
else:
replay_file = open(sys.argv[1], 'rb')
data = replay_file.read()
replay_file.close()
print('Parsing replay')
replay = replays.parse_zbot(data)
level_id = int(input('Enter level ID: ').strip())
client = gd.Client()
print('Downloading level')
lvl = client.run(client.get_level(level_id))
print('Converting replay')
replays.convert_to_time(replay, lvl)
clicks_path = filedialog.askdirectory(mustexist=True, title='Open the clicks folder')
if not clicks_path:
promptExit()
clicks_path = Path(clicks_path)
print('Loading clicks')
click_sounds = clicks.load_clicks(clicks_path)
if len(click_sounds['hold']) == 0 or len(click_sounds['release']) == 0:
print('''Error loading clicks, make sure your clicks directory follows this structure
clicks
|- holds
| |- 1.wav
| |- 2.wav
| |- s1.wav # these are soft clicks
|
|- releases
| |- 1.wav
| |- 2.wav
''')
promptExit()
print('Generating clicks')
clicks = [clicks.Click(action.time, action.hold, click_sounds) for action in replay.actions]
full_length = clicks[-1].time + 1
output = AudioSegment.silent(duration=full_length * 1000)
last_click = None
last_click_hold = None
for click in tqdm(clicks, desc='Mapping clicks'):
if last_click is None or click.hold != last_click.hold:
click.process(last_click_hold, full_length, click_sounds)
if click.hold: last_click_hold = click
last_click = click
output = output.overlay(click.audio, position=click.time * 1000)
output_file = filedialog.asksaveasfilename(defaultextension='mp3', filetypes=('MP3 {.mp3}',), initialdir='.')
if not output_file:
print(':|')
promptExit()
output.export(output_file)
promptExit()
except:
import traceback
if sys.exc_info()[0] != SystemExit:
traceback.print_exc()
promptExit()