Skip to content

Commit c86e7a7

Browse files
committed
3.04
1 parent b48e669 commit c86e7a7

4 files changed

Lines changed: 61 additions & 68 deletions

File tree

main.py renamed to ReaperScript.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Команду ниже нужно ввести один раз в консоли с включенным Reaper.
22
# python -c "import reapy; reapy.configure_reaper()"
3-
# pyinstaller --noconfirm --onefile --noconsole --hidden-import=asstosrt --add-data 'background.png;.' main.py
3+
# pyinstaller --noconfirm --onefile --noconsole --hidden-import=asstosrt --add-data 'background.png;.' ReaperScript.py
44
from file_works import (
55
file_works,
6-
reaper_check,
76
path_choice,
87
get_fx_chains,
98
get_path_to_files
@@ -28,7 +27,6 @@
2827
)
2928
import multiprocessing as mp
3029
import tkinter.messagebox
31-
import subprocess
3230
import pysubs2
3331
import tkinter
3432
import ffmpeg
@@ -298,6 +296,7 @@ def fix_check(project: reapy.Project, subs: List[str]) -> None:
298296
if s not in checked_subs:
299297
project.add_marker(s[0], 'FIX', (255, 0, 255))
300298
for s in dbbl_sbs:
299+
lenght = dbbl_sbs[s][1] - dbbl_sbs[s][0]
301300
for i in items_list:
302301
middle = i[0] + ((i[1] - i[0]) / 2)
303302
if i[0] >= dbbl_sbs[s][0] and i[1] <= dbbl_sbs[s][1]:
@@ -309,19 +308,27 @@ def fix_check(project: reapy.Project, subs: List[str]) -> None:
309308
):
310309
if dbbl_sbs[s][0] < middle < dbbl_sbs[s][1]:
311310
dbbl_sbs[s][2] += 1
311+
elif i[1] - dbbl_sbs[s][0] >= lenght / 3.3:
312+
dbbl_sbs[s][2] += 1
312313
elif i[0] > dbbl_sbs[s][0] and (
313314
i[0] < dbbl_sbs[s][1] and i[1] > dbbl_sbs[s][1]
314315
):
315316
if dbbl_sbs[s][0] < middle < dbbl_sbs[s][1]:
316317
dbbl_sbs[s][2] += 1
318+
elif dbbl_sbs[s][1] - i[0] >= lenght / 3.3:
319+
dbbl_sbs[s][2] += 1
317320
for s in dbbl_sbs:
318321
if dbbl_sbs[s][2] < 2:
319322
project.add_marker(dbbl_sbs[s][0], 'DUBBLE HERE', (255, 255, 0))
320323

321324

322-
def project_save(folder: str, title: str, number: str) -> str:
325+
def project_save(
326+
folder: str,
327+
title: str,
328+
number: str,
329+
project_path: str
330+
) -> str:
323331
"""Функция для сохранения проекта"""
324-
project_path = load_path('project_path')
325332
new_path = f'{folder}/{title} {number}.rpp'
326333
copy = ''
327334
while os.path.exists(new_path):
@@ -402,18 +409,20 @@ def reaper_main(
402409
) -> None:
403410
"""Основная функция"""
404411
save_options(checkboxes)
405-
reaper_check()
412+
project_path = load_path('project_path')
413+
if not project_path:
414+
path_choice('project_path')
415+
project_path = load_path('project_path')
406416
folder = path_choice('folder')
407417
if folder:
408418
buttons_freeze(master, BUTTONS)
409419
subs, audio, video, title, number, ext = file_works(folder)
410420
if audio and video:
411421
master.iconify()
412-
new_path = project_save(folder, title, number)
413-
reaper_path = load_path('reaper_path')
422+
new_path = project_save(folder, title, number, project_path)
414423
hwnd = win32gui.FindWindow('REAPERwnd', None)
415424
win32gui.ShowWindow(hwnd, 2)
416-
subprocess.run([reaper_path, new_path])
425+
reapy.open_project(new_path, in_new_tab=True)
417426
project = reapy.Project()
418427
audio_select(audio)
419428
RPR.InsertMedia(video[0], 512 | 0)
@@ -482,9 +491,7 @@ def resource_path(path):
482491
master.resizable(width=False, height=False)
483492
width = master.winfo_screenwidth()
484493
height = master.winfo_screenheight()
485-
x = (width - 380) // 2
486-
y = (height - 390) // 2
487-
master.title('Выберите нужные опции')
494+
master.title('REAPERSCRIPT')
488495
img = Image.open(resource_path('background.png'))
489496
tk_img = ImageTk.PhotoImage(img)
490497
background_label = tkinter.Label(master, image=tk_img)
@@ -498,6 +505,7 @@ def resource_path(path):
498505
'volume_up_dubbers',
499506
'sub_item',
500507
'sub_region',
508+
'subs_cleaner',
501509
'fix_check',
502510
'render_audio',
503511
'render_video',
@@ -527,35 +535,19 @@ def resource_path(path):
527535
checkboxes[option] = var
528536
BUTTONS = [
529537
'start',
530-
'reaper_exe',
531538
'template',
532539
'rfx',
533540
'fix_check',
534541
]
535542
start_bttn = tkinter.Button(
536543
master,
537-
text='Запуск',
544+
text='START',
538545
name='start',
539546
background='#9b93b3',
540547
activebackground='#9b93b3',
541548
command=lambda: on_save_click(checkboxes, master, BUTTONS)
542549
)
543550
start_bttn.place(relx=0.5, rely=1.0, anchor="s", y=-9)
544-
reaper_exe = tkinter.Button(
545-
master,
546-
text='REAPER',
547-
name='reaper_exe',
548-
background='#9b93b3',
549-
activebackground='#9b93b3',
550-
command=lambda: path_choice('reaper_path')
551-
)
552-
reaper_exe.grid(
553-
row=(len(OPTIONS) + 1),
554-
column=0,
555-
sticky=tkinter.W,
556-
padx=6,
557-
pady=3
558-
)
559551
template = tkinter.Button(
560552
master,
561553
text='TEMPLATE',
@@ -597,10 +589,10 @@ def resource_path(path):
597589
fix_check_button.place(relx=0.5, rely=1.0, anchor="s", x=150, y=-7)
598590
version = tkinter.Label(
599591
master,
600-
text='Версия 3.0',
592+
text='Version 3.04',
601593
background='#9b93b3',
602594
)
603-
version.place(relx=0.5, rely=1.0, anchor="s", x=150, y=-378)
595+
version.place(relx=0.5, rely=1.0, anchor="s", x=150, y=-382)
604596

605597
# Чтобы Reaper API подгрузился, Reaper должен быть включен при запуске скрипта
606598
if __name__ == '__main__':

background.png

34 KB
Loading

check_standalone.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def fix_checker(master: tkinter.Tk, BUTTONS: List):
100100
if s not in checked_subs:
101101
project.add_marker(s[0], 'FIX', (255, 0, 255))
102102
for s in dbbl_sbs:
103+
lenght = dbbl_sbs[s][1] - dbbl_sbs[s][0]
103104
for i in items_list:
104105
middle = i[0] + ((i[1] - i[0]) / 2)
105106
if i[0] >= dbbl_sbs[s][0] and i[1] <= dbbl_sbs[s][1]:
@@ -111,11 +112,15 @@ def fix_checker(master: tkinter.Tk, BUTTONS: List):
111112
):
112113
if dbbl_sbs[s][0] < middle < dbbl_sbs[s][1]:
113114
dbbl_sbs[s][2] += 1
115+
elif i[1] - dbbl_sbs[s][0] >= lenght / 3.3:
116+
dbbl_sbs[s][2] += 1
114117
elif i[0] > dbbl_sbs[s][0] and (
115118
i[0] < dbbl_sbs[s][1] and i[1] > dbbl_sbs[s][1]
116119
):
117120
if dbbl_sbs[s][0] < middle < dbbl_sbs[s][1]:
118121
dbbl_sbs[s][2] += 1
122+
elif dbbl_sbs[s][1] - i[0] >= lenght / 3.3:
123+
dbbl_sbs[s][2] += 1
119124
for s in dbbl_sbs:
120125
if dbbl_sbs[s][2] < 2:
121126
project.add_marker(dbbl_sbs[s][0], 'DUBBLE HERE', (255, 255, 0))

file_works.py

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from config_works import (
1313
load_path,
1414
save_path,
15+
get_option,
1516
)
1617

1718
MANY_VIDEO = 'Оставьте в рабочей папке только нужный видеофайл'
@@ -80,16 +81,6 @@ def path_choice(name: str) -> str or None:
8081
return path
8182

8283

