-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinput_handle.py
More file actions
152 lines (128 loc) · 4.44 KB
/
input_handle.py
File metadata and controls
152 lines (128 loc) · 4.44 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import os
import os.path
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
import sys
import getopt
import json
import configparser
from pygame import mixer
import pygame
import pygame._sdl2.audio as sdl2_audio
from typing import Tuple
import datetime
cfg = configparser.ConfigParser()
def convertTime(seconds):
hours = seconds // 3600
seconds %= 3600
mins = seconds // 60
seconds %= 60
if len(str(hours)) == 1:
hours = "0"+str(hours)
if len(str(mins)) == 1:
mins = "0"+str(mins)
if len(str(seconds)) == 1:
seconds = "0"+str(seconds)
return hours, mins, seconds
def add_time(h, m, s):
now = datetime.datetime.now()
new_time = now + datetime.timedelta(hours=int(h), minutes=int(m), seconds=int(s))
return new_time.strftime("%H:%M:%S")
def check_cfg_exists():
if os.path.isfile('./config.cfg'):
return True
else:
return False
def cfg_create():
with open('config.cfg', 'w') as cfg_file:
cfg['AUDIO DEVICES'] = {'speaker_output': ''}
cfg.write(cfg_file)
def cfg_write(variable_name, value):
with open('config.cfg', 'w') as cfg_file:
cfg['AUDIO DEVICES'][variable_name] = value
cfg.write(cfg_file)
def cfg_read(variable_name):
try:
cfg.read('config.cfg')
return cfg['AUDIO DEVICES'][variable_name]
except:
print("Failed to load config file, falling back")
return select_speaker_output()
def get_devices(capture_devices: bool = False) -> Tuple[str, ...]:
init_by_me = not pygame.mixer.get_init()
if init_by_me:
pygame.mixer.init()
devices = tuple(sdl2_audio.get_audio_device_names(capture_devices))
if init_by_me:
pygame.mixer.quit()
return devices
def select_speaker_output():
if not check_cfg_exists():
cfg_create()
print("--- SPEAKER OUTPUT ---")
speakerDevices = list(get_devices())
# print(speakerDevices)
for i in speakerDevices:
if ("AUX" or "Stereo Mix") in i:
print("\nUsing " + i)
valid = input("Is this correct (y/n)? ")
if valid.lower() == "y":
return speakerDevices[speakerDevices.index(i)]
print("\nCould not find VB Audio AUX")
loop_count = 0
print("\nAudio Options: ")
for i in speakerDevices:
print(str(loop_count) + ".", i)
loop_count += 1
print("\nIf VB Audio is not found here, please check it is not disabled.")
speaker_choice = input("\nPlease select the VB Audio speaker input: ")
cfg_write("speaker_output", speakerDevices[int(speaker_choice)])
return speakerDevices[int(speaker_choice)]
return None
def song_select():
import easygui
selected_file=easygui.fileopenbox()
print(selected_file)
return selected_file
# function need upgrade for video file support
def arguments(argv):
inputfile = ''
outputfile = ''
reset = 0
# parse arguments
try:
opts, args = getopt.getopt(argv, "hi:o:", ["ifile=", "ofile="])
except getopt.GetoptError as err:
print ('rtx-core.py -i <file input path> -o <file name for output>')
print (str(err))
sys.exit(2)
# set variables from arguments if present else set to default values or help message
for opt, arg in opts:
if opt == '-h':
print ('rtx-core.py -i <file input path> -o <file name for output>')
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
# after parsing arguments, check if inputfile is set, if not, exit
if outputfile == '':
outputfile = add_suffix_to_stem(inputfile, "rtx")
outputfile = change_file_extension(outputfile, "wav")
if inputfile == '':
print("\n--- Input file missing ---\n")
print ('rtx-core.py -i <file input path> -o <file name for output>')
sys.exit(2)
return inputfile,outputfile
# small function for file name/path manipulation
def add_suffix_to_stem(file_path, suffix):
base_path, ext = os.path.splitext(file_path)
return base_path + "_" + suffix + ext
def change_file_extension(file_path, new_extension):
base_path, ext = os.path.splitext(file_path)
return base_path + "." + new_extension
def get_file_extension(file_path):
base_path, ext = os.path.splitext(file_path)
return ext
def get_file_name(file_path):
base_path, ext = os.path.splitext(file_path)
return os.path.basename(base_path)