|
1 | 1 | import PySimpleGUI as sg |
2 | 2 | import y2qq |
3 | 3 |
|
4 | | - |
5 | 4 | sg.theme('DarkAmber') |
6 | | -layout = [[sg.Text('设置youtube-dl地址'), sg.Input('youtube-dl', key='yt'), sg.FileBrowse(), sg.Text('设置ffmpeg地址'), sg.Input('ffmpeg', key='ff'), sg.FileBrowse()], |
7 | | - [sg.Text('输入代理端口'), sg.InputText(key='port'), |
8 | | - sg.Button('设置代理')], |
9 | | - [sg.Button('保存配置', key='save_yaml'), |
10 | | - sg.Button('使用配置', key='read_yaml')], |
11 | | - [sg.Text('输入youtube链接'), |
12 | | - sg.InputText(key='url'), sg.Button('获取m3u8')], |
13 | | - [sg.Text('输入直播密钥'), sg.InputText(key='key')], |
14 | | - [sg.Multiline(key='Output', disabled=True, |
15 | | - size=(80, 6), autoscroll=True, reroute_cprint=True)], |
16 | | - [sg.Button('开始直播'), sg.Button('停止推流')]] |
| 5 | +# 设置控件属性 |
| 6 | +yt_text = sg.Text('设置youtube-dl路径') |
| 7 | +yt_input = sg.Input('', key='yt', size=6) |
| 8 | +ff_text = sg.Text('设置ffmpeg路径') |
| 9 | +ff_input = sg.Input('', key='ff', size=9) |
| 10 | +port_text = sg.Text('输入代理端口') |
| 11 | +port_input = sg.InputText(key='port', size=11) |
| 12 | +port_button = sg.Button('设置代理',) |
| 13 | +save_button = sg.Button('保存配置', key='save_yaml', size=14) |
| 14 | +read_button = sg.Button('使用配置', key='read_yaml', size=14) |
| 15 | +url_text = sg.Text('输入youtube链接') |
| 16 | +url_input = sg.InputText(key='url', size=6) |
| 17 | +m3u8_button = sg.Button('获取m3u8', size=9) |
| 18 | +key_text = sg.Text('输入直播密钥') |
| 19 | +key_input = sg.InputText(key='key', size=20) |
| 20 | +output_Ml = sg.Multiline(key='Output', disabled=True, |
| 21 | + size=(50, 17), autoscroll=True, reroute_cprint=True) |
| 22 | +start_button = sg.Button('开始直播', size=14) |
| 23 | +stop_button = sg.Button('停止推流', size=14) |
| 24 | + |
| 25 | +# 左侧布局 |
| 26 | +left_col = [[yt_text, yt_input, sg.FileBrowse('选择文件')], |
| 27 | + [ff_text, ff_input, sg.FileBrowse('选择文件')], |
| 28 | + [port_text, port_input, port_button], |
| 29 | + [save_button, read_button], |
| 30 | + [url_text, url_input, m3u8_button], |
| 31 | + [key_text, key_input], |
| 32 | + [start_button, stop_button]] |
| 33 | +layout = [ |
| 34 | + [sg.Column(left_col), output_Ml] |
| 35 | +] |
17 | 36 |
|
18 | 37 | window = sg.Window('QQ频道转播', layout) |
19 | 38 | while True: |
|
30 | 49 | y2qq.set_proxy(values['port']) |
31 | 50 | sg.cprint('设置代理成功') |
32 | 51 | if event == '获取m3u8': |
| 52 | + # 开启新进程获取m3u8 |
33 | 53 | window.perform_long_operation( |
34 | 54 | lambda: y2qq.get_m3u8(values['yt'], values['url']), '-m3u8-') |
35 | 55 | if event == '-m3u8-': |
36 | 56 | m3u8 = values[event] |
37 | 57 | if event == '开始直播': |
38 | 58 | try: |
| 59 | + # 开启新进程 用于持续打印推流情况 |
39 | 60 | window.perform_long_operation( |
40 | 61 | lambda: y2qq.restream(m3u8, values['ff'], values['key']), '-restream') |
41 | 62 | except: |
42 | 63 | sg.Popup('推流失败,检查m3u8、密钥和ffmpeg是否配置正确') |
43 | 64 | if event == 'save_yaml': |
44 | 65 | try: |
| 66 | + # 保存配置字典到当前文件夹 |
45 | 67 | dic = {'yt': values['yt'], 'ff': values['ff'], |
46 | 68 | 'port': values['port']} |
47 | 69 | with open('config.yaml', 'w') as f: |
|
51 | 73 | sg.Popup('写入配置失败') |
52 | 74 | if event == 'read_yaml': |
53 | 75 | try: |
| 76 | + # 读取保存的配置并更新到控件 |
54 | 77 | with open('config.yaml', 'r') as f: |
55 | 78 | dic = eval(f.read()) |
56 | 79 | window['yt'].update(dic['yt']) |
|
0 commit comments