MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / DownloadSubtitlesGUI

Function DownloadSubtitlesGUI

DemoPrograms/Demo_Youtube-dl_Frontend.py:20–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18
19
20def DownloadSubtitlesGUI():
21 sg.theme('Dark')
22
23 combobox = sg.Combo(values=['', ], size=(10, 1), key='lang')
24 layout = [
25 [sg.Text('Subtitle Grabber', size=(40, 1), font=('Any 15'))],
26 [sg.Text('YouTube Link'), sg.Input(default_text='', size=(60, 1), key='link')],
27 [sg.Output(size=(90, 20), font='Courier 12')],
28 [sg.Button('Get List')],
29 [sg.Text('Language Code'), combobox, sg.Button('Download')],
30 [sg.Button('Exit', button_color=('white', 'firebrick3'))]
31 ]
32
33 window = sg.Window('Subtitle Grabber launcher', layout,
34 text_justification='r',
35 default_element_size=(15, 1),
36 font=('Any 14'))
37
38 # ---===--- Loop taking in user input and using it to query HowDoI --- #
39 while True:
40 event, values = window.read()
41 if event in ('Exit', None):
42 break # exit button clicked
43 link = values['link']
44 if event == 'Get List':
45 print('Getting list of subtitles....')
46 window.refresh()
47 command = [youtube_executable + f' --list-subs {link}']
48 output = ExecuteCommandSubprocess(command, wait=True, quiet=True)
49 lang_list = [o[:5].rstrip()
50 for o in output.split('\n') if 'vtt' in o]
51 lang_list = sorted(lang_list)
52 combobox.update(values=lang_list)
53 print('Done')
54
55 elif event == 'Download':
56 lang = values['lang'] or 'en'
57 print(f'Downloading subtitle for {lang}...')
58 window.refresh()
59 command = [youtube_executable + f' --sub-lang {lang} --write-sub {link}', ]
60 print(ExecuteCommandSubprocess(command, wait=True, quiet=False))
61 print('Done')
62 window.close()
63
64
65def ExecuteCommandSubprocess(command, wait=False, quiet=True, *args):

Callers 1

Calls 5

readMethod · 0.95
refreshMethod · 0.95
updateMethod · 0.95
closeMethod · 0.95
ExecuteCommandSubprocessFunction · 0.70

Tested by

no test coverage detected