83-
def reaper_check() -> None:
84-
"""Функция для создания путей к компонентам REAPER"""
85-
reaper_path = load_path('reaper_path')
86-
if not reaper_path:
87-
path_choice('reaper_path')
88-
project_path = load_path('project_path')
89-
if not project_path:
90-
path_choice('project_path')
91-
92-
9384
def subs_rename(
9485
folder: str,
9586
subs: List[str],
@@ -185,16 +176,15 @@ def audio_rename(folder: str, audio: List[str], ext: str) -> List[str] or None:
185176
def comparator(sub: str) -> bool:
186177
"""Функция для проверки субтитра"""
187178
if (
188-
(
189-
'text' in sub
190-
or 'sign' in sub
191-
or 'надпись' in sub
192-
or 'caption' in sub
193-
or 'title' in sub
194-
or 'song' in sub
195-
or 'screen' in sub
196-
or 'typedigital' in sub
197-
) and 'subtitle' not in sub
179+
'text' in sub
180+
or 'sign' in sub
181+
or 'надпись' in sub
182+
or 'caption' in sub
183+
or 'title' in sub
184+
or 'song' in sub
185+
or 'screen' in sub
186+
or 'typedigital' in sub
187+
or 'phonetics' in sub
198188
):
199189
return True
200190
return False
@@ -219,23 +209,18 @@ def subs_edit(subs: List[str], flag: str) -> None:
219209
elif flag == 'ass':
220210
to_delete = []
221211
search_char = '{'
222-
if subtitles.events[0].name and subtitles.events[0].style:
223-
for i, sub in enumerate(subtitles.events):
224-
if (
225-
comparator(sub.name.lower())
226-
or comparator(sub.style.lower())
227-
) and search_char in sub.text:
228-
to_delete.append(i)
229-
elif subtitles.events[0].name:
212+
if subtitles.events[0].name:
230213
for i, sub in enumerate(subtitles.events):
231214
if comparator(sub.name.lower()) and search_char in sub.text:
232215
to_delete.append(i)
233-
elif subtitles.events[0].style:
216+
if subtitles.events[0].style:
234217
for i, sub in enumerate(subtitles.events):
235218
if comparator(sub.style.lower()) and search_char in sub.text:
236-
to_delete.append(i)
219+
if i not in to_delete:
220+
to_delete.append(i)
237221
else:
238222
return
223+
to_delete.sort()
239224
for i in reversed(to_delete):
240225
del subtitles[i]
241226
subtitles.save(subs[0])
@@ -281,8 +266,12 @@ def file_works(folder: str) -> (
281266
return None, None, None, None, None, None
282267
if subs:
283268
subs = subs_rename(folder, subs, number)
284-
subs_edit(subs, 'srt')
269+
if get_option('subs_cleaner'):
270+
subs_edit(subs, 'srt')
285271
else:
272+
rus_sub = '0:s:m:language:rus'
273+
eng_sub = '0:s:m:language:eng'
274+
any_sub = '0:s:m:language:?'
286275
ass_subs = get_path_to_files(folder, '*.ass')
287276
vtt_subs = get_path_to_files(folder, '*.vtt')
288277
if (ass_subs and vtt_subs) or len(ass_subs) > 1 or len(vtt_subs) > 1:
@@ -291,29 +280,36 @@ def file_works(folder: str) -> (
291280
if vtt_subs:
292281
vtt_sub_convert(folder, vtt_subs)
293282
elif ass_subs:
294-
subs_edit(ass_subs, 'ass')
283+
if get_option('subs_cleaner'):
284+
subs_edit(ass_subs, 'ass')
295285
ass_sub_convert(folder, ass_subs)
296286
elif not ass_subs:
297287
if os.path.splitext(video[0])[-1] == '.mkv':
298-
subs_extract(folder, video, 'ass', '0:s:m:language:eng')
288+
subs_extract(folder, video, 'ass', rus_sub)
299289
ass_subs = get_path_to_files(folder, '*.ass')
300290
if not ass_subs:
301-
subs_extract(folder, video, 'ass', '0:s:m:language:?')
291+
subs_extract(folder, video, 'ass', eng_sub)
292+
ass_subs = get_path_to_files(folder, '*.ass')
293+
if not ass_subs:
294+
subs_extract(folder, video, 'ass', any_sub)
302295
ass_subs = get_path_to_files(folder, '*.ass')
303296
if ass_subs:
304-
subs_edit(ass_subs, 'ass')
297+
if get_option('subs_cleaner'):
298+
subs_edit(ass_subs, 'ass')
305299
ass_sub_convert(folder, ass_subs)
306300
srt_subs = get_path_to_files(folder, '*.srt')
307301
if srt_subs:
308302
subs = subs_rename(folder, srt_subs, number)
309-
subs_edit(subs, 'srt')
303+
if get_option('subs_cleaner'):
304+
subs_edit(subs, 'srt')
310305
else:
311306
try:
312307
if os.path.splitext(video[0])[-1] == '.mkv':
313308
subs_extract(folder, video, 'srt', '0:s:m:language:?')
314309
subs = get_path_to_files(folder, '*.srt')
315310
subs = subs_rename(folder, subs, number)
316-
subs_edit(subs, 'srt')
311+
if get_option('subs_cleaner'):
312+
subs_edit(subs, 'srt')
317313
except IndexError:
318314
pass
319315
return subs, audio, video, title, number, ext

0 commit comments

Comments
 (0)