Skip to content

Commit f95ca56

Browse files
authored
Update y2qq_GUI.py
1 parent 549778f commit f95ca56

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

y2qq_GUI.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
11
import PySimpleGUI as sg
22
import y2qq
33

4-
54
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+
]
1736

1837
window = sg.Window('QQ频道转播', layout)
1938
while True:
@@ -30,18 +49,21 @@
3049
y2qq.set_proxy(values['port'])
3150
sg.cprint('设置代理成功')
3251
if event == '获取m3u8':
52+
# 开启新进程获取m3u8
3353
window.perform_long_operation(
3454
lambda: y2qq.get_m3u8(values['yt'], values['url']), '-m3u8-')
3555
if event == '-m3u8-':
3656
m3u8 = values[event]
3757
if event == '开始直播':
3858
try:
59+
# 开启新进程 用于持续打印推流情况
3960
window.perform_long_operation(
4061
lambda: y2qq.restream(m3u8, values['ff'], values['key']), '-restream')
4162
except:
4263
sg.Popup('推流失败,检查m3u8、密钥和ffmpeg是否配置正确')
4364
if event == 'save_yaml':
4465
try:
66+
# 保存配置字典到当前文件夹
4567
dic = {'yt': values['yt'], 'ff': values['ff'],
4668
'port': values['port']}
4769
with open('config.yaml', 'w') as f:
@@ -51,6 +73,7 @@
5173
sg.Popup('写入配置失败')
5274
if event == 'read_yaml':
5375
try:
76+
# 读取保存的配置并更新到控件
5477
with open('config.yaml', 'r') as f:
5578
dic = eval(f.read())
5679
window['yt'].update(dic['yt'])

0 commit comments

Comments
 (0)