Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import shutil
- import subprocess
- from pynput import keyboard as keyboard2
- from pywinauto.application import Application
- from pywinauto import keyboard
- from time import sleep
- skipsplit = ['Arthur.S11E19.Big.Brother.Binky.Parts.1.and.2.WEB-DL.AAC2.0.H.264-BTN.mkv']
- subskip = []
- path = 'D:\\Arthur.S11.WEB-DL.AAC2.0.H.264-BTN\\Arthur.S11.WEB-DL.AAC2.0.H.264-BTN'
- outdir = 'D:\\Arthur\\Season 11\\'
- s = 11
- e = 1
- root = Application(backend='win32')
- # Set up event for pressing a key
- def on_release(key):
- if key == keyboard2.Key.pause: # If the pause key is pressed
- return False # Stop the pynput listener
- else:
- return True
- def split(where:str, fn:str):
- if where == 'first': # >[
- vrdapp.VideoReDoClass6.Button2.set_focus()
- vrdapp.VideoReDoClass6.Button2.click()
- elif where == 'second': # ]<
- vrdapp.VideoReDoClass6.Button1.set_focus()
- vrdapp.VideoReDoClass6.Button1.click()
- vrdapp.VideoReDoClass6.TrimUnselected.set_focus()
- vrdapp.VideoReDoClass6.TrimUnselected.click()
- vrdapp.VideoReDoClass6.SaveVideo.set_focus()
- vrdapp.VideoReDoClass6.SaveVideo.click()
- vrdapp.SaveVideo.wait('visible', timeout=20)
- vrdapp.SaveVideo.Edit.set_focus()
- vrdapp.SaveVideo.Edit.set_edit_text(fn)
- vrdapp.SaveVideo.Save.wait('ready', timeout=20)
- vrdapp.SaveVideo.Save.set_focus()
- vrdapp.SaveVideo.Save.click()
- # Wait for completion window to exist then close it
- vrdapp.OutputProcessingComplete.wait('exists', timeout=240)
- vrdapp.OutputProcessingComplete.OK.set_focus()
- vrdapp.OutputProcessingComplete.OK.click()
- vrdapp.VideoReDoClass6.wait('visible', timeout=20)
- # Extract subtitles from source material
- # VideoReDo doesn't handle subs, I have to do so manually
- for file in os.listdir(path):
- if file.endswith('.mkv') and file not in skipsplit:
- fullpath = os.path.join(path, file)
- try:
- print(subprocess.check_output(['C:\\Users\\samicrusader\\Downloads\\ffmpeg-shared-06e8eed-9b0e37c-win64-nonfree\\ffmpeg.exe', '-i', fullpath, '-map', '0:s', '-c:s', 'copy', os.path.join(outdir, file.replace('.mkv', '.srt'))]))
- except:
- subskip.append(file)
- # Start VideoReDo
- for file in os.listdir(path):
- fullpath = os.path.join(path, file)
- if file.endswith('.mkv') and file not in skipsplit:
- vrdapp = root.start('C:\\Program Files (x86)\\VideoReDoPro6\\VideoReDoPro6.exe')
- vrdapp.VideoReDoProfessional.wait('ready', timeout=20)
- # Open video file in VideoReDo
- vrdapp.VideoReDoProfessional['Open\nVideo'].click()
- vrdapp.Open.wait('visible', timeout=20)
- vrdapp.Open.FileNameEdit.set_focus()
- vrdapp.Open.FileNameEdit.set_edit_text(fullpath)
- vrdapp.Open.Open.wait('ready', timeout=20)
- vrdapp.Open.Open.set_focus()
- vrdapp.Open.Open.click()
- # Set up keyboard listener
- with keyboard2.Listener(on_release=on_release) as listener:
- listener.join() # This hangs until on_release returns False (e.g. when the Pause/SysRq key is pressed)
- # Split
- split('first', os.path.join(outdir, f'Arthur - S{s:>02}E{e:>02}_src.mkv'))
- e += 1
- split('second', os.path.join(outdir, f'Arthur - S{s:>02}E{e:>02}_src.mkv'))
- e += 1
- sleep(3)
- vrdapp.VideoReDoClass6.menu_select("File -> Exit")
- else: # some videos that dont need to be split
- shutil.copy(fullpath, os.path.join(outdir, f'Arthur - S{s:>02}E{e:>02}_src.mkv'))
- e += 1
- e = 1
- # Start Subtitle Edit
- seapp = root.start('C:\\Program Files\\Subtitle Edit\\SubtitleEdit.exe')
- # Split subtitles
- for file in os.listdir(path):
- if file.endswith('.mkv'):
- fullpath = os.path.join(outdir, file.replace('.mkv', '.srt'))
- if file not in skipsplit and file in subskip:
- e += 2
- elif file in skipsplit:
- #shutil.copy(fullpath, os.path.join(outdir, f'Arthur - S{s:>02}E{e:>02}.srt'))
- e += 1
- else:
- seapp.top_window().wait('ready', timeout=20)
- seapp.top_window().set_focus()
- keyboard.send_keys('^o')
- seapp.Opensubtitle.wait('visible', timeout=20)
- seapp.Opensubtitle.FileNameEdit.set_focus()
- seapp.Opensubtitle.FileNameEdit.set_edit_text(fullpath)
- seapp.Opensubtitle.Open.wait('ready', timeout=20)
- seapp.Opensubtitle.Open.set_focus()
- seapp.Opensubtitle.Open.click()
- sleep(3)
- seapp.top_window().wait('ready', timeout=20)
- seapp.top_window().set_focus()
- keyboard.send_keys('%tss{ENTER}')
- seapp.Splitsubtitle.wait('ready', timeout=20)
- seapp.Splitsubtitle['...'].set_focus()
- seapp.Splitsubtitle['...'].click()
- sleep(2)
- seapp.Openvideofile.wait('visible', timeout=20)
- seapp.Openvideofile.FileNameEdit.set_focus()
- seapp.Openvideofile.FileNameEdit.set_edit_text(os.path.join(outdir, f'Arthur - S{s:>02}E{e:>02}_src.mkv'))
- seapp.Openvideofile.Open.wait('ready', timeout=20)
- seapp.Openvideofile.Open.set_focus()
- seapp.Openvideofile.Open.click()
- seapp.Splitsubtitle.wait('ready', timeout=20)
- seapp.Splitsubtitle['Split'].set_focus()
- seapp.Splitsubtitle['Split'].click()
- sleep(2)
- seapp.Savepart1as.wait('ready', timeout=20)
- seapp.Savepart1as.Edit.set_focus()
- seapp.Savepart1as.Edit.set_edit_text(os.path.join(outdir, f'Arthur - S{s:>02}E{e:>02}.srt'))
- seapp.Savepart1as.Save.wait('ready', timeout=20)
- seapp.Savepart1as.Save.set_focus()
- seapp.Savepart1as.Save.click()
- e += 1
- seapp.Splitsubtitle.wait('active', timeout=20)
- seapp.Savepart2as.wait('ready', timeout=20)
- seapp.Savepart2as.Edit.set_focus()
- seapp.Savepart2as.Edit.set_edit_text(os.path.join(outdir, f'Arthur - S{s:>02}E{e:>02}.srt'))
- seapp.Savepart2as.Save.wait('ready', timeout=20)
- seapp.Savepart2as.Save.set_focus()
- seapp.Savepart2as.Save.click()
- e += 1
- sleep(2)
- try:
- os.remove(fullpath)
- except:
- pass
- keyboard.send_keys('%fx')
- e = 1
- # finally, mux.
- for file in os.listdir(outdir):
- if file.startswith('Arthur - ') and file.endswith('_src.mkv'):
- basename = file.rstrip('_src.mkv')
- srcpath = os.path.join(outdir, file)
- mkvpath = os.path.join(outdir, basename+'.mkv')
- srtpath = os.path.join(outdir, basename+'.srt')
- cmdline = ["C:\\Program Files\\MKVToolNix\\mkvmerge.exe", "--ui-language", "en", "--output", mkvpath, "--no-track-tags", "--no-global-tags", "--no-chapters", "--language", "0:en", "--language", "1:en", "--track-name", "1:English", "(", srcpath, ")"]
- if os.path.exists(srtpath):
- cmdline += ["--language", "0:en", "--track-name", "0:English", "(", srtpath, ")"]
- cmdline += ["--title", basename, "--track-order", "0:0,0:1,1:0"]
- print(subprocess.check_output(cmdline).decode())
- os.remove(srcpath)
- if os.path.exists(srtpath):
- os.remove(srtpath)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement