Improve Categories for overlay menu
now categories it's folders in "sound" folder
This commit is contained in:
parent
c05f0681bb
commit
e880f5c87a
1 changed files with 37 additions and 35 deletions
72
main.py
72
main.py
|
@ -50,10 +50,6 @@ def found_device(list_): # Поиск микшера VoiceMee
|
||||||
return index
|
return index
|
||||||
|
|
||||||
def sound_get(mode): # Сбор файлов
|
def sound_get(mode): # Сбор файлов
|
||||||
MUSIC = ['Music']
|
|
||||||
MEME = ['Meme']
|
|
||||||
OTHER = ['Other']
|
|
||||||
CATS = [MUSIC, MEME, OTHER]
|
|
||||||
|
|
||||||
if os.path.exists('settings.json') and mode == False:
|
if os.path.exists('settings.json') and mode == False:
|
||||||
sounds_list = jsonread('settings.json')
|
sounds_list = jsonread('settings.json')
|
||||||
|
@ -72,35 +68,40 @@ def sound_get(mode): # Сбор файлов
|
||||||
msg.exec_()
|
msg.exec_()
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
menu = []
|
||||||
|
sounds_list = ['sound\\']
|
||||||
for i in os.listdir('sound'): # Коонвертируем файлы в .wav
|
for i in os.listdir('sound'): # Коонвертируем файлы в .wav
|
||||||
|
print(f'i = {i}')
|
||||||
|
print(os.path.join(os.getcwd(), 'sound', i))
|
||||||
name = i
|
name = i
|
||||||
format_ = ''
|
format_ = ''
|
||||||
while i[-1] != '.':
|
if os.path.isfile(os.path.join('sound', i)):
|
||||||
format_ += i[-1]
|
while i[-1] != '.':
|
||||||
i = i[:-1]
|
format_ += i[-1]
|
||||||
format_ = format_[::-1]
|
i = i[:-1]
|
||||||
if format_ in ['mp3', 'm4a']:
|
format_ = format_[::-1]
|
||||||
os.system(f'ffmpeg.exe -i "sound\\{name}" "sound\\{i}wav"')
|
if format_ in ['mp3', 'm4a']:
|
||||||
os.remove(f'sound\\{name}')
|
os.system(f'ffmpeg.exe -i "sound\\{name}" "sound\\{i}wav"')
|
||||||
|
os.remove(f'sound\\{name}')
|
||||||
sounds = os.listdir('sound')
|
sounds_list.append(name)
|
||||||
for i in sounds: # Ищем ключевые слова в названиях песен
|
|
||||||
tag = ''
|
|
||||||
for x in i:
|
|
||||||
if x not in [' ', '.', '-', '_']:
|
|
||||||
tag += x
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
if tag.lower() == 'music':
|
|
||||||
MUSIC.append(i)
|
|
||||||
elif tag.lower() == 'meme':
|
|
||||||
MEME.append(i)
|
|
||||||
else:
|
else:
|
||||||
OTHER.append(i)
|
sounds_list_cat = [os.path.join('sound', i)]
|
||||||
|
for x in os.listdir(os.path.join('sound', i)): # Коонвертируем файлы в .wav
|
||||||
menu = []
|
print(f'x = {x}')
|
||||||
for i in CATS:
|
print(os.path.join('sound', i, x))
|
||||||
menu.append(i)
|
name = x
|
||||||
|
format_ = ''
|
||||||
|
if os.path.isfile(os.path.join('sound', i, x)):
|
||||||
|
while x[-1] != '.':
|
||||||
|
format_ += x[-1]
|
||||||
|
x = x[:-1]
|
||||||
|
format_ = format_[::-1]
|
||||||
|
if format_ in ['mp3', 'm4a']:
|
||||||
|
os.system(f'ffmpeg.exe -i "sound\\{os.path.join(i, name)}" "sound\\{os.path.join(i, x)}wav"')
|
||||||
|
os.remove(f'sound\\{os.path.join(i, name)}')
|
||||||
|
sounds_list_cat.append(name)
|
||||||
|
menu.append(sounds_list_cat)
|
||||||
|
menu.append(sounds_list)
|
||||||
|
|
||||||
if os.path.exists('settings.json'):
|
if os.path.exists('settings.json'):
|
||||||
hotkeys = jsonread('settings.json')[1]
|
hotkeys = jsonread('settings.json')[1]
|
||||||
|
@ -126,12 +127,14 @@ def save(): # Сохранение списка
|
||||||
hotkeys = None
|
hotkeys = None
|
||||||
|
|
||||||
def play_sound(index): # Проигрываение звука
|
def play_sound(index): # Проигрываение звука
|
||||||
|
print(select[0], select[1])
|
||||||
try:
|
try:
|
||||||
filename = COMBOS[index].currentText()
|
filename = COMBOS[index].currentText()
|
||||||
except:
|
except:
|
||||||
filename = index
|
filename = menu[select[0]][select[1]]
|
||||||
|
print(filename)
|
||||||
try:
|
try:
|
||||||
data, fs = sf.read(os.path.join('sound', filename), dtype='float32')
|
data, fs = sf.read(os.path.join(menu[select[0]][0], filename), dtype='float32')
|
||||||
sd.play(data, fs)
|
sd.play(data, fs)
|
||||||
keyboard.wait(sd.play())
|
keyboard.wait(sd.play())
|
||||||
sd.wait()
|
sd.wait()
|
||||||
|
@ -142,8 +145,6 @@ def play_sound(index): # Проигрываение зву
|
||||||
###! CONTROL !###
|
###! CONTROL !###
|
||||||
def key(arg): # Хоткеи
|
def key(arg): # Хоткеи
|
||||||
|
|
||||||
select = [0, 0]
|
|
||||||
|
|
||||||
def select_move(mode):
|
def select_move(mode):
|
||||||
select[1] += mode[1]
|
select[1] += mode[1]
|
||||||
select[0] += mode[0]
|
select[0] += mode[0]
|
||||||
|
@ -151,7 +152,7 @@ def key(arg): # Хоткеи
|
||||||
select[0] = 0
|
select[0] = 0
|
||||||
if select[1] > len(menu[select[0]])-1 or select[1] < -len(menu[select[0]])+1:
|
if select[1] > len(menu[select[0]])-1 or select[1] < -len(menu[select[0]])+1:
|
||||||
select[1] = 0
|
select[1] = 0
|
||||||
if mode[0] > 0:
|
if mode[0] != 0:
|
||||||
select[1] = 0
|
select[1] = 0
|
||||||
over.label.setText(menu[select[0]][select[1]])
|
over.label.setText(menu[select[0]][select[1]])
|
||||||
win.select_label.setText(menu[select[0]][select[1]])
|
win.select_label.setText(menu[select[0]][select[1]])
|
||||||
|
@ -172,7 +173,7 @@ def key(arg): # Хоткеи
|
||||||
keyboard.add_hotkey(80, select_move, args=[[0, 1]])
|
keyboard.add_hotkey(80, select_move, args=[[0, 1]])
|
||||||
keyboard.add_hotkey(77, select_move, args=[[1, 0]])
|
keyboard.add_hotkey(77, select_move, args=[[1, 0]])
|
||||||
keyboard.add_hotkey(75, select_move, args=[[-1, 0]])
|
keyboard.add_hotkey(75, select_move, args=[[-1, 0]])
|
||||||
keyboard.add_hotkey(76, play_sound, args=[menu[select[0]][select[1]]])
|
keyboard.add_hotkey(76, play_sound, args=[''])
|
||||||
keyboard.add_hotkey(73, sd.stop)
|
keyboard.add_hotkey(73, sd.stop)
|
||||||
|
|
||||||
def main(): # Интерфейс
|
def main(): # Интерфейс
|
||||||
|
@ -201,6 +202,7 @@ if __name__ == '__main__':
|
||||||
win = MainUi()
|
win = MainUi()
|
||||||
win.show()
|
win.show()
|
||||||
|
|
||||||
|
select = [0, 0]
|
||||||
COMBOS = [
|
COMBOS = [
|
||||||
win.combo0,
|
win.combo0,
|
||||||
win.combo1,
|
win.combo1,
|
||||||
|
|
Loading…
Add table
Reference in a new issue